1

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.

user5053360
  • 279
  • 2
  • 14

2 Answers2

1

When running a JAR file from command line you have two options for specifying the classpath:

  1. 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);
  2. 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