idea16使用maven命令clean、编译、打包jar或者war

项目环境:idea16+jdk1.7+maven-3.3.9

项目说明:编写简单的java类,使用maven命令生成jar包,然后执行-------》"java  -classpath  jar所在路径  main类名称"

注意:使用idea16工具的maven命令生成的jar包可能不包含第三方依赖

1、编写pom.xml文件

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. 4.0.0spark-jqz-predictcom.enn1.0-SNAPSHOTUTF-8UTF-81.7<!--add  maven release-->1.71.7UTF-8mysqlmysql-connector-java5.1.24<!--junit-->junitjunit4.12<!--slf4j-->org.slf4jslf4j-log4j121.7.20<!---  
  3.     引入本地jar  
  4.     <dependency>  
  5.             <groupId>org.apache.spark</groupId>  
  6.             <artifactId>spark-assembly_2.10</artifactId>  
  7.             <version>1.6.0-cdh5.8.0</version>  
  8.             <scope>system</scope>  
  9.             <systemPath>D:/spark-assembly-1.6.2-hadoop2.6.0.jar</systemPath>  
  10.         </dependency>  
  11.       
  12.     --><!--编译java代码使用该配置-->spark-jqz-predict<!-- 编译插件 -->org.apache.maven.pluginsmaven-compiler-plugin3.11.71.7UTF-8<!-- 打包 -->maven-assembly-pluginjar-with-dependenciesmake-assemblypackagesingle<!--注意:如果是编译scala代码,则需要使用如下配置--><!--  
  13.       
  14.       
  15.        <build>  
  16.         <finalName>sparkEnn</finalName>  
  17.         <sourceDirectory>src/main/scala</sourceDirectory>  
  18.         <testSourceDirectory>src/test/scala</testSourceDirectory>  
  19.         <plugins>  
  20.             <plugin>  
  21.                 <groupId>org.scala-tools</groupId>  
  22.                 <artifactId>maven-scala-plugin</artifactId>  
  23.                 <executions>  
  24.                     <execution>  
  25.                         <goals>  
  26.                             <goal>compile</goal>  
  27.                             <goal>testCompile</goal>  
  28.                         </goals>  
  29.                     </execution>  
  30.                 </executions>  
  31.                 <configuration>  
  32.                     <scalaVersion>${scala.version}</scalaVersion>  
  33.                     <args>  
  34.                         <arg>-target:jvm-1.7</arg>  
  35.                     </args>  
  36.                 </configuration>  
  37.             </plugin>  
  38.             <plugin>  
  39.                 <groupId>org.apache.maven.plugins</groupId>  
  40.                 <artifactId>maven-eclipse-plugin</artifactId>  
  41.                 <configuration>  
  42.                     <downloadSources>true</downloadSources>  
  43.                     <buildcommands>  
  44.                         <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>  
  45.                     </buildcommands>  
  46.                     <additionalProjectnatures>  
  47.                         <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>  
  48.                     </additionalProjectnatures>  
  49.                     <classpathContainers>  
  50.                         <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>  
  51.                         <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>  
  52.                     </classpathContainers>  
  53.                 </configuration>  
  54.             </plugin>  
  55.             <plugin>  
  56.                 <artifactId>maven-assembly-plugin</artifactId>  
  57.                 <configuration>  
  58.                     <descriptorRefs>  
  59.                         <descriptorRef>jar-with-dependencies</descriptorRef>  
  60.                     </descriptorRefs>  
  61.                     <archive>  
  62.                         <manifest>  
  63.                             <mainClass></mainClass>  
  64.                         </manifest>  
  65.                     </archive>  
  66.                 </configuration>  
  67.                 <executions>  
  68.                     <execution>  
  69.                         <id>make-assembly</id>  
  70.                         <phase>package</phase>  
  71.                         <goals>  
  72.                             <goal>single</goal>  
  73.                         </goals>  
  74.                     </execution>  
  75.                 </executions>  
  76.             </plugin>  
  77.         </plugins>  
  78.     </build>  
  79.     <reporting>  
  80.         <plugins>  
  81.             <plugin>  
  82.                 <groupId>org.scala-tools</groupId>  
  83.                 <artifactId>maven-scala-plugin</artifactId>  
  84.                 <configuration>  
  85.                     <scalaVersion>${scala.version}</scalaVersion>  
  86.                 </configuration>  
  87.             </plugin>  
  88.         </plugins>  
  89.     </reporting>  
  90.       
  91.       
  92.     -->  
posted @ 2018-05-15 17:52  星朝  阅读(661)  评论(0编辑  收藏  举报