Maven:带有依赖项的 jar + Java文档

发布于 2025-01-03 19:53:05 字数 3846 浏览 1 评论 0原文

我有一个项目,它对其他 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魔法少女 2025-01-10 19:53:05

我最终放弃并在 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文