views:

128

answers:

2

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"&gt;
  <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&lt;/url&gt;
  <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?

A: 

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:

$>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"&gt;
   <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&lt;/url&gt;

   <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>
naikus
I have added below. Still the same scenario.<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>
Even this also did not work Sir. Please can you help me
You will have to use mvn jar:jar command or mvn package command (if your project is a jar), and then check the contents of the jar file.
naikus
I am using mvn package only and checked the contents of the jar file. No no use.
Can you post the contents of your pom.xml in your question?
naikus
I have posted pom.xml
Okay, your pom.xml is all wrong, I'm surprised your project actually compiles. I've updated my answer with a pom.xml. Use that as your pom, add all your dependencies in the dependencies section.
naikus
A: 

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.

Pascal Thivent