简体   繁体   English

蚂蚁罐找不到或加载主类

[英]Ant jar Could not find or load main class

I am running a jar with a particular argument for eg: testscript run then this testscript exists in different directories so I run the jar of that script using the java jar command of ant something like this: 我正在运行带有特定参数的jar,例如: testscript run然后该testscript存在于不同目录中,因此我使用ant的java jar命令运行该脚本的jar,如下所示:

<java jar="testscript-jar.jar">
<arg value="run"/>
</java>

By doing that I get error Could not find or load main class . 通过这样做,我得到错误Could not find or load main class

This command works fine for the first 2-3 instances but start showing error for the rest of the directories. 此命令在前2-3个实例中工作正常,但对于其他目录开始显示错误。

Make sure the jar attribute points to the correct path of the Jar file relative to the Ant's project base dir. 确保jar属性指向相对于Ant项目基目录的Jar文件的正确路径。 See this quote from the java task documentation : 请参阅java任务文档中的以下引用:

The parameter of the jar attribute is of type File ; jar属性的参数类型为File that is, the parameter is resolved to an absolute file relative to the base directory of the project, not the directory in which the Java task is run. 即,将参数解析为相对于项目基本目录的绝对文件, 而不是相对于运行Java任务的目录。 If you need to locate a JAR file relative to the directory the task will be run in, you need to explicitly create the full path to the JAR file. 如果需要相对于将在其中运行任务的目录找到一个JAR文件,则需要显式创建该JAR文件的完整路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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