2
我知道这有点超出了maven的范围,但我需要将具有编译类的本地目录添加到模块的类路径中。 我看到:Maven: add a folder or jar file into current classpath,但这只适用于一个罐子。maven将本地类目录添加到模块的类路径
我需要有一个类似的解决方案,但编译类在本地文件系统上的目录。这甚至有可能吗?
Thx!
我知道这有点超出了maven的范围,但我需要将具有编译类的本地目录添加到模块的类路径中。 我看到:Maven: add a folder or jar file into current classpath,但这只适用于一个罐子。maven将本地类目录添加到模块的类路径
我需要有一个类似的解决方案,但编译类在本地文件系统上的目录。这甚至有可能吗?
Thx!
经过一番深入的研究后,我发现我最好的选择是使用maven-antrun-plugin,并在过程资源阶段从类中生成一个jar文件,并将它作为依赖项添加到系统范围和systemPath中我刚刚建造的罐子。
双龙片段:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="mpower.jar">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="${env.USERPROFILE}\.m2\repository\ant-contrib\ant-contrib\1.0b3\ant-contrib-1.0b3.jar"/>
<if>
<available file="${classes.dir}" type="dir"/>
<then>
<jar destfile="${env.TEMP}\classes.jar">
<fileset dir="${classes.dir}\classes">
<include name="**/**"/>
</fileset>
</jar>
</then>
<else>
<fail message="${classes.dir} not found. Skipping jar creation"/>
</else>
</if>
</target>
</configuration>
</execution>
</executions>
....
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
</dependency>
<dependency>
<groupId>com.my.code</groupId>
<artifactId>classes.jar</artifactId>
<version>1.1</version>
<scope>system</scope>
<systemPath>${env.TEMP}\classes.jar</systemPath>
</dependency>
非常感谢您在这里记录这一点。我有由Javassist动态生成的类,我无法在测试中使用它们。试过了Maven Build Helper插件,但它不起作用,因为我没有代码而是类文件。这是真正让我走的唯一的事情。谢谢! – khituras 2015-03-19 15:05:09