Maven:jar-with-dependencies + JavaDoc

时间:2012-02-08 00:54:24

标签: java maven maven-assembly-plugin

我有一个项目,对其他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没有优雅的解决方案,那么我将不得不手动做一些事情。但是,我认为我想要做的事情非常普遍,所以我认为会有一个简单的方法。

1 个答案:

答案 0 :(得分:0)

我最终放弃并在maven之后运行.sh脚本来做我想做的事。

Unix救援!