[英]How can I create a jar file in Netbeans using Maven?
Following some questions I have created a jar file but when I try to execute it in my prompt I have this error: 遵循一些问题,我创建了一个jar文件,但是当我尝试在提示符下执行它时,出现此错误:
Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.NoClassDefFoundError: com/itextpdf/layout/element/IBlockElement
错误:发生了JNI错误,请检查安装,然后重试。线程“主”中的异常java.lang.NoClassDefFoundError:com / itextpdf / layout / element / IBlockElement
but if I run it in Netbeans it starts. 但是如果我在Netbeans中运行它,它将启动。 why?
为什么?
This is my POM.xml file : 这是我的POM.xml文件:
<project>
...
<dependencies>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>7.0.2</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>io</artifactId>
<version>7.0.2</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>7.0.2</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>forms</artifactId>
<version>7.0.2</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>pdfa</artifactId>
<version>7.0.2</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>pdftest</artifactId>
<version>7.0.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.18</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<!-- POI : Excel library -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.antonionappi.editorpdf.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Your built jar does not contain the dependencies which you compiled with. 内置的jar不包含编译时使用的依赖项。 You can either use the maven assembly plugin to generate a package of dependencies and then configure the classpath, or just build a single jar with all dependencies contained inside: How can I create an executable JAR with dependencies using Maven?
您可以使用maven程序集插件生成依赖项包,然后配置类路径,也可以仅构建一个包含所有依赖项的jar: 如何使用Maven创建具有依赖项的可执行JAR?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.