gpt4 book ai didi

java - 如何运行maven目标目录中JAR文件中的java类?

转载 作者:行者123 更新时间:2023-12-01 05:39:15 25 4
gpt4 key购买 nike

我想在 maven 构建后运行我的 Izpack 安装程序,但在执行“mvn test”后我得到以下输出:

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building RS IzPack installer
[INFO] task-segment: [test]
[INFO] ------------------------------------------------------------------------
[debug] execute contextualize
[INFO] [resources:copy-resources {execution: copy-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 109 resources
[INFO] Copying 4 resources
[INFO] Preparing exec:java
[WARNING] Removing: java from forked lifecycle, to prevent recursive invocation.
[debug] execute contextualize
[INFO] [resources:copy-resources {execution: copy-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 109 resources
[INFO] Copying 4 resources
[INFO] [exec:java {execution: default}]
[WARNING]
java.lang.ClassNotFoundException: com.izforge.izpack.installer.Installer
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
at java.lang.Thread.run(Thread.java:595)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. com.izforge.izpack.installer.Installer

看起来我必须以某种方式将生成的 jar 文件放入类路径中,有什么想法吗?

摘 self 的 pom.xml :

  <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal> <!-- "exec" also possible -->
</goals>
<configuration>
<mainClass>com.izforge.izpack.installer.Installer</mainClass>
<arguments>
<argument>-console</argument>
<!-- <argument>arg1</argument> -->
</arguments>
</configuration>
</execution>
</executions>
</plugin>
Apache Maven 2.2.1(r801777;2009-08-06 21:16:01+0200)Java版本:1.6.0_20Java主目录:C:\Java\jdk16\jre默认区域设置:en_GB,平台编码:Cp1252操作系统名称:“windows xp”版本:“5.1”架构:“x86”系列:“windows”

马丁

最佳答案

你看过 jar 里面吗?可能是maven没有将需要的类包含到jar中。

关于java - 如何运行maven目标目录中JAR文件中的java类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7565914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com