When I run my java program from the command prompt, the program does not not run because of a ClassNotFound error. But the class I see is there in a jar file which is on the classpath. That same program when I run from Eclipse works.Not sure as to what I am missing here.Thanks.I was trying to run the following command from my windows dos prompt: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.And I looked into one of the jars under target\dependency-jars to confirm that the jar file has the CommandLineJobRunner class.
-
1probably you need to provide the required libraries while running from cmd.YoungHobbit– YoungHobbit2015-09-27 12:13:24 +00:00Commented Sep 27, 2015 at 12:13
-
2can you show the command you are running?leeor– leeor2015-09-27 12:13:58 +00:00Commented Sep 27, 2015 at 12:13
-
Thanks.I was trying to run the following command from my windows dos prompt: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 readJobuser5053360– user50533602015-09-27 14:32:46 +00:00Commented Sep 27, 2015 at 14:32
-
Please add the command to the question and format it as code. You can edit the question.Stefan Dollase– Stefan Dollase2015-09-27 14:49:41 +00:00Commented Sep 27, 2015 at 14:49
-
Thanks @Stefan.Done.user5053360– user50533602015-09-27 15:10:39 +00:00Commented Sep 27, 2015 at 15:10
Add a comment
|
2 Answers
When running a JAR file from command line you have two options for specifying the classpath:
- Using the -classpath or -cp command line argument, followed by a space and a list of full paths to all classpath entries delimited by a semicolon (Windows) or colon (Linux/Unix);
- Using the Class-Path entry in the main JAR manifest where other rules apply.
Comments
If there is no Main-Class entry in your manifest file, you might need to specify the class containing the main method on the command line like this:
java -cp MyJar.jar com.example.MyMainClass
See also:
1 Comment
user5053360
I was trying to execute the following command.Seems to be correct: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