1

我正在尝试使用以下代码在 maven2 的 MANIFEST.MF 中添加类路径,但无法添加它。

<build>
  <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
            <source>1.5</source>
            <target>1.5</target>
            <manifest>
              <addClasspath>true</addClasspath>
              <useUniqueVersions>false</useUniqueVersions>
            </manifest>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
   <finalName>iHubServiceImpl</finalName>
</build>

你能帮我么。


更新:在更新的 pom.xml 下方:

<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>
  <parent>
    <groupId>com.adp.ihub</groupId>
    <artifactId>PreFinal</artifactId>
    <version>1</version>
  </parent>
  <groupId>com.adp.ihub</groupId>
  <artifactId>iHubCommon</artifactId>
  <version>1</version>
  <packaging>jar</packaging>
  <name>iHubCommon</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-jar-plugin</artifactId>
          <version>2.3.1</version>
          <configuration>
            <archive>
              <manifest>
                <addClasspath>true</addClasspath>
                <classpathLayoutType>simple</classpathLayoutType>
              </manifest>
              <manifestEntries>
                <mode>development</mode>
                <url>${pom.url}</url>
                <key>value</key>
              </manifestEntries>
            </archive>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <!-- Use the jar plugin for plugin management configuration to take effect -->    
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
      </plugin>
    </plugins>
    <sourceDirectory>${basedir}/src</sourceDirectory>
    <resources>
      <resource>
        <directory>${basedir}/src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
          <exclude>**/pom*</exclude>
        </excludes>
      </resource>
    </resources>
    <finalName>iHubCommon</finalName>
  </build>
  <dependencies>
    <dependency>
      <groupId>com.adp.ihub</groupId>
      <artifactId>BizLogic3</artifactId>
      <version>1</version>
      <scope>system</scope>
      <systemPath>${PWD}/iHUBCM/Environment/lib/BizLogic3.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>com.adp.ihub</groupId>
      <artifactId>EncryptionAPI-jdk15-0.4</artifactId>
      <version>1</version>
      <scope>system</scope>
      <systemPath>${PWD}/iHUBCM/Environment/lib/EncryptionAPI-jdk15-0.4.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>com.adp.ihub</groupId>
      <artifactId>adpbod-1.0</artifactId>
      <version>1</version>
      <scope>system</scope>
      <systemPath>${PWD}/iHUBCM/Environment/lib/adpbod-1.0.jar</systemPath>
    </dependency>
  </dependencies>
</project>

但我仍然没有得到 manifest.mf 中的条目。怎么了?

4

2 回答 2

4

要将Class-Path 条目添加到 Manifest<archive> ,您需要通过添加具有适当配置的元素来告诉 Maven Jar 插件这样做。来自Manifest 定制(稍作改编):

自定义清单

可以使用存档配置元素更改默认清单。您将在下面找到一些可用的配置选项。有关更多信息,请参阅 Maven 存档器参考。此版本的 Maven JAR 插件使用 Maven Archiver 2.4。

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.1</version>
        <configuration>
          <archive>
            <index>true</index>
            <manifest>
              <addClasspath>true</addClasspath>
            </manifest>
            <manifestEntries>
              <mode>development</mode>
              <url>${pom.url}</url>
              <key>value</key>
            </manifestEntries>
          </archive>
        </configuration>
        ...
      </plugin>
    </plugins>
  </build>
  ...
</project>

但是在您的情况下,问题是您正在(ab)使用邪恶的 system范围,根据定义,该范围适用于应该始终可用并且[未]在存储库中查找的依赖项。所以不要期望 Maven 将它们放在 Manifest.mf 的 Class-Path 条目中。

我想我永远不会重复人们不应该使用它system的作用域依赖项,但强烈建议不要使用它们:

system:此依赖项在项目生命周期的某个阶段是必需的,但特定于系统。不鼓励使用此范围:这被认为是“高级”类型的功能,只有在您真正了解其使用的所有后果时才应使用,如果不是实际上无法量化,这可能会非常困难。根据定义,此范围使您的构建不可移植。在某些边缘情况下可能是必要的。系统范围包括<systemPath>指向此依赖项在本地机器上的物理位置的元素。因此,它用于指代预期会出现在给定本地机器上而不是存储库中的某些工件;并且其路径可能因机器而异。元素可以在其systemPath路径中引用环境变量:${JAVA_HOME}例如。

要么在本地存储库中安装 jar,要么使用公司存储库,或者使用基于文件的存储库。但不要使用system范围。

于 2010-08-10T14:43:26.223 回答
0

maven 编译器插件不讨论名为“manifest”的配置属性,您可能希望使用 maven-jar-plugin 。请参阅此链接以了解如何操作。

编辑:当您使用 pluginManagement 配置插件时,您需要实际使用元素中的插件。请参阅文档

<build>
   <pluginManagement>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
               <archive>
                  <manifest>
                     <addClasspath>true</addClasspath>
                  </manifest>
                  <manifestEntries>
                     <mode>development</mode>
                     <url>${pom.url}</url>
                     <key>value</key>
                  </manifestEntries>
               </archive>
            </configuration>
         </plugin>
     </plugins>
  </pluginManagement>

  <plugins>
      <!-- Use the jar plugin for plugin management configuration to take effect -->
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
      </plugin>
  </plugins>
</build>  

在控制台类型上:

$>mvn jar:jar

编辑使用这个 pom.xml

<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.adp.ihub</groupId>
   <artifactId>PreFinal</artifactId>
   <version>1</version>
   <packaging>jar</packaging>

   <name>PreFinal</name>
   <url>http://maven.apache.org</url>

   <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>

   <dependencies>
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>3.8.1</version>
         <scope>test</scope>
      </dependency>

      <!-- !!! ADD YOUR DEPENDENCIES HERE !!! -->
   </dependencies>

   <build>
      <pluginManagement>
         <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-jar-plugin</artifactId>
               <version>2.3.1</version>
               <configuration>
                  <archive>
                     <manifest>
                        <addClasspath>true</addClasspath>
                     </manifest>
                     <manifestEntries>
                        <mode>development</mode>
                        <url>${pom.url}</url>
                        <key>value</key>
                     </manifestEntries>
                  </archive>
               </configuration>
            </plugin>
         </plugins>
      </pluginManagement>

      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
         </plugin>
      </plugins>
   </build>
</project>
于 2010-08-10T06:58:59.793 回答