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.

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

2 Answers 2

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.
Sign up to request clarification or add additional context in comments.

Comments

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:

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.