這個Maven項目文件pom.xml
包含修復和一些小技巧/什麼改變,爲什麼它已被更改的提示。
<?xml version="1.0" encoding="UTF-8"?>
<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 POM best at the top -->
<!-- WANRING: Here you import the parent of 3th party. This is (almost) never correct!!! -->
<!-- For a simple project, which only exists of 1 set of classes and unit tests, you do -->
<!-- not need a parent POM. Only for multi module Maven project, you will have a parent -->
<!-- POM. Or for organisation wide configuration, of repositories, Maven plugin -->
<!-- configuration, and so. When starting with a small project, leave out the parent POM -->
<!-- reference. -->
<parent>
<groupId>com.x.y</groupId>
<artifactId>third-party-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<!-- Better keep all project stuff together -->
<groupId>com.x.y.z</groupId>
<artifactId>your-project-name</artifactId>
<packaging>pom</packaging>
<name>My Little Sandbox</name>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<!-- Here only a reference to the compiled jar is required!!! -->
<!-- If a source jar is available, it will get pulled in automatically!!! -->
<!-- As this is done by (naming) convention of all jars, in a Maven repository -->
<dependency>
<groupId>com.x.y.thirdparty</groupId>
<artifactId>thirdparty</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</project>
備註:其中一個新項目延伸屆黨父POM,是當新的項目是一些實物屆党項目的extention /插件的罕見病例。然後,它可以使用相同的Maven Plug-in版本,依賴關係等等,就像第三方使用的一樣。這使得最新的Extention/Plug-in與第三方軟件的其他部分配合良好。
具體的例子來嘗試
<?xml version="1.0" encoding="UTF-8"?>
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>org.organisation.play-ground</groupId>
<artifactId>my-little-sandbox</artifactId>
<packaging>pom</packaging>
<name>My Little Sandbox</name>
<version>1.0.0-SNAPSHOT</version>
<dependencies>
<!-- A dependency reuired for each phase -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.12</version>
</dependency>
<!-- A dependency only needed during runtime phase -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
<scope>runtime</scope>
</dependency>
<!-- A dependency only needed during compile and test phase -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
是的groupId,artifactId和version是否正確? (我的意思是它們與安裝依賴項時使用的是相同的嗎?)您是否更新過IntelliJ中的Maven項目? – Tunaki
也許「Maven - 下載源代碼」會有所幫助,但不知道 – Klever
的POM設置是否正常,否則它不會首先導入到IntelliJ中,對嗎?我可以導航到圖書館並查看來源。如果我嘗試直接引用一個類,如com.x.y.它不起作用。 IntelliJ能夠自動完成com.x.y.但它不會在下拉列表中顯示,儘管它存在於源代碼jar中! –
Rabiees