[英]Building a maven project for deployment
Hello all I'm pretty new to using maven to build Java project so I'm sure the solution to my problem will be quite easy. 大家好,我是使用maven构建Java项目的新手,所以我确信我的问题的解决方案将非常简单。 I have installed the Eclipse Maven plugin and created a maven project. 我已经安装了Eclipse Maven插件并创建了一个maven项目。 I now wish to package this project and distribute it as a runnable jar file. 我现在希望打包这个项目并将其作为可运行的jar文件分发。 However when I run 但是,当我跑
mvn package
and then try to run the jar file I get the following error: 然后尝试运行jar文件我收到以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError: main/Formatter
The pom for this particular file looks like so: 这个特定文件的pom看起来像这样:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>GROUP</groupId>
<artifactId>pcap.csv.xml</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</project>
Any help would be greatly appreciated. 任何帮助将不胜感激。
You need to specify the main class in the jar plugin: 您需要在jar插件中指定主类:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>main.Formatter</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
If you want to distribute a single jar you need to use a single-jarifier (fatjar, jarjar, onejar, etc.) 如果你想分发一个jar,你需要使用一个单一的jarizer(fatjar,jarjar,onejar等)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.