我有一个专有的jar,我想作为依赖添加到我的pom.
但我不想将它添加到存储库.原因是我希望我的常用maven命令等mvn compile开箱即用.(没有要求开发人员将其自己添加到某个存储库中).
我希望jar在源代码控制中位于第3方库中,并通过pom.xml文件的相对路径链接到它.
可以这样做吗?怎么样?
我正在使用maven-assembly插件来创建我的应用程序的jar,包括其依赖项如下:
<assembly>
<id>macosx</id>
<formats>
<format>tar.gz</format>
<format>dir</format>
</formats>
<dependencySets>
<dependencySet>
<includes>
<include>*:jar</include>
</includes>
<outputDirectory>lib</outputDirectory>
</dependencySet>
</dependencySets>
</assembly>
Run Code Online (Sandbox Code Playgroud)
(我省略了一些与问题无关的其他内容)
到目前为止,这工作得很好,因为它创建了一个lib包含所有依赖项的目录.但是,我最近添加了一个新的依赖项,其范围是system,并且它不会将其复制到lib输出目录.我必须遗漏一些基本的东西,所以我打电话求助.
我刚刚添加的依赖项是:
<dependency>
<groupId>sourceforge.jchart2d</groupId>
<artifactId>jchart2d</artifactId>
<version>3.1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/external/jchart2d-3.1.0.jar</systemPath>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我能够包含此依赖项的唯一方法是将以下内容添加到assembly元素:
<files>
<file>
<source>external/jchart2d-3.1.0.jar</source>
<outputDirectory>lib</outputDirectory>
</file>
</files>
Run Code Online (Sandbox Code Playgroud)
但是,这会强制我在重命名此jar时更改pom和程序集文件(如果有的话).而且,这似乎是错的.
我有试过<scope>runtime</scope>在dependencySets和<include>sourceforge.jchart2d:jchart2d</include>没有运气.
那么如何system在maven 2中将scoped jar 包含到汇编文件中?
非常感谢
我已经在Stack Overflow上找到了如何在项目中包含第三方JAR而不将其安装到"本地存储库"的答案:
我可以在没有安装的情况下将jar添加到maven 2 build classpath吗?
但是,当我使用Maven Shade插件创建包含项目所有依赖项的JAR时,第三方JAR不会自动包含在内.
如何让Maven Shade插件将这样的第三方JAR添加到着色的JAR中?
根据得到的答案,我做到了.我做的是,将这个片段添加到我的pom.xml的开头:
<repositories>
<repository>
<id>repo</id>
<url>file://${basedir}/repo</url>
</repository>
</repositories>
Run Code Online (Sandbox Code Playgroud)
然后为我的项目添加了一个依赖项,也添加到pom.xml:
<dependencies>
<dependency>
<groupId>dummy</groupId>
<artifactId>dummy</artifactId>
<version>0.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
然后运行命令行将包添加到'repo':
mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file
-Dfile=<my-jar>.jar -DgroupId=dummy -DartifactId=dummy
-Dversion=0.0.0 -Dpackaging=jar -DlocalRepositoryPath=`pwd`/repo/
Run Code Online (Sandbox Code Playgroud)
(不确定repo路径是否需要完整路径,但不想冒险.)
repo子目录的内容现在是:
repo/dummy/dummy/0.0.0/dummy-0.0.0.jar
repo/dummy/dummy/0.0.0/dummy-0.0.0.pom
repo/dummy/dummy/maven-metadata-local.xml
Run Code Online (Sandbox Code Playgroud)
现在我可以将其检入版本控制,并且没有本地或远程依赖项.
这是我的pom文件:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sia.g7</groupId>
<artifactId>sia</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>sia</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
<dependency>
<groupId>commons-math</groupId>
<artifactId>commons-math</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jmathplot</groupId>
<artifactId>jmathplot</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jmathplot.jar</systemPath>
</dependency>
<dependency>
<groupId>jgraphx</groupId>
<artifactId>jgraphx</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jgraphx.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>com.sia.g7.AbstractSimulation</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
当我运行罐子时,我得到:
Exception in thread "main" java.lang.NoClassDefFoundError: com/mxgraph/swing/mxGraphComponent …Run Code Online (Sandbox Code Playgroud) 我正在使用maven-compile插件来编译类.现在我想在当前的类路径中添加一个jar文件.该文件保留在另一个位置(假设c:/jars/abc.jar.我更喜欢将此文件保留在此处).我怎样才能做到这一点?
如果我在参数中使用classpath:
<configuration>
<compilerArguments>
<classpath>c:/jars/abc.jar</classpath>
</compilerArguments>
</configuration>
Run Code Online (Sandbox Code Playgroud)
它将无法工作,因为它将覆盖当前的类路径(包括所有依赖项)
请帮我.
我有一些我自己提供的依赖项.这些罐子位于资源目录中.在我的pom中,它们的范围是系统,我包括它们的路径.但是,当我使用程序集插件并使用时
<addClasspath>true</addClasspath>
Run Code Online (Sandbox Code Playgroud)
它不会添加系统jar的路径.如何让它们自动包含在内?
谢谢