IDEA Java/Scala混合项目maven打包

1.在建立Maven项目时,选择骨架为maven-archetype-quickstart

2.pom文件内容为:


  4.0.0

  scalalearn
  scalalearn
  1.0-SNAPSHOT
  jar

  scalalearn
  http://maven.apache.org

  
    UTF-8
  

  
    
      junit
      junit
      3.8.1
      test
    
    
      org.scala-lang
      scala-library
      2.11.6
    
  
  
    
      
        org.scala-tools
        maven-scala-plugin
        2.15.2
        
          
            scala-compile-first
            
              compile
            
            
              
                **/*.scala
              
            
          
          
            scala-test-compile
            
              testCompile
            
          
        
      
      
        maven-assembly-plugin
        
          
            jar-with-dependencies
          
          
            src/main/resources/META-INF/MANIFEST.MF
          
        
        
          
            make-assembly
            package
            
              single
            
          
        
      
    
  

3.在src/main下新建scala文件夹,用于存放scala源码,并在project structure中将其设为source目录;在src/main下建立resources/META-INF目录,并建立MANIFEST.MF文件,在里面填入mainclass,并将resources目录设置为资源目录

Main-Class: com.scalalearn.java.main.App
4.设置之好的项目结构如图所示:

IDEA Java/Scala混合项目maven打包_第1张图片

5.com.scalalearn.scala.main.ScalaPrint.scala的内容为:

package com.scalalearn.scala.main

/**
  * Created by Administrator on 2016/5/14.
  */
object ScalaPrint {
  def print():Unit={
    println("I love scala");
  }
}

com.scalalearn.java.main.App.java的内容为:

package com.scalalearn.java.main;

import com.scalalearn.scala.main.ScalaPrint;

/**
 * Hello world!
 *
 */
public class App {
    public static void main( String[] args ) {
        ScalaPrint.print();
    }
}
6.打jar包的mvn命令为:mvn clean scala:compile compile package

7.最后会在target目录下生成两个jar包,分别为:scalalearn-1.0-SNAPSHOT.jar和scalalearn-1.0-SNAPSHOT-jar-with-dependencies.jar

8.运行jar效果如下:


你可能感兴趣的:(Scala)