通常,我们在pom.xml中使用 dependency 标记,以使Maven在类路径上包含JAR,并且还将依赖关系打包。
如果在同一项目的构建步骤中生成JAR,该怎么办?我的意思是,生成它的不是编译插件,它是一个没有任何Java源代码的JAR,并且由外部可执行文件创建。
我可以使用maven exec插件生成我的JAR,并使用maven安装插件将其安装到本地存储库。但是我仍然不能在同一个项目中将它作为依赖项:无论我将JAR generator命令放入哪个阶段,依赖项检查都将在此之前进行,并且失败,因为JAR尚不存在。
系统范围依赖性是我的最佳选择吗?然后我需要放弃包装。它已被弃用。而且JAR必须位于项目目录之外。
还是JAR生成器必须位于单独的pom中?也不是很好,因为JAR仅用于此项目。
我可以配置依赖项插件来推迟依赖项检查并下载到编译阶段吗?
还有其他解决方法吗?
这个pom几乎可以用,但是第一次我需要手动将生成的东西安装到仓库中。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>something-parent</artifactId>
<groupId>something</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>something-sample</artifactId>
<properties>
<jnbridge.path>C:/Program Files (x86)/JNBridge/JNBridgePro v9.0</jnbridge.path>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-proxies-jar</id>
<phase>generate-test-resources</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>jnbproxy.bat</executable>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>process-test-resources</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>jnbridge.local</groupId>
<artifactId>proxies</artifactId>
<version>0.0.0</version>
<packaging>jar</packaging>
<file>${basedir}/proxies.jar</file>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!--
Yes, these are true system-scope dependencies. JNBridge is expected to be
installed on the system wherever this project is built.
-->
<dependency>
<groupId>com.jnbridge.org.apache</groupId>
<artifactId>bcel</artifactId>
<version>5.1</version>
<scope>system</scope>
<systemPath>${jnbridge.path}/jnbcore/bcel-5.1-jnbridge.jar</systemPath>
</dependency>
<dependency>
<groupId>com.jnbridge</groupId>
<artifactId>jnbcore</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${jnbridge.path}/jnbcore/jnbcore.jar</systemPath>
</dependency>
<!--
This one will be installed to local maven repo in the process-test-resources phase,
as defined in the project/build/plugins section of this file.
-->
<dependency>
<groupId>jnbridge.local</groupId>
<artifactId>proxies</artifactId>
<version>0.0.0</version>
</dependency>
<!-- other dependencies... -->
</dependencies>
</project>