简体   繁体   English

Maven-使用addjars-maven-plugin将jar添加到classpath中以创建Java项目

[英]Maven - addjars-maven-plugin to add jars to classpath for an java project build

I am using addjars-maven-plugin to add all the jars present in web-inf/lib to my classpath and i am able to build my web-application and package it as war . 我正在使用addjars-maven-pluginweb-inf/lib存在的所有jar添加到我的classpath并且能够构建我的web-application并将其打包为war

Is there any similar way to add all the jars present in some folder to classpath , while building java classes and package it as jar ? 有什么类似的方法可以将some folder存在的所有jar添加到classpath ,同时构建java classes并将其打包为jar

I tried the same plugin as below. 我尝试了如下相同的插件。 But, when i try to build my project, the jars are downloaded to my local repository . 但是,当我尝试构建项目时,罐子会下载到我的local repository But still i get class not found exception. 但是仍然我没有找到类的异常。

Kindly help. 请帮助。 Thanks in advance! 提前致谢!

    <build>
       <plugins>
                <plugin>
                  <groupId>com.googlecode.addjars-maven-plugin</groupId>
                  <artifactId>addjars-maven-plugin</artifactId>
                  <version>1.0.2</version>
                  <executions>
                    <execution>
                        <goals>
                            <goal>add-jars</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>${project.basedir}/src/main/extlib</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                  </executions>
                </plugin>
        </plugins>
  </build>

Full pom.xml content: 完整的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.xyz</groupId>
   <artifactId>testlogger</artifactId>
   <packaging>jar</packaging>
   <version>1.0</version>
    <build>
        <plugins>
            <plugin>
              <groupId>com.googlecode.addjars-maven-plugin</groupId>
              <artifactId>addjars-maven-plugin</artifactId>
              <version>1.0.2</version>
              <executions>
                <execution>
                    <goals>
                        <goal>add-jars</goal>
                    </goals>
                    <configuration>
                        <resources>
                            <resource>
                                <directory>${project.basedir}/src/main/extlib</directory>
                            </resource>
                        </resources>
                    </configuration>
                </execution>
              </executions>
            </plugin>
        </plugins>
    </build>
</project>

I could achieve adding the jars present in any folder by using addjars-maven-plugin as above but, the only change i had to make is change the version of the plugin from 1.0.2 to 1.0.5. 我可以通过使用上述的addjars-maven-plugin来添加存在于任何文件夹中的jar,但是,我唯一要做的更改是将插件的版本从1.0.2更改为1.0.5。 Thanks all for the support!! 谢谢大家的支持!

I had the same challenge with addjars-maven-plugin . 我对addjars-maven-plugin遇到了同样的挑战。 Calling mvn clean install it builds successfully but under eclipse (RAD 9.5) my source files could not be compiled because of missing jars. 调用mvn clean install可以成功构建,但是在eclipse(RAD 9.5)下,由于缺少jar,我的源文件无法编译。 Now add the maven-compiler-plugin : 现在添加maven-compiler-plugin

<build>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <includes>
            <include>${some.dir}/libs/*.jar</include>
        </includes>
    </configuration>
</plugin>

Nevertheless those jars are not added under Maven Dependencies in the project structure. 但是,这些jar并没有添加到项目结构中的Maven Dependencies下。

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

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