Maven通过systemPath/system添加jar,但不会添加到war或其他任何地方

Ber*_*own 18 java maven

我想通过systemPath从本地文件系统相对于我的项目目录结构添加一个jar文件,而不是在远程存储库上.我添加了依赖声明,但maven没有做任何其他事情.

在下面的声明中,我希望将jar文件复制到我的目标web-inf/lib目录,并将jar文件作为war文件的一部分.目前,这种情况不会发生.如何将jar文件复制到我的war文件中?

这是调试maven模式的输出:

DEBUG] cglib:cglib-nodep:jar:2.2:test (setting scope to: compile)^M
DEBUG] Retrieving parent-POM: org.objenesis:objenesis-parent:pom:1.2 for project: null:objenesis:ja
DEBUG]   org.objenesis:objenesis:jar:1.2:test (selected for test)^M
DEBUG]   org.javap.web:testRunWrapper:jar:1.0.0:system (selected for system)^M
DEBUG] Plugin dependencies for:
...


<dependency>
    <groupId>org.javap.web</groupId>
    <artifactId>testRunWrapper</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/testRunWrapper.jar</systemPath>
</dependency>
<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>                 
        <webResources>
            <resource>
                <directory>WebContent</directory>
            </resource>
        </webResources>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

Ber*_*own 25

好的,我这样做了:注意底部的目录结构.使用下面的方法,来自相对项目路径的jar文件被视为与其他jar一样的一等公民.下面的列表更正了我原来的问题.使用下面的pom.xml列表,jar文件将复制到我的目标目录.

<repositories>
    <repository>
        <id>JBoss</id>
        <name>JBoss Repository</name>
        <layout>default</layout>
        <url>http://repository.jboss.org/maven2</url>
    </repository>

    <repository>
       <id>my-local-repo</id>
       <url>file://${basedir}/lib/repo</url>
    </repository>
</repositories>

<dependency>
    <groupId>testRunWrapper</groupId>
    <artifactId>testRunWrapper</artifactId>
    <version>1.0.0</version>            
</dependency>
Run Code Online (Sandbox Code Playgroud)
$ find repo
repo
repo/testRunWrapper
repo/testRunWrapper/testRunWrapper
repo/testRunWrapper/testRunWrapper/1.0.0
repo/testRunWrapper/testRunWrapper/1.0.0/testRunWrapper-1.0.0.jar
Run Code Online (Sandbox Code Playgroud)


小智 18

使用maven依赖插件完成工作:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
                        <includeScope>system</includeScope>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)


Wil*_*son 6

不要使用系统.要执行您想要的操作,只需将其声明为常规(编译)依赖项,并将mvn install:install-file用于本地存储库.其他所有内容都可以按照您的需要运行(lib将被复制等).这意味着构建只能在您的计算机上运行.

要为您的(内部)团队正确修复此问题,您需要设置一个存储库(例如Artifactory,Nexus或Archiva).对于团队使用Maven来说,这几乎是必须的.

如果这是用于公共(例如开源)使用,您可以通过http服务器模拟存储库或建立真实的存储库.