我有一个JavaFX应用程序,我使用它没有模块(即我删除了模块信息文件).该应用程序正在得到建设与mvn clean package
刚刚好,我可以运行它与java -jar myapp-with-dependecies.jar
刚刚好.有一个Main类运行我的javafx应用程序(lifehack运行javafx应用程序没有模块,在互联网上找到):
public class Main {
public static void main(String[] args) {
DesktopApplication.main(args);
}
}
以下是我在POM中的插件:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</path>
</annotationProcessorPaths>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>my.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>my.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I also found this configuration somewhere in the internet when searching how to make JavaFX run without modules. And obviously there are some files in my resources package, i.e. fxml files, css files and configuration file for hibernate.
Now you have a full understanding of structure of my project. Other than that, there are just dependencies for logic and my classes, that are not critical for my question, so you also have a reproducible example. These are my javafx dependencies:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>19.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>19.0.2</version>
</dependency>
我的问题是:我现在如何制作我的应用程序的可执行.exe文件?我也想包括Java在它,这样客户将不必安装所需的Java版本.到目前为止,我try 的是:
- 我使用了Launch4j,它创建了一个.exe文件,但问题是它假定客户端已经安装了Java.
- 我从GitHub下载了一些项目,它已经配置为可以很容易地从JavaFX应用程序中创建包含Java的可执行文件.问题是我已经有了我的项目,我不想仅仅为了构建exe而将很多文件转移到新项目中.
I think there should be a more clear way of how to do it, using some commands or something like that. Unfortunately, I didn't find a good step by step explanation of how to do it. So this is my question, if someone will enlighten me and tell me how to do it, I will appreciate that, thanks.
UPD: Just to make things clear, I'm using Linux and want to create .exe file for Windows. Is that possible?