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.
Asked
Active
Viewed 1,387 times
1

user5053360
- 279
- 2
- 14
-
1probably you need to provide the required libraries while running from cmd. – YoungHobbit Sep 27 '15 at 12:13
-
2can you show the command you are running? – leeor Sep 27 '15 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 readJob – user5053360 Sep 27 '15 at 14:32
-
Please add the command to the question and format it as code. You can edit the question. – Stefan Dollase Sep 27 '15 at 14:49
-
Thanks @Stefan.Done. – user5053360 Sep 27 '15 at 15:10
2 Answers
1
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.

dimplex
- 494
- 5
- 9
0
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:

Community
- 1
- 1

Stefan Dollase
- 4,530
- 3
- 27
- 51
-
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 – user5053360 Sep 27 '15 at 14:33