maven依赖--dependency命令

maven 依赖

要分析的pom文件:

<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>uk.ac.liverpool</groupId>
	<artifactId>JTViewer</artifactId>
	<version>0.7.1</version>
	<name>The JT format parser and renderer</name>
	<developers>

		<developer>
			<name>Fabio Corubolo</name>
			<email>corubolo@gmail.com</email>
		</developer>
		<developer>
			<name>Jerome Fuselier</name>
			<email>jerome.fuselier@gmail.com</email>
		</developer>

	</developers>

	<description>A pure Java library to decode the JT(TM) file format from Siemens PLM (TM).
See http://www.jtopen.com/ for samples and the file format specification. See licensing for the specific JT specification license data structures license. The library is produced independently and has no affiliation to Siemens PLM (TM).
This library curerntly parses JT files including faceted data, the Logocal Scene Graph and other the necessary information, and renders it using the JReality toolkit.</description>
	<url>http://code.google.com/p/jt-java/</url>
	<inceptionYear>2010</inceptionYear>
	<build>
		<plugins>
			<!-- 该插件用于编译源码 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
					<source>1.5</source>
					<target>1.5</target>
				</configuration>
			</plugin>

			<!-- 该插件用于设置主类,因为默认的mvn install生成的jar是不带主类入口的 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>

				<configuration>
					<archive>
						<manifest>
							<!-- 设置classpath路径 -->
							<addClasspath>true</addClasspath>
							<!-- 设置主类入口 -->
							<mainClass>uk.ac.liv.jt.viewer.JTViewer</mainClass>
						</manifest>
					</archive>
				</configuration>
			</plugin>

			<!-- 该插件能打包项目为指定格式,更重要的是能能够自定义包含/排除指定的目录或文件。 -->
			<plugin>
				<artifactId>maven-assembly-plugin</artifactId>
				<executions>
					<execution>
						<!-- 绑定到package阶段,自动打包; -->
						<id>assemble</id>
						<phase>package</phase>
						<goals>
							<goal>single</goal>
						</goals>
						<configuration>
							<descriptors>
								<!-- 指定一个Assembly描述符文件,该文件指定了打包格式,包含的文件/过来的文件等信息,可以同时指定多个描述符文件,打包成不同的格式。 -->
								<descriptor>src/main/assembly/jtv.xml</descriptor>
							</descriptors>
						</configuration>
					</execution>
				</executions>
				<configuration>
					<finalName>JTViewer</finalName>
				</configuration>
			</plugin>
		</plugins>

	</build>

	<repositories>
		<repository>
			<id>google.code.fab4project</id>
			<name>google.code.fab4project</name>
			<!-- 这个地址现在已经不存在了 :<url>http://fab4browser.googlecode.com/svn/trunk/repository/</url> -->
			<url>https://github.com/jasonknight/jreality/tree/master/lib</url>
		</repository>

	</repositories>

	<dependencies>

		<dependency>
			<groupId>jreality</groupId>
			<artifactId>jReality</artifactId>
			<version>1.0</version>
			<scope>system</scope>
			<systemPath>D:/lib/jReality.jar</systemPath>
		</dependency>

		<dependency>
			<groupId>jreality</groupId>
			<artifactId>jrworkspace</artifactId>
			<version>1.0</version>
			<scope>system</scope>
			<systemPath>D:/lib/jrworkspace.jar</systemPath>
		</dependency>

		<dependency>
			<groupId>jreality</groupId>
			<artifactId>jterm</artifactId>
			<version>1.0</version>
			<scope>system</scope>
			<systemPath>D:/lib/jterm.jar</systemPath>
		</dependency>

		<dependency>
			<groupId>jreality</groupId>
			<artifactId>smrj.jar</artifactId>
			<version>1.0</version>
			<scope>system</scope>
			<systemPath>D:/lib/smrj.jar</systemPath>
		</dependency>

		<!-- Sunflow是一个照片级的渲染系统,具备光线跟踪渲染内核,整个工程用Java编写,面向对象的结构 -->
		<dependency>
			<groupId>jreality</groupId>
			<artifactId>sunflow.jar</artifactId>
			<version>1.0</version>
			<scope>system</scope>
			<systemPath>D:/lib/sunflow.jar</systemPath>
		</dependency>

		<!-- 颜色检测器 -->
		<dependency>
			<groupId>jreality</groupId>
			<artifactId>colorpicker</artifactId>
			<version>1.0</version>
			<scope>system</scope>
			<systemPath>D:/lib/colorpicker.jar</systemPath>
		</dependency>

		<dependency>
			<groupId>jreality</groupId>
			<artifactId>beans</artifactId>
			<version>1.0</version>
			<scope>system</scope>
			<systemPath>D:/lib/beans.jar</systemPath>
		</dependency>

		<dependency>
			<groupId>com.lowagie</groupId>
			<artifactId>itext</artifactId>
			<version>2.1.3</version>
			<type>jar</type>
			<scope>compile</scope>
			<exclusions>
				<exclusion>
					<artifactId>bcmail-jdk14</artifactId>
					<groupId>bouncycastle</groupId>
				</exclusion>
				<exclusion>
					<artifactId>bcprov-jdk14</artifactId>
					<groupId>bouncycastle</groupId>
				</exclusion>
			</exclusions>
		</dependency>

		<dependency>
			<groupId>com.thoughtworks.xstream</groupId>
			<artifactId>xstream</artifactId>
			<version>1.3.1</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>org.beanshell</groupId>
			<artifactId>bsh</artifactId>
			<version>2.0b4</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>

		<dependency>
			<groupId>org.codehaus.janino</groupId>
			<artifactId>janino</artifactId>
			<version>2.5.16</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>

		<!-- 语法分析解析器 -->
		<dependency>
			<groupId>antlr</groupId>
			<artifactId>antlr</artifactId>
			<version>2.7.7</version>
			<type>jar</type>
			<scope>compile</scope>
		</dependency>
	</dependencies>
</project>

1.mvn dependency:list:

可查看当前项目的已解析依赖。强直接在当前项目pom中声明的依赖定义为顶层依赖,而这些顶层依赖的依赖则定义为第二层依赖,以此类推。

[INFO] --- maven-dependency-plugin:2.8:list (default-cli) @ JTViewer ---
[INFO] 
[INFO] The following files have been resolved:
[INFO]    jreality:colorpicker:jar:1.0:system
[INFO]    jreality:jrworkspace:jar:1.0:system
[INFO]    org.beanshell:bsh:jar:2.0b4:compile
[INFO]    xpp3:xpp3_min:jar:1.1.4c:compile
[INFO]    jreality:beans:jar:1.0:system
[INFO]    com.thoughtworks.xstream:xstream:jar:1.3.1:compile
[INFO]    org.codehaus.janino:janino:jar:2.5.16:compile
[INFO]    jreality:jReality:jar:1.0:system
[INFO]    antlr:antlr:jar:2.7.7:compile
[INFO]    jreality:jterm:jar:1.0:system
[INFO]    jreality:smrj.jar:jar:1.0:system
[INFO]    jreality:sunflow.jar:jar:1.0:system
[INFO]    com.lowagie:itext:jar:2.1.3:compile
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS


2. mvn dependency:tree

能够查看依赖树,通过这棵树能够很清楚的看到某个依赖是通过哪条路径引入进来的。

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ JTViewer ---
[INFO] uk.ac.liverpool:JTViewer:jar:0.7.1  
[INFO] +- jreality:jReality:jar:1.0:system
[INFO] +- jreality:jrworkspace:jar:1.0:system
[INFO] +- jreality:jterm:jar:1.0:system
[INFO] +- jreality:smrj.jar:jar:1.0:system
[INFO] +- jreality:sunflow.jar:jar:1.0:system
[INFO] +- jreality:colorpicker:jar:1.0:system
[INFO] +- jreality:beans:jar:1.0:system
[INFO] +- com.lowagie:itext:jar:2.1.3:compile
[INFO] +- com.thoughtworks.xstream:xstream:jar:1.3.1:compile
[INFO] |  \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] +- org.beanshell:bsh:jar:2.0b4:compile
[INFO] +- org.codehaus.janino:janino:jar:2.5.16:compile
[INFO] \- antlr:antlr:jar:2.7.7:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.080 s
[INFO] Finished at: 2016-10-13T10:04:12+08:00
[INFO] Final Memory: 13M/217M
[INFO] ------------------------------------------------------------------------


注意:

JTViewer:jar:0.7.1  //项目编译后的打包;

“+-”后面的jar包是顶层依赖包,在pom中进行了声明;

“|  \-”后面的jar包是引用包,未在pom中声明;

只要声明顶层包,其对应的引用包会自动去仓库中下载;

“\-”,不管在pom文件中最后一个依赖引用是哪个,其前缀都是“\-”,如最后一个是:\- antlr:antlr:jar:2.7.7:compile,或最后一个是 \- jreality:jReality:jar:1.0:system,而该依赖是重要依赖,不可缺少,即 ”\-” 仅表后最后一个依赖引用;


2. mvn dependency:analyze

可以帮助分析当前项目的依赖。

[INFO] --- maven-dependency-plugin:2.8:analyze (default-cli) @ JTViewer ---
[WARNING] Unused declared dependencies found:
[WARNING]    jreality:jrworkspace:jar:1.0:system
[WARNING]    jreality:jterm:jar:1.0:system
[WARNING]    jreality:smrj.jar:jar:1.0:system
[WARNING]    jreality:sunflow.jar:jar:1.0:system
[WARNING]    jreality:colorpicker:jar:1.0:system
[WARNING]    jreality:beans:jar:1.0:system
[WARNING]    com.lowagie:itext:jar:2.1.3:compile
[WARNING]    org.beanshell:bsh:jar:2.0b4:compile
[WARNING]    org.codehaus.janino:janino:jar:2.5.16:compile
[WARNING]    antlr:antlr:jar:2.7.7:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.697 s
[INFO] Finished at: 2016-10-13T10:51:20+08:00
[INFO] Final Memory: 14M/217M
[INFO] ------------------------------------------------------------------------

结果会有2部分:

首先是"Used declared dependencies found",指项目中使用到,但是没有显示声明的依赖,如果有的话,需要在pom中添加依赖声明;

另外就是“Unused declared dependencies found”,指项目中未使用的,但是显示声明的依赖,但是对于这样的依赖,不能直接删除,要仔细分析。因为dependency:analyze只会分析编译主代码和测试代码用到的依赖,一些执行测试和运行时需要的依赖是发现不了的。但是很显然有些依赖是必须的,不能删除。所以要小心寻找无用的依赖信息,然后再删除。


通过以上分析,可以需要与不需要的依赖,达到优化作用。

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值