如何在eclipse中查找maven的各个jar包依赖的是别的什么jar包

2024-12-23 08:24:06
推荐回答(1个)
回答1:

1、创建一个新的Maven项目:
mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch3 -DartifactId=simple -DpackageName=org.sonatype.mavenbook

2、构建打包应用:
mvn install[在pom.xml同级目录下执行]

3、查看项目完整的pom.xml文件,包括系统默认设置以及用户自定义设置:
mvn help:effective-pom

4、生成报告或者文档:
mvn site

5、mvn exec:java执行目标类
mvn exec:java -Dexec.mainClass=org.sonatype.mavenbook.weather.Main

6、查看插件的完整描述:
mvn help:describe -Dplugin=exec -Dfull

7、找出该项目所依赖的项目(jar)列表:
mvn dependency:resolve
mvn dependency:analyze(找出项目非直接依赖)
结果如下:
[INFO] The following files have been resolved:
[INFO] com.ibm.icu:icu4j:jar:2.6.1:compile
[INFO] commons-collections:commons-collections:jar:3.1:compile
[INFO] commons-lang:commons-lang:jar:2.1:compile
[INFO] dom4j:dom4j:jar:1.6.1:compile
[INFO] jaxen:jaxen:jar:1.1.1:compile
[INFO] jdom:jdom:jar:1.0:compile
[INFO] junit:junit:jar:3.8.1:test
[INFO] log4j:log4j:jar:1.2.14:compile
[INFO] oro:oro:jar:2.0.8:compile
[INFO] velocity:velocity:jar:1.5:compile
[INFO] xalan:xalan:jar:2.6.0:compile
[INFO] xerces:xercesImpl:jar:2.6.2:compile
[INFO] xerces:xmlParserAPIs:jar:2.6.2:compile
[INFO] xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] xom:xom:jar:1.0:compile

8、查看整个项目的依赖树:
mvn dependency:tree
结果如下:
[INFO] org.sonatype.mavenbook.ch04:simple-weather:jar:1.0
[INFO] +- log4j:log4j:jar:1.2.14:compile
[INFO] +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] +- jaxen:jaxen:jar:1.1.1:compile
[INFO] | +- jdom:jdom:jar:1.0:compile
[INFO] | +- xerces:xercesImpl:jar:2.6.2:compile
[INFO] | \- xom:xom:jar:1.0:compile
[INFO] | +- xerces:xmlParserAPIs:jar:2.6.2:compile
[INFO] | +- xalan:xalan:jar:2.6.0:compile
[INFO] | \- com.ibm.icu:icu4j:jar:2.6.1:compile
[INFO] +- velocity:velocity:jar:1.5:compile
[INFO] | +- commons-collections:commons-collections:jar:3.1:compile
[INFO] | +- commons-lang:commons-lang:jar:2.1:compile
[INFO] | \- oro:oro:jar:2.0.8:compile
[INFO] \- junit:junit:jar:3.8.1:test

9、查看完整的依赖,包括那些因为冲突而被拒绝引入的依赖:
mvn install -X

10、打包应用(jar):
mvn install assembly:assembly

11、在 Jetty Servlet 容器中启动你的 web 应用:
mvn jetty:run

12、重新编译:
mvn compile