我的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>com.spt</groupId>
<artifactId>astra</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>javafx</groupId>
<artifactId>javafx</artifactId>
<version>2.2.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jfxrt.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.spt.buket_3_wifi.desktop.Main</mainClass>sta
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>default-copy-resources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
它成功编译,依赖项log4j-1.2.17.jar和javafx-2.2.3.jar都被复制到lib文件夹。问题是lib / javafx-2.2.3.jar没有包含在jar清单文件中的Class-Path中,所以我无法运行它。 MANIFEST.MF是:
Manifest-Version: 1.0
Built-By: karasev
Build-Jdk: 1.7.0_40
Class-Path: lib/log4j-1.2.17.jar
Created-By: Apache Maven 3.1.0
Main-Class: com.spt.buket_3_wifi.desktop.Main
Archiver-Version: Plexus Archiver
如您所见,仅添加了lib / log4j-1.2.17.jar。有什么问题?有什么想法吗?
答案 0 :(得分:5)
您可以尝试这种方法:
...[truncated]...
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.spt.buket_3_wifi.desktop.Main</mainClass>
</manifest>
<manifestEntries>
<Class-Path>lib/javafx-2.2.3.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
...[truncated]...
但这对于JavaFX库来说并不是必需的,因为它已经在JVM类路径中了。