Idea使用Maven编译scala和打包jar

下面Maven的pom文件

[html]  view plain  copy
  1. <properties>  
  2.     <maven.compiler.source>1.7maven.compiler.source>  
  3.     <maven.compiler.target>1.7maven.compiler.target>  
  4.     <encoding>UTF-8encoding>  
  5.     <scala.version>2.11.7scala.version>  
  6.     <scala.compat.version>2.11scala.compat.version>  
  7. properties>  
  8.   
  9. <dependencies>  
  10.   
  11.     <dependency>  
  12.         <groupId>org.scala-langgroupId>  
  13.         <artifactId>scala-libraryartifactId>  
  14.         <version>${scala.version}version>  
  15.     dependency>  
  16. dependencies>  
  17.   
  18. <build>  
  19.       
  20.     <sourceDirectory>src/main/scalasourceDirectory>  
  21.     <testSourceDirectory>src/test/scalatestSourceDirectory>  
  22.       
  23.     <plugins>  
  24.         <plugin>  
  25.             <groupId>net.alchim31.mavengroupId>  
  26.             <artifactId>scala-maven-pluginartifactId>  
  27.             <version>3.2.2version>  
  28.             <executions>  
  29.                 <execution>  
  30.                     <goals>  
  31.                         <goal>compilegoal>  
  32.                         <goal>testCompilegoal>  
  33.                     goals>  
  34.                     <configuration>  
  35.                         <args>  
  36.                               
  37.                             <arg>-dependencyfilearg>  
  38.                             <arg>${project.build.directory}/.scala_dependenciesarg>  
  39.                         args>  
  40.                     configuration>  
  41.                 execution>  
  42.             executions>  
  43.         plugin>  
  44.   
  45.           
  46.         <plugin>  
  47.             <groupId>org.apache.maven.pluginsgroupId>  
  48.             <artifactId>maven-shade-pluginartifactId>  
  49.             <version>2.4.3version>  
  50.             <executions>  
  51.                 <execution>  
  52.                     <phase>packagephase>  
  53.                     <goals>  
  54.                         <goal>shadegoal>  
  55.                     goals>  
  56.                     <configuration>  
  57.                         <filters>  
  58.                             <filter>  
  59.                                 <artifact>*:*artifact>  
  60.                                 <excludes>  
  61.                                     <exclude>META-INF/*.SFexclude>  
  62.                                     <exclude>META-INF/*.DSAexclude>  
  63.                                     <exclude>META-INF/*.RSAexclude>  
  64.                                 excludes>  
  65.                             filter>  
  66.                         filters>  
  67.                         <transformers>  
  68.                             <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
  69.                                 <resource>reference.confresource>  
  70.                             transformer>  
  71.                             <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">  
  72.                                 <mainClass>cn.itcast.rpc.MastermainClass>   
  73.                             transformer>  
  74.                         transformers>  
  75.                     configuration>  
  76.                 execution>  
  77.             executions>  
  78.         plugin>  
  79.     plugins>  
  80. build>  

上面是使用Scala2.11的版本,注意scala2.11 netbean不支持这个参数-make:transitive这个参数,所以必须得注释掉

下面是简单的测试:

Idea使用Maven编译scala和打包jar_第1张图片


使用Maven进行jar依赖打包,之前使用Idea的artifacts进行打包,但是导出的jar有可能因为缺少某些信息而无法直接运行,但是使用maven自动的pakage便没有这个问题,而且jar包的大小明显小于artifacts的jar包大小,下面是使用方法

Idea使用Maven编译scala和打包jar_第2张图片

下载完相关的依赖后,会在target的目录下生成下项目的jar包


你可能感兴趣的:(maven,scala)