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

标签 java maven classpath

我知道这有点超出 maven 的范围,但我需要将包含已编译类的本地目录添加到模块的类路径中。 我看到了:Maven: add a folder or jar file into current classpath ,但这仅适用于 jar 。

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

谢谢!

最佳答案

经过一些广泛的研究,我发现我最好的选择是使用 maven-antrun-plugin 并在 process-resources 阶段,从类中生成一个 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>

关于java - maven 将本地类目录添加到模块的类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9925263/

相关文章:

tomcat - 如何在 Windows 7 中为 tomcat 6 设置类路径

java - 使用 Play Java 从 Firebase 接收 Json

java - Java 和 JSF 2.0 是嵌入式使用的可行替代方案吗?

java - 使用httpclient以同步方式执行rest调用

maven - 使用自定义 Checkstyle 运行 Maven Checkstyle

java - 如何使用maven for spring-boot在模块之间共享application.properties

java - 在一台服务器上运行不同的项目

mysql - 如何在 Hibernate、MySQL 应用程序中使用 import.sql 文件将默认数据插入表中

java - 如何读取jar内的属性文件?

java - 尝试创建 jar 时 list 文件中的行太长