Dra*_*ase 5 java dependencies repository maven
在过去一个小时左右的时间里,我一直在尝试让我的 Maven 项目包含其依赖项中的源文件,但由于某种原因,事实并非如此。我已按照以下链接提供的步骤进行操作,但是当我编译并运行插件时,出现 ClassNotFoundException:
https://github.com/mkremins/fanciful
我已确保将上面链接中的依赖项和存储库包含到我的 pom.xml 文件中,但是当我编译时,它们不会添加到我的 .jar 文件中。
我对使用 Maven 还很陌生,到目前为止还很喜欢它,尽管解决这样的问题可能会很痛苦。
我正在通过执行以下操作来构建该项目:
右键单击项目 -> 运行方式 -> Maven 构建 -> 目标:全新安装
经过一番探索,我发现事情并不像我想象的那么容易。我将以下内容添加到我的 pom.xml 构建部分:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>mkremins:fanciful</include>
<include>org.json:json</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Run Code Online (Sandbox Code Playgroud)
唯一的问题是我还需要手动包含我想要使用的主库的依赖项 - mkremins:fanciful; 是否有标志或选项可以自动从我需要的一个文件复制依赖项,而不是还包括<include>org.json:json</include>
?
好吧,如果你想将依赖项复制到目标 jar,你需要告诉 maven 这样做!Maven 不知道您的项目的工件是否是自给自足的可执行 jar、要在容器内执行的 jar 或只是另一个项目的依赖项或库。
您可能想使用maven-dependency-plugin中的复制依赖项任务
例如:
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}</outputDirectory>
<excludeTransitive>false</excludeTransitive>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
为了进行更多调整,您可能还想使用 jar 插件和程序集插件。有关创建可执行 jar 的更多信息:
http://www.ibm.com/developerworks/java/library/j-5things13/index.html?ca=dat-
归档时间: |
|
查看次数: |
6228 次 |
最近记录: |