我有一个使用 LWJGL 的项目,我想将所需的 jar 和相关的 native 复制到生成的 jar 的输出目录中。我不想将依赖项注入(inject)到最终的 jar 本身中。
我可以运行 mvn package
和 mvn dependency:copy-dependencies
,两者都很好用。
我尝试运行目标“copy-dependency”是通过向“maven-dependency-plugin”添加执行,如下所示:
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/libs
</outputDirectory>
</configuration>
</execution>
</executions>
再次,如 this answer 所引用,结果相同:打包完成,创建一个 jar,但旁边没有依赖项。没有记录 prepare-package
正在发生,或者 maven-dependency-plugin
正在运行。
我还尝试过绑定(bind)到其他阶段,例如 package
、validate
、test
,但它们都不会导致执行发生。这是我的 pom.xml
中的唯一执行。我只有几个插件:
maven-clean-plugin
maven-resources-plugin
maven-compiler-plugin
maven-jar-plugin (with a config declaring its manifest, shown below)
maven-install-plugin
maven-dependency-plugin
上述配置:
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>libs/</classpathPrefix>
<mainClass>
xyz.valnet.hadean.HadeanGame
</mainClass>
</manifest>
</archive>
</configuration>
我另外还有 3 个配置文件,用于通过设置属性 lwjgl-natives
以及在依赖项中使用的属性来选择要使用的 LWJGL native 。
我的问题主要是:哪些事情可能导致此执行不发生。
最佳答案
<pluginManagement>
下列出的插件只会由子目录中具有自己的 pom.xml
的项目执行
在当前项目中执行的插件应列出,不带 <pluginManagement>
修复删除pluginManagement,或重新组织插件以正确反射(reflect)应运行哪些插件以及应将哪些插件用于子项目。
<build>
<plugins>
[...]
</plugins>
<pluginManagement>
<plugins>
[...]
</plugins>
</pluginManagement>
</build>
关于java - 如何使用 `maven package` 将依赖项复制到输出目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75036298/