的关注
https://github.com/javafx-maven-plugin/javafx-basic-archetype
我使用:
mvn archetype:generate -DarchetypeGroupId=com.zenjava -DarchetypeArtifactId=javafx-basic-archetype
然后,我从项目目录中执行了mvn package
,并生成了jar。
我尝试通过双击运行jar,但没有任何反应。
我试图通过命令行运行:java -jar Tester.jar
但我得到错误:
目标\ Tester.jar
中没有主要的清单属性
注意:如果我导入项目并运行它,它确实从IntelliJIDEA运行,但IntelliJ不生成.jar
,只生成.class
个文件。
这是它产生的pom:
<?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>testgroup</groupId>
<artifactId>Tester</artifactId>
<name>Tester</name>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<organization>
<!-- Used as the 'Vendor' for JNLP generation -->
<name>testorg</name>
</organization>
<properties>
<slf4j.version>1.7.12</slf4j.version>
<log4j.version>1.2.17</log4j.version>
</properties>
<build>
<finalName>Tester</finalName>
<plugins>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.5</version>
<configuration>
<mainClass>testgroup.MainApp</mainClass>
<!-- only required if signing the jar file -->
<keyStoreAlias>example-user</keyStoreAlias>
<keyStorePassword>example-password</keyStorePassword>
<allPermissions>true</allPermissions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- MigLayout -->
<dependency>
<groupId>com.miglayout</groupId>
<artifactId>miglayout-javafx</artifactId>
<version>5.0</version>
</dependency>
<!-- Apache Commons -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
</project>
答案 0 :(得分:1)
错误消息基本上意味着您没有Manifest.MF文件中指定的主类的路径。
在pom.xml文件中添加以下代码行,并更改mainClass
参数以获取正确的代码:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.maventest.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
在此之后,您应该运行mvn clean package
命令,然后尝试运行您的应用程序。