maven将一个本地类目录添加到模块的类路径中 [英] maven add a local classes directory to module's classpath
问题描述
我知道这有点超出了maven的范围,但我需要将一个带有编译类的本地目录添加到模块的类路径中。
我看到: Maven:添加一个文件夹或jar文件到当前的类路径,但这只适用于jar。
我需要一个类似的解决方案,但在目录中有编译的类本地文件系统。这甚至可能吗?
Thx!
经过一番广泛的讨论研究,我发现我最好的选择是使用maven-antrun-plugin,在进程资源阶段,从类中生成一个jar,并将其作为系统范围和systemPath的依赖项添加到我刚刚构建的jar中。 p>
Pom片段:
< 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.propertiesclasspath =$ {env.USERPROFILE} \.m2 \repository \-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>
<失败消息=$ {classes.dir}未找到。跳过jar创建/>
< / 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>
I know this is a bit out of maven's scope, but I need to add a local directory with compiled classes to the module's classpath. I saw: Maven: add a folder or jar file into current classpath, but this is good for a jar only.
I need to have a similar solution but with compiled classes in a directory on local file system. Is this even possible?
Thx!
After some extensive research, I found that my best option was to use the maven-antrun-plugin and during the process-resources phase, generate a jar from the classes and add it as dependency with system scope and systemPath to the jar I just built.
Pom snippets:
<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>
这篇关于maven将一个本地类目录添加到模块的类路径中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!