简体   繁体   English

Maven:具有依赖关系的jar + JavaDoc

[英]Maven: jar-with-dependencies + JavaDoc

I have a project that has a few dependencies on other Jars. 我有一个项目,该项目对其他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. 我目前使用JavaDoc插件和Assembly插件生成项目的.zip文件,其中包含我的Jar,依赖项Jars和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. 但是,我想把事情归结为这样,以便.zip中只有一个Jar,以及相关的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? 我知道程序集插件+ jar-with-dependencies是我的朋友,但是如何解决这个问题,以便我可以打包一个包含此jar的.zip文件和JavaDoc?

Relevant parts of my pom below: 下面是我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>

Relevant parts of dist-jwd.xml: 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: 以及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. 我猜这可能是鸡和蛋的问题,所以如果maven没有合适的解决方案,那么我将不得不手动执行某些操作。 However, I think what I'm trying to do is pretty common, so I would think there would be an easy way. 但是,我认为我想做的事很普遍,所以我认为会有一种简单的方法。

I ended up giving up and running a .sh script after the maven stuff to do what I wanted. 我最终放弃并运行了.m脚本来执行我想要的事情。

Unix to the rescue! 抢救Unix!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM