Using Scala IDE on Maven projects

refer to :http://scala-ide.org/docs/tutorials/m2eclipse/index.html

Using Scala IDE for Eclipse on a Maven Scala project is fairly straightforward.. when all the pieces are in the right place. In this tutorial I will show how to use the Scala IDE on an existing maven project, and how to start with a fresh project.

Install m2eclipse-scala

Maven integration in Eclipse is a separate plugin, and depending on which version of Eclipse you have installed, you might already have it or not.

The default maven plugin does not support Scala out of the box, so you need to install the m2eclipse-scala connector. This connector understands the Scala maven plugin and links the compile phase to the Eclipse Scala Builder.

You can install both plugins by pointing Eclipse to the m2eclipse-scala update site.

Note

If you don't have the vanilla Maven Integration for Eclipse, make sure you have enabled Check all update sites to find required software. If you already have it, you can leave this box unchecked.

../../_images/install-new-software.png

In this tutorial we used the following versions:

  • Scala IDE: 3.0.0 for 2.10.1
  • m2eclipse: 1.3.1
  • m2eclipse-scala: 0.4.2
  • scala-maven-plugin: 3.1.3

Create a new Scala Maven project

If everything went well, you should now have Maven and Scala support in your Eclipse installation. Let's create a new Scala maven project, starting with a simple Scala project based on an archetype.

Select New -> Project -> Other and then select Maven Project. On the next window, search forscala-archetype. Make sure you select the one in group net.alchim31.maven, and click Next.

../../_images/archetypes.png

Follow the wizard and enter values for group ID, artifact, etc. Click Finish and you should have a new Scala project in the workspace.

../../_images/new-project.png

Notice that the new project has both the Maven and Scala nature, and src/main/scala is listed as a source folder. You should be able to build and launch your project, or run tests.

Import an existing Scala Maven project

It is probably rare to start a new project, so let's take a look at importing an existing Scala project.

Assuming your project builds fine with maven, you should have something similar in your pom.xml:

    
    
  1. <plugin>
  2. <groupId>net.alchim31.maven</groupId>
  3. <artifactId>scala-maven-plugin</artifactId>
  4. <version>3.1.3</version>
  5. <executions>
  6. <execution>
  7. <goals>
  8. <goal>compile</goal>
  9. <goal>testCompile</goal>
  10. </goals>
  11. </execution>
  12. </executions>

To get this project in Eclipse, choose File -> Import -> Existing Maven Project and navigate to the directory containing your maven project.

../../_images/import.png

When you click Finish, the project is imported and it should have both Maven and Scala natures. You'll notice that both src/main/java and src/main/scala are listed as source folders. You should be able to build and run your application, and use all Maven commands on your project.

Warning

As of March 2013, a bug causes both src/main/scala and src/test/scala to use the default output folder (target/classes). This may be confusing when building tests, since their class files will not end in target/test-classes, as they would when building on the command line. You can work around this by manually changing the output folder for src/test/scala.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值