English 中文(简体)
Maven jar 依赖关系和关系
原标题:Maven jar dependencies and relations

我试图寻找现有问题, 但找不到任何问题, 感觉我的问题很简单, 但可能是因为这个问题很具体, 我无法在任何地方找到答案。

总之,我和马文有两个项目,第二个项目依赖/需要第一个项目的某些类别。在某些情况下,我希望依赖JAR而不是项目依赖。

I solved this by creating an additional jar with maven-jar-plugin, where i included the needed classes. The jar was correctly created and was output in ${project.build.directory}. But the pom of project A is located in the same directory, that is/was a pain for me and for project B, cause of the dependencies used in project A. (is there a way to ignore the pom located in ${project.build.directory} ??? like:

<dependency>
            <groupId>projectA.groupId</groupId>
            <artifactId>A</artifactId>
            <version>1x-SNAPSHOT</version>
            <classifier>classes</classifier>
                    ->  <ignorePom>true</ignorePom>
        </dependency>

) )

Now I´m using the system scope for the dependency and its working fine after adding the systempath. Although the scope system must be avoided everywhere it is possible. The Systempath is annoying me because this is not a good practice and because of the absolute path.

我知道,我可以把创造的罐子 安装到存储库里 通过使用

mvn 安装:安装 - 文件

但我想尽可能使这个过程自动化,你有什么建议?

提前感谢

最佳回答

最好的解决办法是使用存储器管理器,真正释放第一个罐子,并在需要的地方建立真正的依赖关系。

基于您所写的内容, 我将建议创建一个单独的 Maven 工程, 包含其他几个模块将使用的分类, 释放它, 并简单地使用该模块的依赖性。 这将完全解决您的问题 。

问题回答

Maven 不支持在罐子上的依附关系。 有系统范围, 但范围非常有限, 并可能导致各种麻烦。 如果您需要依赖 Jar, 您需要指定一个独特的群集Id 和 articleId 。 如果您不想在 Maven 建它, 您可以将它配置给您的本地回收管理器( 或者甚至您本地安装 mvn 安装:安装文件的 repo ) 。

取决于配有分类器的罐子的工作效果,但效果不好,因为反应堆不能适当地将它们纳入多模块项目。

您是否读过有关'的文件?http://maven.apache.org/guides/introduction/introduction/introduction-to-dependency-mechanis.html' rel=“nofollow”>>Maven ?如果您有使用Maven来定义您的项目,那么您不必做任何特殊工作才能使依赖性发挥作用。

对于您的需求,您有两个选择: 创建两个独立的项目, 其中一个项目依赖于另一个 OR, 您可以创建一个多模块项目, 其中一个模块仍然依赖于另一个模块 。

<强 > 两个单独的项目

.
 |-- A
 |   `-- pom.xml
 |   `-- src
 |       `-- main
 |           `-- java
 `-- B
     `-- pom.xml
     `-- src
         `-- main
             `-- java

A/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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company</groupId>
    <artifactId>A</artifactId>
    <version>1.0-SNAPSHOT</version>
</project>

B/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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company</groupId>
    <artifactId>B</artifactId>
    <version>2.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.company</groupId>
            <artifactId>A</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

就是这样,你对B中的A型项目/模块有依赖性

您首先通过发行 mvn 安装 (并存于目录A) 来构建工程 A。 文物将安装在您的本地副本中( 并可供其他工程使用 ) 。

然后您通过发行 mvn 安装 (并在目录B中) 来构建工程 B。 文物将安装在您的本地副本中 。

< 强度 > 带有子模块 < /强 > 的父项目

.
 |-- A
 |   `-- pom.xml
 |   `-- src
 |       `-- main
 |           `-- java
 `-- B
 |   `-- pom.xml
 |   `-- src
 |       `-- main
 |           `-- java
 `-- pom.xml

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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company</groupId>
    <artifactId>parent</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>

    <modules>
        <module>A</module>
        <module>B</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.company</groupId>
                <artifactId>A</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>

是用来帮助子模块选择正确版本的 。

A/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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.company</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <groupId>com.company</groupId>
    <artifactId>A</artifactId>

</project>

B/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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.company</groupId>
        <artifactId>parent</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <groupId>com.company</groupId>
    <artifactId>B</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.company</groupId>
            <artifactId>A</artifactId>
        </dependency>
    </dependencies>
</project>

有了这个解决方案, 您只需在父文件夹中定位自己, 并运行 < code> mvn 安装 < / code > (或 < code> mvn 软件包 或类似) 。 现在您将按照正确的顺序构建 A 和 B, 整个工程可以导入到 Eclipse 中 。





相关问题
In Eclipse, why doesn t "Show In" appear for non-Java files?

If I have a *java file open, I can right click on the source, scroll down to "Show In (Alt-Shift-W)", and select Navigator. If I have an *xml, *jsp, or pretty much anything besides a Java source ...

Eclipse: Hover broken in debug perspective

Since upgrading Eclipse (Galileo build 20090920-1017), hover in debug no longer displays a variable s value. Instead, hover behaves as if I were in normal Java perspective: alt text http://...

Eclipse smart quotes - like in Textmate

Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the " key? I m a newbie here so be ...

Indentation guide for the eclipse editor

Is there a setting or plugin for eclipse that can show indentation guides in the editor? Something like the Codekana plugin for visual studio (not so fancy is also OK). Important that it works with ...

Adding jar from Eclipse plugin runtime tab

I want to add .jar files for plugin from the Runtime tab of manifest file. When I use the Add... button, I can see only sub-directories of the plugin project. So if I want to add same .jar file to ...

How to copy multiple projects into single folder in eclipse

I have two projects, Project1 and Project2. Now i want to copy this projects into eclipse workspace but i want these projects to be in a single folder like below. Eclipse Workspace -> Project -> ...

Java: Finding out what is using all the memory

I have a java application that runs out of memory, but I have no idea which code is allocating the memory. Is there an application with which I can check this? I use Eclipse.

热门标签