简体   繁体   English

如何从maven项目引用非maven项目(在eclipse工作区中)?

[英]How to reference a non-maven project (in eclipse workspace) from a maven project?

I am working on a new project which is a plugin for a product. 我正在开发一个新项目,它是一个产品的插件。

I use maven to build my plugin (zip) but I need to reference the source code of the product which is defined in my Eclipse workspace. 我使用maven来构建我的插件(zip),但我需要引用在Eclipse工作区中定义的产品的源代码。 But this source code is not managed by Maven and I do not want to migrate it. 但是这个源代码不是由Maven管理的,我不想迁移它。

Is it possible to refers this workspace project by any way? 是否可以通过任何方式引用此工作空间项目? (maven plugins, workaround welcome). (maven插件,解决方法欢迎)。

The dependency is just needed for the compilation inside Eclipse but will not be packaged in the plugin itself ( provided scope). Eclipse中的编译只需要依赖项,但不会在插件本身中打包( provided范围)。

I have also m2e in Eclipse and I want to keep this configuration when I make a "Maven Update". 我在Eclipse中也有m2e,我想在进行“Maven更新”时保留这个配置。

UPDATE: I am looking for a solution which will work with a mvn clean install on a command line because I want to be able to execute the build from a CI platform (eg Jenkins) 更新:我正在寻找一个解决方案,它将在命令行上使用mvn clean install ,因为我希望能够从CI平台执行构建(例如Jenkins)

Simply use Project -> Properties -> Java Build Path -> Projects -> Add 只需使用Project - > Properties - > Java Build Path - > Projects - > Add

If you need to compile it outside Eclipse you can add a dependency to physical jar location: 如果需要在Eclipse外部编译它,可以在物理jar位置添加依赖项:

 <dependency>
    <groupId>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/test.jar</systemPath>
</dependency>

You might consider using the antrun plugin to trigger the compilation of your source code in the external project linked to your compile phase. 您可以考虑使用antrun插件在链接到编译阶段的外部项目中触发源代码的编译。 You could even copy your .class files into your target folder so the runtime classpath finds them 您甚至可以将.cl​​ass文件复制到目标文件夹中,以便运行时类路径找到它们

Because I have already the compiled source and I do not need to recompile them (or to modify anything) I decided to package them using the pom assembly. 因为我已经编译了源代码而且我不需要重新编译它们(或修改任何东西)我决定使用pom程序集打包它们。

I made a separate project (under the same parent's than my plugins developement projects) called like openemm-src: 我创建了一个单独的项目(在与我的插件开发项目相同的父项下),类似于openemm-src:

  Parent project (openemm-plugin-dev)
       |- plugin-1
       |- plugin-2
       |- openemm-src 
              |- pom.xml 

The pom.xml for the openemm-src project looks like: openemm-src项目的pom.xml如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>openemm.plugin.dev</groupId>
        <artifactId>plugin</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <artifactId>openemm-src</artifactId>
    <version>1.0.0</version>
    <packaging>pom</packaging>
    <name>OpenEMM Source Code Library</name>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>src/assembly/src-plugin.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    <xecution>
                </executions>
            </plugin>

        </plugins>
    </build>
</project>

and the file src/assembly/src-plugin.xml : 和文件src/assembly/src-plugin.xml

<assembly>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>

    <fileSets>
        <fileSet>
            <directory>build/classes</directory>
            <outputDirectory></outputDirectory>
        </fileSet>
    </fileSets>
</assembly> 

After this, I refers the jar from the siblings projects like this: 在此之后,我从兄弟姐妹项目中引用了这样的jar:

<dependency>
    <groupId>openemm.plugin.dev</groupId>
    <artifactId>openemm-src</artifactId>
    <version>1.0.0</version>
    <scope>provided</scope>
</dependency>

This solution is looking more like a workaround, but this is because the OpenEMM project does not have any "Plugin Template Project" to be managed with Maven. 此解决方案看起来更像是一种解决方法,但这是因为OpenEMM项目没有任何“插件模板项目”可以使用Maven进行管理。

Note this is just a partial configuration and I had also to refers to the Agnitas libraries which did not contains all the source code (both were necessary to compile my code). 请注意,这只是一个部分配置,我还要引用Agnitas库,它们不包含所有源代码(两者都是编译我的代码所必需的)。

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

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