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

Java 如何使用Maven和Netbeans创建可执行jar文件,java,maven,netbeans,jar,executable-jar,Java,Maven,Netbeans,Jar,Executable Jar,我试图创建一个可运行的jar文件,但不知何故,我的Maven/Netbeans未能做到这一点。这是我的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.apac

我试图创建一个可运行的jar文件,但不知何故,我的Maven/Netbeans未能做到这一点。这是我的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>

4.0.0
德克西
已缓存在本地存储库中,在经过central的更新间隔或强制更新之前,不会重新尝试解析->[帮助1]

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

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


我做错了什么?如何修复此问题?

没有
maven jar插件的
1.8.1
版本

这里列出了所有可用版本的
maven jar插件

您必须将
版本
更新为早期版本

最新版本的示例:

<version>3.0.2</version>
3.0.2

我在我的一个项目中所做的是使用maven jar插件和maven汇编插件

结果是一个可执行的胖jar

<artifactId>maven-assembly-plugin</artifactId>
            <version>2.5.5</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>de.ksw.kbse.cdi.testprogram.App</mainClass>
                    </manifest>
                    <manifestEntries>                      
                        <!--this one is to add the version information in the manifest. This is something that I need but you can ignore it-->  
                        <version>${project.version}</version>
                    </manifestEntries>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <finalName>${project.artifactId}</finalName>
                <appendAssemblyId>false</appendAssemblyId> 
                <classifier>DEV</classifier>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> <!-- to inheritance merges -->
                    <phase>package</phase> <!-- just to use in the packaging phase -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <!--This plugin is used to have just one jar instead of 2-->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.0.1</version>
            <configuration>
                <classesDirectory>${project.build.outputDirectory}</classesDirectory>
                <finalName>${project.artifactId}</finalName>
                <outputDirectory>${project.build.directory}</outputDirectory>
                <verify>false</verify>
            </configuration>
        </plugin>
maven汇编插件
2.5.5
de.ksw.kbse.cdi.testprogram.App
${project.version}
带有依赖项的jar
${project.artifactId}
假的
发展
组装
包裹
单一的
org.apache.maven.plugins
maven jar插件
3.0.1
${project.build.outputDirectory}
${project.artifactId}
${project.build.directory}
假的
在此之后,只需单击netbeans中的clean和build按钮并搜索一些内容

使用程序集文件:路径\到\ JAR/KBSE-CDI-Testprogram.JAR


您应该使用Maven Central作为参考!我不知道这个网站。谢谢。最后。。。事实证明,正如你所说,我使用了错误的版本。我使用它,因为我使用了我发现的第一个maven jar插件,那可能是一个旧插件。但是,不是我没有任何问题。:)谢谢