maven add a local classes directory to module's classpath

亡梦爱人 提交于 2019-12-30 07:22:46

问题


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!


回答1:


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>


来源:https://stackoverflow.com/questions/9925263/maven-add-a-local-classes-directory-to-modules-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!