简体   繁体   中英

Adding jar files available in absolute path into classpath

I am using maven build tool. My intention is to add jar files available in a separate absolute folder [eg: C:\\test1.jar, C:\\test2.jar] into the classpath.

To do so, I am adding the below in my pom file.

<plugin>
 <artifactId>maven-war-plugin</artifactId>
 <version>2.2</version>
 <configuration>
  <archive>
   <manifest>
    <addClasspath>true</addClasspath>         
   </manifest>
   <manifestEntries> 
     <Class-Path>C:/test1.jar, C:/test2.jar</Class-Path> 
   </manifestEntries>
  </archive>
 </configuration>
</plugin> 

I could see the jars are added into the class-path of MANIFEST.MF file available in the war but when the war is deployed, it fails due to "java.lang.ClassNotFoundException" [related to test1.jar OR test2.jar].

Does this mean test1.jar and test2.jar added in the class-path of MANIFEST.MF is not added to classpath OR am I missing something or wrong here.

Please help me out to add jar files available in absolute path to classpath by using MANIFEST.MF of war file OR any other ideas to do the same.

Better solution is when you add your jar to maven repository and then use them like normal dependency. Here is command for adding jar to maven repo.

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
    -DartifactId=<artifact-id> -Dversion=1.0 -Dpackaging=jar

And then in your pom.xml

<dependency>
    <groupId><group-id></groupId>
    <artifactId><artifact-id></artifactId>
    <version>1.0</version>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM