Maven:带有依赖项的 jar + Java文档
我有一个项目,它对其他 Jars 有一些依赖。我目前使用 JavaDoc 插件和 Assembly 插件生成项目的 .zip,其中包含我的 Jar、依赖项 Jars 以及 javadoc。
但是,我想将事情归结为 .zip 中只有一个 Jar 以及相关的 JavaDoc。我知道程序集插件 + jar-with-dependencies 是我的朋友,但是我如何解决这个问题,以便我可以将包含此 jar 的 .zip 与我的 JavaDoc 一起打包?
我的 pom 的相关部分如下:
<properties>
<assemblyJar>${project.build.finalName}.jar</assemblyJar>
<assemblyJwd>${project.build.finalName}-jar-with-dependencies.jar</assemblyJwd>
<java.code.version>1.4</java.code.version>
</properties>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version> <!-- 2.3 might be needed -->
<configuration>
<descriptors>
<descriptor>src/assembly/dist-jwd.xml</descriptor>
</descriptors>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-jwd</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version> <!-- 2.3 might be needed -->
<configuration>
<descriptors>
<descriptor>src/assembly/dist.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
dist-jwd.xml 的相关部分:
<id>dist-jwd</id>
<includeBaseDirectory>true</includeBaseDirectory>
<files>
<file>
<fileMode>444</fileMode>
<source>target/${assemblyJar}</source>
<outputDirectory></outputDirectory>
</file>
</files>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<scope>compile</scope>
<excludes>
<exclude>javax.servlet:servlet-api</exclude>
</excludes>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
以及 dist.xml 的相关部分:
<id>dist-zip</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<fileMode>444</fileMode>
<directory>target/site/apidocs</directory>
<outputDirectory>javadoc</outputDirectory>
</fileSet>
</fileSets>
<files>
<file>
<fileMode>444</fileMode>
<source>target/${assemblyJwd}</source>
<outputDirectory></outputDirectory>
</file>
</files>
目前我收到错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2.1:single (make-jwd) on project deviceinsight-api-java: Failed to create assembly: Error adding file to archive: /Users/barmistead/Mercurial/deviceinsight-print/target/deviceinsight-api-java-3.1.16-1-SNAPSHOT-jar-with-dependencies.jar isn't a file. -> [Help 1]
我猜这可能是先有鸡还是先有蛋的问题,所以如果 maven 不这样做如果没有一个优雅的解决方案,那么我将不得不手动执行一些操作。然而,我认为我想做的事情很常见,所以我认为会有一个简单的方法。
I have a project that has a few dependencies on other Jars. I currently use the JavaDoc plugin and Assembly plugin to generate a .zip of my project, which contains my Jar, the dependency Jars, plus the javadoc.
However, I would like to boil things down so that there is only a single Jar inside the .zip, along with the relevant JavaDoc. I know that the assembly plugin + jar-with-dependencies is my friend for this, but how do I work it out such that I can package up a .zip containing this jar, along with my JavaDoc?
Relevant parts of my pom below:
<properties>
<assemblyJar>${project.build.finalName}.jar</assemblyJar>
<assemblyJwd>${project.build.finalName}-jar-with-dependencies.jar</assemblyJwd>
<java.code.version>1.4</java.code.version>
</properties>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version> <!-- 2.3 might be needed -->
<configuration>
<descriptors>
<descriptor>src/assembly/dist-jwd.xml</descriptor>
</descriptors>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-jwd</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version> <!-- 2.3 might be needed -->
<configuration>
<descriptors>
<descriptor>src/assembly/dist.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-zip</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
Relevant parts of dist-jwd.xml:
<id>dist-jwd</id>
<includeBaseDirectory>true</includeBaseDirectory>
<files>
<file>
<fileMode>444</fileMode>
<source>target/${assemblyJar}</source>
<outputDirectory></outputDirectory>
</file>
</files>
<dependencySets>
<dependencySet>
<outputDirectory>lib</outputDirectory>
<scope>compile</scope>
<excludes>
<exclude>javax.servlet:servlet-api</exclude>
</excludes>
<useProjectArtifact>false</useProjectArtifact>
</dependencySet>
</dependencySets>
And relevant parts of dist.xml:
<id>dist-zip</id>
<formats>
<format>zip</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<fileMode>444</fileMode>
<directory>target/site/apidocs</directory>
<outputDirectory>javadoc</outputDirectory>
</fileSet>
</fileSets>
<files>
<file>
<fileMode>444</fileMode>
<source>target/${assemblyJwd}</source>
<outputDirectory></outputDirectory>
</file>
</files>
Currently I get the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2.1:single (make-jwd) on project deviceinsight-api-java: Failed to create assembly: Error adding file to archive: /Users/barmistead/Mercurial/deviceinsight-print/target/deviceinsight-api-java-3.1.16-1-SNAPSHOT-jar-with-dependencies.jar isn't a file. -> [Help 1]
I'm guessing this is a possible chicken-and-egg problem, so If maven doesn't have a graceful solution then I will have to do something manually. However, I think what I'm trying to do is pretty common, so I would think there would be an easy way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终放弃并在 Maven 之后运行 .sh 脚本来做我想做的事情。
Unix 来救援!
I ended up giving up and running a .sh script after the maven stuff to do what I wanted.
Unix to the rescue!