运行jar文件时使用main问题

时间:2014-04-22 08:15:30

标签: java eclipse jar executable-jar

我正在尝试运行一个jar文件,我已经在eclipse中创建了清单文件并指定了主入口点。我已经测试了所有我的类文件和我需要工作的文件(TestRead.java)一直给我这个错误我不知道为什么或如何解决它:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/ws/commons/schema/XmlSchemaElement
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
    at java.lang.Class.getMethod0(Unknown Source)
    at java.lang.Class.getMethod(Unknown Source)
    at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.ws.commons.schema.XmlSchemaElement
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 6 more

以下是命令行:

java -jar JavaWdslApp.jar

编辑:我将它保存为可运行的Jar文件,并尝试运行它但是另一个问题告诉我数组已超出界限:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

这就是我所说的:

public static void main(String[] args) {
String path1 = args[0];
String fileName = args[1];
TagDef tagDef;

String[] operations;
try {
    operations = listOperationsUnique("abc");
    System.out.println("operation:" + operations.length);
    for (int i = 0; i < operations.length; i++) {
        System.out.println("operation:" + operations[i]);
    }
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (SAXException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (ParserConfigurationException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

try {
    tagDef = refheader(path1, fileName); 

    System.out.println("=================================================================");
    System.out.println("abc");
    System.out.println(abc);
    System.out.println("=================================================================");

} catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();

}

2 个答案:

答案 0 :(得分:1)

第二个错误是由于您尝试访问args [0]和args 1而导致的,而您还没有通过命令行通知任何参数。它看起来应该类似于:

java -jar JavaWdslApp.jar valueForPath1 valueForFileName

我建议你查看java command reference

答案 1 :(得分:0)

问题在于您的罐子包装。您创建的jar文件不包含必需的依赖项。创建jar文件时,请在文件中包含必需的库。那么你应该好好去。