2012-05-10 1 views
1

Хорошо, вот что смущает меня:Что не хватает в этой сборке jar?

Я возиться с некоторыми просто кодированием с использованием Netbeans для компиляции и запуска некоторых программ Java, теперь, когда я получил повесить его, я пытался строить опарник и открытие его вне Netbeans, но я ударил в лицо этой ошибки:

Error: Could not find or load main class C:\Users\n\Desktop\DirectoryLi 
st_1\DirectoryList_1\build\classes\directorylist\DirectoryList_1.jar 

То, что я не уверен в том, как/почему это происходит, как я могу запустить программу, которая производит текстовый файл с некоторая информация в нем, полностью прекрасная, когда я запускаю ее в Netbeans, что исключается? Что пошло не так?

Вот журнал от компиляции фляги:

Спасибо за помощь!

init: 
deps-clean: 
Updating property file: C:\Users\n\Desktop\DirectoryList_1\DirectoryList_1\build\built-clean.properties 
Deleting directory C:\Users\n\Desktop\DirectoryList_1\DirectoryList_1\build 
clean: 
init: 
deps-jar: 
Created dir: C:\Users\n\Desktop\DirectoryList_1\DirectoryList_1\build 
Updating property file: C:\Users\Maxunknown\Desktop\DirectoryList_1\DirectoryList_1\build\built-jar.properties 
Created dir: C:\Users\n\Desktop\DirectoryList_1\DirectoryList_1\build\classes 
Created dir: C:\Users\n\Desktop\DirectoryList_1\DirectoryList_1\build\empty 
Created dir: C:\Users\n\Desktop\DirectoryList_1\DirectoryList_1\build\generated-sources\ap-source-output 
Compiling 1 source file to C:\Users\n\Desktop\DirectoryList_1\DirectoryList_1\build\classes 
compile: 
Created dir: C:\Users\n\Desktop\DirectoryList_1\DirectoryList_1\dist 
Copying 1 file to C:\Users\n\Desktop\DirectoryList_1\DirectoryList_1\build 
Nothing to copy. 
Building jar: C:\Users\n\Desktop\DirectoryList_1\DirectoryList_1\dist\DirectoryList_1.jar 
To run this application from the command line without Ant, try: 
java -jar "C:\Users\n\Desktop\DirectoryList_1\DirectoryList_1\dist\DirectoryList_1.jar" 
jar: 
BUILD SUCCESSFUL (total time: 0 seconds) 

Очень грязный и, вероятно, лучше организовать код:

/* 
* To change this template, choose Tools | Templates 
* and open the template in the editor. 
*/ 
package directorylist; 

import java.io.File; 
import java.io.FileNotFoundException; 
import java.io.FileOutputStream; 
import java.io.PrintWriter; 
import java.util.logging.Level; 
import java.util.logging.Logger; 

/** 
* This program lists the files in a directory specified by the user. The user 
* is asked to type in a directory name. If the name entered by the user is not 
* a directory, a message is printed and the program ends. 
*/ 
public class DirectoryList { 

    public static void main(String[] args) { 
     try { 
//   String directoryName;    // Directory name entered by the user. 
//   Scanner scanner;     // scanner reads from standard input. 
//   scanner = new Scanner(System.in); // scanner reads from standard input. 
// 
//   System.out.print("Enter a directory name: "); 
//   directoryName = scanner.nextLine().trim(); 

      String indent = ""; 
      String userHome = System.getProperty("user.home"); 
      String fileSeparator = System.getProperty("file.separator"); 

      File log = new File(userHome + fileSeparator + "log.txt"); 
      FileOutputStream stream; 
      stream = new FileOutputStream(log); 
      PrintWriter out = new PrintWriter(stream); 

//   System.out.println(userHome); 
//   System.out.println(fileSeparator); 

      for (int i = 0; i < userHome.length(); i++) { 
       if (userHome.charAt(i) == fileSeparator.charAt(0)) { 
        userHome = userHome.substring(0, i + 1); 
       } 
      } 

      System.out.println("Files in directory \"" + userHome + "\""); 
      out.println("Files in directory \"" + userHome + "\""); 
      directoryListV2(userHome, 1, out); 
     } // end main() 
     catch (FileNotFoundException ex) { 
      Logger.getLogger(DirectoryList.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    } // end main() 

    public static void directoryListV2(String directoryName, int directoryLevel, PrintWriter out) { 

     File directory;  // File object referring to the directory. 
     String[] files;  // Array of file names in the directory. 
     directory = new File(directoryName); 
     String fileSeparator = System.getProperty("file.separator"); 
     String indent = ""; 

     for (int i = 0; i < directoryLevel; i++) { 
      indent += " "; 
     } 

     if (directory.isDirectory() == false) { 
      if (directory.exists() == false) { 
       System.out.println("There is no such directory!"); 
       out.println("There is no such directory!"); 
      } else { 
       System.out.println("That file is not a directory."); 
       out.println("That file is not a directory."); 
      } 
     } else { 
      files = directory.list(); 
//   System.out.println("Files in directory \"" + directory + "\":"); 
//   out.println("Files in directory \"" + directory + "\":"); 

      if (files != null) { 
       for (int i = 0; i < files.length; i++) { 
        if (isDirectory(directoryName + fileSeparator + files[i] + fileSeparator)) { 
         System.out.println(indent + directoryName + fileSeparator + files[i] + fileSeparator); 
         out.println(indent + directoryName + fileSeparator + files[i] + fileSeparator); 

         directoryListV2(directoryName + fileSeparator + files[i], directoryLevel + 1, out); 
        } else { 
         System.out.println(indent + files[i]); 
         out.println(indent + files[i]); 
        } 
       } 
      } 
     } 
     out.flush(); 
    } 

    private static boolean isDirectory(String directoryName) { 
     File directory; 

     directory = new File(directoryName); 
     if (directory.isDirectory() == true) { 
      if (directory.exists() == true) { 
       return true; 
      } 
     } 
     return false; 
    } 
} // end class DirectoryList 
+0

Основная декларация класса в манифесте, возможно. –

+0

Уже задал здесь http://stackoverflow.com/questions/7485670/error-could-not-find-or-load-main-class – Juliano

+0

Как вы пытались запустить банку? Как выглядит MANIFEST.MF? – Thomas

ответ

0

Проблема заключается в том, что главный класс в вас банке не загружен.

Для этого вам нужно будет сделать манифест для основного класса в банке.

Вы можете найти лучший учебник по созданию исполняемого JAR here

другого ресурса может также найден here, который является основным ориентиром Sun для создания исполняемых баночки.

Надеюсь, что это сработает для вас.

Наслаждайтесь!

+0

Ahhhh, то, что вы сказали, звучит логично, но я все еще чувствую эту проблему! Я пробовал несколько вещей: Добавление Main-Class: directorylist.DirectoryList к манифесту Выполнение этой же задачи с полным именем пути вместо Однако ошибка возникает! – Hobbyist

+0

Тогда может возникнуть проблема в кодировании. –

+0

Но это работает, как ожидалось, в IDE, возможно ли это? – Hobbyist

 Смежные вопросы

  • Нет связанных вопросов^_^