无法在maven2的MANIFEST.MF中添加类路径

发布于 2024-09-13 10:28:51 字数 4413 浏览 3 评论 0原文

我正在尝试使用以下代码在 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中获取条目。怎么了?

I am trying to add class path in MANIFEST.MF in maven2 with following code but it is unable to add it.

<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>

Can you please help me.


Update: Below the updated 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>

But I still don't get the entries in my manifest.mf. what's wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猥︴琐丶欲为 2024-09-20 10:28:52

向清单添加类路径条目 ,您需要通过添加具有适当配置的 元素来告诉 Maven Jar 插件执行此操作。来自清单定制(略有调整):

自定义清单

默认清单可以更改
与存档配置
元素。下面你会发现一些
配置选项是
可用的。有关详细信息,请参阅 Maven
归档器参考。这个版本的
Maven JAR 插件使用 Maven Archiver
2.4.

<前><代码><项目>;
...
<构建>
<插件>
<插件>
org.apache.maven.plugins
maven-jar-plugin;
<版本>2.3.1
<配置>
<存档>
<索引>true
<清单>
true

<清单条目>
<模式>开发
${pom.url};
<键>值



...



...

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

我想我永远不会重复足够的人们不应该使用它系统范围的依赖项,但它们的用途是强烈劝阻

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

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

To Add a Class-Path Entry to the Manifest, you need to tell the Maven Jar Plugin to do so by adding an <archive> element with the appropriate configuration. From Manifest customization (slightly adapted):

Customization the Manifest

The default manifest can be altered
with the archive configuration
element. Below you will find some of
the configuration options that are
available. For more info see the Maven
Archiver reference. This version of
Maven JAR Plugin uses 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>

But the problem in your case is that you are (ab)using the evil system scope which by definition is for dependencies that are supposed to be always available and [are] not looked up in a repository. So don't expect Maven to put them in the Class-Path entry of the Manifest.mf.

I guess I'll never repeat enough that people should not use it system scoped dependencies, but their use is strongly discouraged:

system: This dependency is required in some phase of your project's lifecycle, but is system-specific. Use of this scope is discouraged: This is considered an "advanced" kind of feature and should only be used when you truly understand all the ramifications of its use, which can be extremely hard if not actually impossible to quantify. This scope by definition renders your build non-portable. It may be necessary in certain edge cases. The system scope includes the <systemPath> element which points to the physical location of this dependency on the local machine. It is thus used to refer to some artifact expected to be present on the given local machine an not in a repository; and whose path may vary machine-to-machine. The systemPath element can refer to environment variables in its path: ${JAVA_HOME} for instance.

Either install your jars in your local repository, or use a corporate repository, or use a file based repository. But don't use the system scope.

⊕婉儿 2024-09-20 10:28:52

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

编辑:
当你使用插件管理来配置插件时,你需要在元素中实际使用该插件。
请参阅 文档

<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>  

在控制台类型上:

gt;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>

The maven compiler plugin does not talk about a configuration attribute called "manifest", You may want to use the maven-jar-plugin. See this link on how to do it.

Edit:
When you are using the pluginManagement to configure plugins,you need to actually use the plugin in the elements.
See the documenttation

<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>  

On console type:

gt;mvn jar:jar

Edit use this 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文