【问题标题】:Maven systemPath dependency not added to Class-Path in manifest [duplicate]Maven systemPath 依赖项未添加到清单中的 Class-Path [重复]
【发布时间】:2013-12-24 06:51:41
【问题描述】:

我的 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。有什么问题?有什么想法吗?

【问题讨论】:

    标签: java maven jar


    【解决方案1】:

    你可以试试这个方法:

    ...[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 库不是必需的,因为它已经在 J​​VM 类路径中。

    【讨论】:

      猜你喜欢
      • 2020-09-22
      • 1970-01-01
      • 2016-01-16
      • 2015-02-14
      • 1970-01-01
      • 2020-11-24
      • 2016-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多