如何使用Maven和Netbeans创建可执行jar文件

如何使用Maven和Netbeans创建可执行jar文件

本文介绍了如何使用Maven和Netbeans创建可执行jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个可运行的jar文件,但不知怎的,我的Maven / Netbeans没有这样做。这是我的pom.xml:

I'm trying to create a runnable jar file, but somehow my Maven/Netbeans fails to do so. This is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>de.ksw</groupId>
    <artifactId>KBSE-CDI-Testprogram</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>
    <build>
        <plugins>
            <plugin>
                <version>1.8.1</version>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>de.ksw.kbse.cdi.testprogram.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>KBSE-CDI</artifactId>
            <version>${project.version}</version>
        </dependency>
        <dependency>
            <groupId>maven</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>1.8.1</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

如您所见,我已经尝试添加主类。我还添加了依赖maven-jar-plugins,但是当我尝试编译项目时仍然收到错误消息:

As you can see I already tried to add the main class. I also added the dependency maven-jar-plugins, but I still get an error messagen when I try to compile the project:

要查看错误的完整堆栈跟踪,请使用-e开关重新运行Maven。
使用-X开关重新运行Maven以启用完整的调试日志记录。

To see the full stack trace of the errors, re-run Maven with the -e switch. Re-run Maven using the -X switch to enable full debug logging.

有关错误和可能的解决方案的更多信息,请阅读以下文章:
[帮助1]

For more information about the errors and possible solutions, please read the following articles: [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException

我在这里做错了什么?如何解决这个问题?

What am I doing wrong here? How to fix this?

推荐答案

没有版本 1.8.1 maven-jar-plugin

此处列出了所有可用版本的 maven -jar-plugin

Here the list of all available versions of maven-jar-plugin : https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-jar-plugin

您必须更新版本进入早期版本。

You have to update version into an earlier version.

最新版本示例:

<version>3.0.2</version>

这篇关于如何使用Maven和Netbeans创建可执行jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 05:50