[英]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. 从命令行调用Java类时,Java找不到可执行类,即使它位于类路径上的JAR文件中。 I was getting this from a call within a Python script, but the same behavior happens on command line (DOS on Windows). 我是从Python脚本中的调用中得到的,但是在命令行(Windows上的DOS)中也会发生相同的行为。 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. 由于安全原因,当使用java -jar
运行Java时,Java会忽略classpath变量。
The solution is to define the dependencies in the Class-Path:
attribute of your MANIFEST.MF
file. 解决方案是在MANIFEST.MF
文件的Class-Path:
属性中定义依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.