简体   繁体   English

将绝对路径中可用的jar文件添加到类路径中

[英]Adding jar files available in absolute path into classpath

I am using maven build tool. 我正在使用maven构建工具。 My intention is to add jar files available in a separate absolute folder [eg: C:\\test1.jar, C:\\test2.jar] into the classpath. 我的目的是将一个单独的绝对文件夹[例如:C:\\ test1.jar,C:\\ test2.jar]中可用的jar文件添加到类路径中。

To do so, I am adding the below in my pom file. 为此,我在我的pom文件中添加以下内容。

<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]. 我可以看到jar被添加到战争中可用的MANIFEST.MF文件的类路径中但是当部署了war时,由于“java.lang.ClassNotFoundException”[与test1.jar或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. 这是否意味着在MANIFEST.MF的类路径中添加的test1.jar和test2.jar没有添加到类路径中,或者我在这里遗漏了什么或者错了。

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. 请帮助我通过使用战争文件的MANIFEST.MF或其他任何想法来添加以类路径的绝对路径提供的jar文件。

Better solution is when you add your jar to maven repository and then use them like normal dependency. 更好的解决方案是将jar添加到maven存储库,然后像普通依赖项一样使用它们。 Here is command for adding jar to maven repo. 这是将jar添加到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 然后在你的pom.xml中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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