Maven-Java项目中的可执行文件 [英] Maven - Executable file from a java project
问题描述
我需要使用maven(用于学校项目)从单个maven命令创建可执行文件.我从未使用过maven,并在stackoverlow上尝试过许多解决方案.解决方案创建了一个jar文件,但该文件从未打开.
I need to use maven (for a school project) to create an executable file from a single maven command. I've never used maven and tried many solutions here on stackoverlow. The solutions created a jar file, but the file never opened.
这是我的项目结构
src
com
project
code
swing
programm
interface
Main.class
我知道这不是行家惯例,但是现在更改它意味着我将不得不为大约40个类调整导入(因为intelliJ不能完美地重构所有内容).
I know this isn't maven convention, however changing it now would mean I would have to adjust the imports (as intelliJ doesn't refactor everything perfectly) for around 40 classes.
<?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>MyGroup</groupId>
<artifactId>myProgramm</artifactId>
<version>0.7-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Hello World</name>
<description>Course Project</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.25.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit/junit5-engine -->
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit5-engine</artifactId>
<version>5.0.0-ALPHA</version>
</dependency>
</dependencies>
<build>
</build>
要制作可执行文件,我必须放入什么?
What do I have to put inside to make an executable file?
推荐答案
您需要将插件添加到您的pom.xml
文件
You need to add plugin to your pom.xml
file
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>com.example.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
并运行程序:mvn clean install exec:java
...这是doc http://www的链接. mojohaus.org/exec-maven-plugin/usage.html
... here is the link for doc http://www.mojohaus.org/exec-maven-plugin/usage.html
有不同的解决方案,具体取决于您的要求: https://www. baeldung.com/executable-jar-with-maven
There are possible different solutions, depends on your requirements: https://www.baeldung.com/executable-jar-with-maven
这篇关于Maven-Java项目中的可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!