简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM