繁体   English   中英

maven将本地类目录添加到模块的类路径

[英]maven add a local classes directory to module's classpath

我知道这有点超出了Maven的范围,但是我需要在模块的类路径中添加包含已编译类的本地目录。 我看到了: Maven:将文件夹或jar文件添加到当前的classpath中 ,但这仅对jar有用。

我需要有一个类似的解决方案,但在本地文件系统上的目录中包含已编译的类。 这有可能吗?

谢谢!

经过大量研究,我发现我最好的选择是使用maven-antrun-plugin,并在流程资源阶段,从类中生成一个jar,并将其作为对系统范围和systemPath的依赖关系添加到我刚刚构建的jar中。

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.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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM