如何在maven jar构建过程中包含外部jar?

Mat*_*cke 19 jar maven-plugin maven maven-assembly-plugin

我想在maven中构建一个带有依赖项的.jar文件.不幸的是,我必须在buildpath中包含一些外部.jars.当我现在尝试使用maven包构建此项目时,我将收到一个错误,即找不到那些外部.jars.

如何调整我的pom文件来添加这些罐子?当前:

    <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2-beta-4</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    </plugins>
Run Code Online (Sandbox Code Playgroud)

bas*_*mes 13

您可以将构建路径中的外部jar包含为依赖项<scope>system</scope> .

检查此链接

  • 它看起来是正确的,但如果它不是JDK的一部分,如示例所示.如果您想引用与pom位于同一目录中的JAR,该怎么办?(在项目文件夹中) (6认同)
  • 嗯,很好,但那个dep将不会与你的jar /战争打包. (4认同)
  • 根据 Maven 官方页面,现在已弃用。 (4认同)

小智 6

您需要使用以下命令将外部jar添加到.m2文件夹中

mvn install:install-file -Dfile=[JAR] -DgroupId=[some.group] -DartifactId=[Some Id] -Dversion=1.0.0 -Dpackaging=jar
Run Code Online (Sandbox Code Playgroud)

这会将给定的jar添加到.m2文件夹中.之后转到pom.xm并添加具有给定组ID,工件ID和版本的依赖项.