Intellij IDEA Maven插件 - 管理依赖关系 [英] Intellij IDEA Maven Plugin - Manage Dependencies

查看:424
本文介绍了Intellij IDEA Maven插件 - 管理依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是IntelliJ和Maven的新手并尝试了一下。我通过Module& amp;进口了一些库。 项目结构窗口中的项目结构设置(见下面的屏幕截图),因为我认为我必须在这里添加我的依赖项。我还认为这会自动创建带有依赖列表的pom.xml,但事实并非如此!我必须通过以下步骤添加我的依赖项:

I'm new to IntelliJ and Maven and tried a bit around. I imported some libraries via the Module & Project Structure Settings in the "Project Structure" window (see screenshot below), because I thought that I have to add my dependencies here. I also thought that this creates the pom.xml with dependency list automatically, but it didn't! I had to add my dependencies via following steps:

Open the pom.xml file > Menu "Code" > "Generate" > Popup "Dependency"

Alt + Insert

项目结构窗口:

要导出我的所有库,我还必须在pom.xml中添加一个插件:

To export all my libraries I also had to add a plugin in the 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>test</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>your.package.MainClass</mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>

       [...]

    </dependency>
</dependencies>

并通过run设置目标配置到

and set the goal via run configuration to

clean compile assembly:single package

这让我在运行两个罐子时:

This created me on running two jars:

test-1.0-SNAPSHOT.jar & test-1.0-SNAPSHOT-jar-with-dependencies.jar

这是很多事情要做对于初学者!我现在的问题是:是否有更短的方法来管理项目的依赖关系?什么是项目结构设置真正的(在依赖管理的情况下)???我做了太多或有什么不对吗?

That was a lot of things to do for a beginner! My question now: Is there a shorter way to manage the project's dependencies? And what is the project structure setting really for (in case of dependency management)??? Did I do too much or something wrong?

PS:对于所有刚接触过Maven& IntelliJ,请参阅 https://www.jetbrains.com/idea/help/maven.html

PS: For all who are new to Maven & IntelliJ, see https://www.jetbrains.com/idea/help/maven.html

推荐答案

如果你使用maven,你只需要在pom.xml上添加你的依赖项。

If you use maven you just have to add your dependencies on the pom.xml.

你也可以使用

Open the pom.xml file > Menu "Code" > "Generate" > Popup "Dependency"

正如您所做的那样。 InteliJ会自动将它添加到项目的类路径中。

As you do. InteliJ will add it to the classpath of the your project automatically.

例如,当你有子模块时,会使用项目结构。它不是在这里添加jar。

Project Structure is used when you have submodule for example. It's not here to add jar.

这篇关于Intellij IDEA Maven插件 - 管理依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆