Maven相关知识点

436 阅读2分钟

1.Scala Maven项目生成

1)安装scala
2)安装eclipse for scala
3)配置Maven (windows -> Preferences ->Maven ->Installations、Maven ->User Settings)
4)创建scala项目
New ->project ->Maven project ->scala-archetype-simple
5)编辑pom.xml
删除-make:transitive属性
增加(单元测试用,也可以不加):
	<dependency>
		<groupId>org.specs2</groupId>
		<artifactId>specs2-junit_${scala.compat.version}</artifactId>
		<version>2.4.16</version>
		<scope>test</scope>
	</dependency>
依赖spark streaming:
	<dependency> 
	       <groupId>org.apache.spark</groupId>
	       <artifactId>spark-streaming_2.11</artifactId>
	       <version>2.1.0</version>
	  </dependency>

2.将所依赖jar打包成一个包

	<plugin>
	   <artifactId> maven-assembly-plugin </artifactId>
	   <configuration>
		<descriptorRefs>
			 <descriptorRef>jar-with-dependencies</descriptorRef>
		</descriptorRefs>
		<archive>
			 <manifest>
				  <mainClass>com.demo2.App</mainClass>
			 </manifest>
		</archive>
	   </configuration>
	   <executions>
		<execution>
			 <id>make-assembly</id>
			 <phase>package</phase>
			 <goals>
				  <goal>single</goal>
			 </goals>
		</execution>
	   </executions>
	</plugin>

3.Maven安装jar包命令

mvn?install:install-file?-Dfile=jar包的位置?-DgroupId=上面的groupId?-DartifactId=上面的artifactId?-Dversion=上面的version -Dpackaging=jar

mvn install:install-file -Dfile=rpm-maven-plugin-2.1.5.jar -DgroupId=org.codehaus.mojo -DartifactId=rpm-maven-plugin -Dversion=2.1.5 -Dpackaging=jar

来自 www.blogjava.net/fancydeepin…

4.导出依赖文件

在eclipse中,选择项目的pom.xml文件,点击右键菜单中的Run As-->Maven build...,见下图红框中,在弹出的Configuration窗口中,输入dependency:copy-dependencies后,点击运行 maven项目所依赖的jar包会导出到targed/dependency目录中。

来自 blog.csdn.net/u014175572/…

5.运行Maven打包的scala的程序

java -Xmx512M -jar xxx.jar 或者 scala xxx.jar

以上两种方式均为将其依赖的jar也一起打包的情况下运行

spark程序执行:spark-submit --class com.scala.sparkExample.App --master local[4] sparkExample-0.0.1-SNAPSHOT-jar-with-dependencies.jar

注:如果代码中设置了--master,则命令行中的master不会起作用

打包命令 mvn assembly:assembly

来自 blog.csdn.net/xyznol/arti…

6.mvn package打包时跳过test阶段

解决方法有两种: 1)使用mvn命令 mvn package -DskipTests

2)pom.xml中配置

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-surefire-plugin</artifactId>
			<configuration>
				<skip>true</skip>
			</configuration>
		</plugin>
	</plugins>
</build>

7.查看整颗树依赖关系

mvn dependency:tree

来自 outofmemory.cn/code-snippe…