James Adams
James Adams

Reputation: 8727

Class not found error, but class is in JAR file on classpath

When calling a Java class from command line Java can't find the executable class, even though it's in a JAR file on the class path. I was getting this from a call within a Python script, but the same behavior happens on command line (DOS on Windows). Can anyone advise?

c:\nco> java -mx1200m -cp C:\tmp\lib\indices-0.0.2-SNAPSHOT.jar nidis.indices.GriddedIndexCalculator 

Error: Could not find or load main class nidis.indices.GriddedIndexCalculator

c:\nco> jar -tf C:\tmp\lib\indices-0.0.2-SNAPSHOT.jar | find "GriddedIndexCalculator"

nidis/indices/GriddedIndexCalculator.class

Upvotes: 2

Views: 1870

Answers (1)

rlegendi
rlegendi

Reputation: 10606

Java omits the classpath variable when you run it with java -jar due to security reasons.

The solution is to define the dependencies in the Class-Path: attribute of your MANIFEST.MF file.

Upvotes: 2

Related Questions