How to create an executable jar which is executable (Maven-Jfoenix-Hibernate-IntelliJ) __有人可以做这个主题吗resolve/close
How to create an executable jar which is executable (Maven-Jfoenix-Hibernate-IntelliJ) __ Can someone makes the subject resolve/close please
我尝试从在 IntelliJ 中使用 Maven、JFX、JFoenix、Hibernate ...的项目生成可执行 jar 文件
我尝试了很多解决方案,我们可以在不同的开发人员那里找到这些解决方案 forum/website(包括 Whosebug)。
因此没有人为我工作..
我尝试创建可执行 jar 文件:
命令:mvn compile _ 创建两个不执行任何操作的可执行 jar..
创建工件:文件 -> 全部保存 -> 项目结构 -> + -> Jar -> 从模块依赖项 -> Main Class : MyMainClass / Directory : src\main\java OR src\main\resources (因为他为某人工作改变了这个。)- > 好的
构建 -> 构建工件 -> 构建 或 重建。
此时我有一个可执行文件,但它什么都不执行..
- 阴影堵塞:(您将在 pom.xml 的代码中看到)结果为:
Failed to execute goal
org.apache.maven.plugins:maven-shade-plugin:3.2.1:shade (default-cli)
on project GymFormManager: Failed to create shaded artifact, project main
artifact does not exist.
pom.xml,我只拿了重要的部分因为它太大了:
...
<modelVersion>4.0.0</modelVersion>
<groupId>com.gymform.maven</groupId>
<artifactId>GymFormManager</artifactId>
<version>1.0-SNAPSHOT</version>
</dependencies>
...
<!-- Try To Create Executable Jar -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.gymformmanager.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.gymformmanager.Main</mainClass>
</transformer>
</transformers>
<!-- I have tried with and without hadedArtifact --> <shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>GymFormManager</shadedClassifierName> <!-- Any name that makes sense -->
</configuration>
</execution>
</executions>
</plugin>
目前,我有三个什么都不做的可执行 jar:
The first executable
The path of the first executable
The second and third executable
Their paths
编辑:
在听从 Jony 的建议后,我遇到了这个错误:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/gymformmanager/Main has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runt
ime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access0(Unknown Source)
at java.net.URLClassLoader.run(Unknown Source)
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
我用这个解决了版本问题:
Windows ignores JAVA_HOME: how to set JDK as default?
Error: JavaFX runtime components are missing, and are required to run this application
虽然我在 pom.xml 中有依赖关系:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
如果你想创建一个可执行的jar文件,你需要相应地配置Maven Archiver。您需要告诉它使用哪个 main class。这是通过配置元素完成的。这是配置为添加 class 路径并使用 class fully.qualified.MainClass 作为主要 class:
的示例 pom.xml
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
...
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
</configuration>
...
</plugin>
</plugins>
</build>
...
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
...
</project>
你可以尝试 assemble 一个所谓的 fatjar 与 maven:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.gymformmanager.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
这将在您的输出目录中创建一个名为 GymFormManager-jar-with-dependencies.jar 的附加 jar 文件。你可以 运行 它与:
java -jar GymFormManager-jar-with-dependencies.jar
我猜 javafx-maven-plugin is a good option to build JFX application. It is based on Java Packager Tool 并且可以构建本机包和 jar。呼叫 mvn jfx:jar
开始构建。
<plugin>
<!-- Generate Executable JFX JAR -->
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.8.3</version>
<configuration>
<vendor>${vendor}</vendor>
<mainClass>${mainClass}</mainClass>
<allPermissions>true</allPermissions>
<manifestAttributes>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
<Build-Timestamp-Format>${maven.build.timestamp.format}</Build-Timestamp-Format>
<Build-Timestamp>${dev.build.timestamp}</Build-Timestamp>
</manifestAttributes>
<jfxMainAppJarName>${jfxMainAppJarName}</jfxMainAppJarName>
</configuration>
<executions>
<execution>
<id>create-jfxjar</id>
<phase>package</phase>
<goals>
<goal>build-jar</goal>
</goals>
</execution>
</executions>
</plugin>
我尝试从在 IntelliJ 中使用 Maven、JFX、JFoenix、Hibernate ...的项目生成可执行 jar 文件
我尝试了很多解决方案,我们可以在不同的开发人员那里找到这些解决方案 forum/website(包括 Whosebug)。 因此没有人为我工作..
我尝试创建可执行 jar 文件:
命令:mvn compile _ 创建两个不执行任何操作的可执行 jar..
创建工件:文件 -> 全部保存 -> 项目结构 -> + -> Jar -> 从模块依赖项 -> Main Class : MyMainClass / Directory : src\main\java OR src\main\resources (因为他为某人工作改变了这个。)- > 好的
构建 -> 构建工件 -> 构建 或 重建。 此时我有一个可执行文件,但它什么都不执行..- 阴影堵塞:(您将在 pom.xml 的代码中看到)结果为:
Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.2.1:shade (default-cli) on project GymFormManager: Failed to create shaded artifact, project main artifact does not exist.
pom.xml,我只拿了重要的部分因为它太大了:
...
<modelVersion>4.0.0</modelVersion>
<groupId>com.gymform.maven</groupId>
<artifactId>GymFormManager</artifactId>
<version>1.0-SNAPSHOT</version>
</dependencies>
...
<!-- Try To Create Executable Jar -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.gymformmanager.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.gymformmanager.Main</mainClass>
</transformer>
</transformers>
<!-- I have tried with and without hadedArtifact --> <shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>GymFormManager</shadedClassifierName> <!-- Any name that makes sense -->
</configuration>
</execution>
</executions>
</plugin>
目前,我有三个什么都不做的可执行 jar:
The first executable The path of the first executable
The second and third executable Their paths
编辑: 在听从 Jony 的建议后,我遇到了这个错误:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/gymformmanager/Main has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runt
ime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access0(Unknown Source)
at java.net.URLClassLoader.run(Unknown Source)
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
我用这个解决了版本问题: Windows ignores JAVA_HOME: how to set JDK as default?
Error: JavaFX runtime components are missing, and are required to run this application
虽然我在 pom.xml 中有依赖关系:
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
如果你想创建一个可执行的jar文件,你需要相应地配置Maven Archiver。您需要告诉它使用哪个 main class。这是通过配置元素完成的。这是配置为添加 class 路径并使用 class fully.qualified.MainClass 作为主要 class:
的示例 pom.xml<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
...
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
</configuration>
...
</plugin>
</plugins>
</build>
...
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>1.1</version>
</dependency>
</dependencies>
...
</project>
你可以尝试 assemble 一个所谓的 fatjar 与 maven:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.gymformmanager.Main</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>assemble-all</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
这将在您的输出目录中创建一个名为 GymFormManager-jar-with-dependencies.jar 的附加 jar 文件。你可以 运行 它与:
java -jar GymFormManager-jar-with-dependencies.jar
我猜 javafx-maven-plugin is a good option to build JFX application. It is based on Java Packager Tool 并且可以构建本机包和 jar。呼叫 mvn jfx:jar
开始构建。
<plugin>
<!-- Generate Executable JFX JAR -->
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.8.3</version>
<configuration>
<vendor>${vendor}</vendor>
<mainClass>${mainClass}</mainClass>
<allPermissions>true</allPermissions>
<manifestAttributes>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
<Build-Timestamp-Format>${maven.build.timestamp.format}</Build-Timestamp-Format>
<Build-Timestamp>${dev.build.timestamp}</Build-Timestamp>
</manifestAttributes>
<jfxMainAppJarName>${jfxMainAppJarName}</jfxMainAppJarName>
</configuration>
<executions>
<execution>
<id>create-jfxjar</id>
<phase>package</phase>
<goals>
<goal>build-jar</goal>
</goals>
</execution>
</executions>
</plugin>