【发布时间】:2016-05-31 12:36:44
【问题描述】:
我正在尝试创建一个.bat 文件来运行我生成的可执行 JAR 文件。我找到了 this 创建 .bat 文件以运行项目的方法。所以,我阅读了插件here 并将以下内容添加到我的pom.xml。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.10</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
<configuration>
<assembleDirectory>${assembleDir}</assembleDirectory>
<generateRepository>false</generateRepository>
<repositoryName>lib</repositoryName>
<configurationDirectory>conf</configurationDirectory>
<copyConfigurationDirectory>false</copyConfigurationDirectory>
<programs>
<program>
<mainClass>com.companyname.tests.TestRunner</mainClass>
<id>AutoConfigTest</id>
</program>
</programs>
</configuration>
</plugin>
而且,是的,顾名思义,这个 JAR 包含 JUnit 测试用例。
我阻止插件解压缩 JAR 并创建 repo 文件夹并将其设置为我已经生成的 lib 文件夹,其中包含所有 JAR(可执行文件和依赖项)。正在生成.bat 文件,但是在运行它时出现以下错误。
Error: Could not find or load main class com.companyname.tests.TestRunner
另外,我希望命令提示符在执行后保留。在这种情况下,它会立即关闭。也许是因为我遇到了错误。我不确定。
所以,再次搜索并找到this。但正如公认的答案所暗示的那样,我的 pom.xml 已经包含 -
<packaging>jar</packaging>
组装后的目录是-
AutoConfigTest
|
|--bin
| `- contains the .bat file
|--conf
| `- contains the property files and other configuration files
|--lib
`- contains all the JARs
我在这里做错了什么?
【问题讨论】:
-
是的,question you mention 看起来和你的一模一样。接受的解决方案很奇怪,因为
jar是默认包装。您是否尝试过其他解决方案和建议?似乎有几件事可能会出错,而彼此的答案解决了其中一件事情。 -
生成的
.bat文件内容是什么?lib/中的任何.jar文件是否包含您的课程com.companyname.tests.TestRunner? -
@SubOptimal 是的,包含
com.companyname.tests.TestRunner的jar 存在于lib文件夹中。我已经检查过了。 -
@BileshGanguly 我认为它不在脚本
AutoConfigTest.bat期望的地方。看看我的回答。 -
@SubOptimal 我已经将依赖项添加到类路径中。请查看生成的批处理文件。我已经更新了问题。
标签: java maven batch-file jar