2015-09-27 79 views
1

当我从命令提示符运行我的java程序时,由于ClassNotFound错误,程序不会运行。但是我看到的类是存在于类路径中的jar文件中的。当我从Eclipse运行相同的程序工作。不知道我在这里失踪。谢谢。我试图从我的Windows DOS提示符下运行以下命令:C:\softwares\SpringBatchExample4>java -cp "target/dependency-jars/*:target/spring-batch.jar" org.springframework.batch.core.launch.support.CommandLineJobRunner spring/batch/jobs/job-read-files.xml readJob。然后我看着目标\依赖项下的一个罐子-jars确认jar文件具有CommandLineJobRunner类。当从命令提示符运行程序时发现Classnotound

+1

可能你需要提供从cmd运行时所需的库。 – YoungHobbit

+2

你能显示你正在运行的命令吗? – leeor

+0

Thanks.I试图从我的Windows dos提示符运行以下命令:C:\ softwares \ SpringBatchExample4> java -cp“target/dependency-jars/*:target/spring-batch.jar”org.springframework.batch。 core.launch.support.CommandLineJobRunner spring/batch/jobs/job-read-files.xml readJob – user5053360

回答

1

当从命令行运行JAR文件,你必须指定类路径两种选择:

  1. 使用-classpath或-cp命令行参数,后跟一个空格和完整路径到所有列表由分号(Windows)或冒号(Linux/Unix)分隔的类路径条目;
  2. 在其他规则适用的主JAR清单中使用Class-Path条目。
0

如果在您的清单文件中没有的Main-Class条目,您可能需要指定包含这样的命令行main方法的类:

java -cp MyJar.jar com.example.MyMainClass 

参见:

+0

我试图执行以下命令。看起来是正确的:C:\ softwares \ SpringBatchExample4> java -cp“target/dependency-jars/*:target/spring-batch.jar”org.springframework.batch.core。 launch.support.CommandLineJobRunner spring/batch/jobs/job-read-files.xml readJob – user5053360

相关问题