Intellij IDEA Maven 插件 - 管理依赖关系
Intellij IDEA Maven Plugin - Manage Dependencies
我是 IntelliJ 和 Maven 的新手,尝试了一下。我通过 "Project Structure" window 中的模块和项目结构设置导入了一些库(见下面的截图),因为我认为我必须在这里添加我的依赖项。我还认为这会自动创建 pom.xml 和依赖列表,但它没有!我必须通过以下步骤添加依赖项:
Open the pom.xml file > Menu "Code" > "Generate" > Popup "Dependency"
或
Alt + 插入
项目结构Window:
要导出我所有的库,我还必须在 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>
并通过 运行 配置将目标设置为
clean compile assembly:single package
这让我 运行 宁两个罐子:
test-1.0-SNAPSHOT.jar & test-1.0-SNAPSHOT-jar-with-dependencies.jar
初学者要做的事情太多了!我现在的问题是:是否有更短的方法来管理项目的依赖关系?项目结构设置的真正目的是什么(在依赖管理的情况下)???是我做多了还是做错了什么?
PS:对于所有 Maven 和 IntelliJ 的新手,请参阅 https://www.jetbrains.com/idea/help/maven.html
如果你使用 Maven,你只需要在 pom.xml.
上添加你的依赖项
您也可以使用
Open the pom.xml file > Menu "Code" > "Generate" > Popup "Dependency"
如你所愿。 InteliJ 会自动将其添加到项目的类路径中。
例如,当您有子模块时,将使用项目结构。这里不是加jar的
我是 IntelliJ 和 Maven 的新手,尝试了一下。我通过 "Project Structure" window 中的模块和项目结构设置导入了一些库(见下面的截图),因为我认为我必须在这里添加我的依赖项。我还认为这会自动创建 pom.xml 和依赖列表,但它没有!我必须通过以下步骤添加依赖项:
Open the pom.xml file > Menu "Code" > "Generate" > Popup "Dependency"
或
Alt + 插入
项目结构Window:
要导出我所有的库,我还必须在 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>
并通过 运行 配置将目标设置为
clean compile assembly:single package
这让我 运行 宁两个罐子:
test-1.0-SNAPSHOT.jar & test-1.0-SNAPSHOT-jar-with-dependencies.jar
初学者要做的事情太多了!我现在的问题是:是否有更短的方法来管理项目的依赖关系?项目结构设置的真正目的是什么(在依赖管理的情况下)???是我做多了还是做错了什么?
PS:对于所有 Maven 和 IntelliJ 的新手,请参阅 https://www.jetbrains.com/idea/help/maven.html
如果你使用 Maven,你只需要在 pom.xml.
上添加你的依赖项您也可以使用
Open the pom.xml file > Menu "Code" > "Generate" > Popup "Dependency"
如你所愿。 InteliJ 会自动将其添加到项目的类路径中。
例如,当您有子模块时,将使用项目结构。这里不是加jar的