【发布时间】:2016-06-02 15:58:03
【问题描述】:
请问,您能解释一下为什么我的 jar 文件没有在目标文件夹之外执行吗?我怎样才能独立完成?将其复制/粘贴到另一个目录。
当我在目标文件夹外执行我的 jar 时,会产生 NoClassDefFound 错误。它无法从依赖项中加载 jar。
这是我的 pom.xml:
<properties>
<docx4j.version>3.3.0</docx4j.version>
</properties>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.epam.executor.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR with runtime dependencies so that this program can be executed from command line using java -jar command -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j</artifactId>
<version>${docx4j.version}</version>
</dependency>
</dependencies>
我通过这个带有 3 个参数的命令执行我的 jar:
java -jar DocumentTemplate-1.0.jar D:\Trash\xml1.xml D:\Trash\template.docx D:\Trash\results.docx
【问题讨论】:
-
我猜你需要
docx4j所以你应该把它添加到你的类路径中。您已经添加了lib/,这需要包含您所依赖的所有 jar。 (相对于罐子) -
简而言之,docx4j在哪里?你得到的错误信息是什么?