我正在尝试从JAR运行课程。此类不是此jar中唯一的主类。另外,它还需要其他数量的jar文件,这些文件与该Jar保存在同一目录中。我尝试过的命令如下:
(使用Windows平台,mydir是我所有jar所在的目录)
mysql-connector- java-5.1.13-bin.jar是myProjImport.jar运行所需的,com.mycomp.myProj.importer.csv.TestImporter是我要运行的课程。 "C:\Documents and Settings\user\workspace\myProjImport\src\conf\datasource.properties"并且"C:\temp\apollo_claims_test.txt"是由类所需的命令行参数TestImporter 下面是我曾尝试:
mysql-connector- java-5.1.13-bin.jar
myProjImport.jar
com.mycomp.myProj.importer.csv.TestImporter
"C:\Documents and Settings\user\workspace\myProjImport\src\conf\datasource.properties"
"C:\temp\apollo_claims_test.txt"
TestImporter
mydir>java -cp C:\temp\test_myProj\mysql-connector-java-5.1.13-bin.jar;. myProjImport.jar com.mycomp.myProj.importer.csv.TestImporter "C:\Documents and Settings\user\workspace\myProjImport\src\conf\datasource.properties" "C:\temp\apollo_claims_test.txt"
这是错误:
Exception in thread "main" java.lang.NoClassDefFoundError: myProjImport/jar Caused by: java.lang.ClassNotFoundException: myProjImport.jar at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) Could not find the main class: myProjImport.jar. Program will exit.
有人可以告诉我我应该运行什么命令吗?
尝试:
java -cp C:\temp\test_myProj\mysql-connector- java-5.1.13-bin.jar;myProjImport.jar com.mycomp.myProj.importer.csv.TestImporter "C:\Documents and Settings\user\workspace\myProjImport\src\conf\datasource.properties" "C:\temp\apollo_claims_test.txt”
java -cp C:\temp\test_myProj\mysql-connector- java-5.1.13-bin.jar;myProjImport.jar com.mycomp.myProj.importer.csv.TestImporter "C:\Documents and Settings\user\workspace\myProjImport\src\conf\datasource.properties" "C:\temp\apollo_claims_test.txt
提供您从与myProjImport.jar相同的目录运行