How do I find the correct Maven archetype project for developing with Scala in Eclipse?

南楼画角 提交于 2019-11-29 21:07:32
Paul Samsotha

Here's how I got it to work. It seems all the archetypes aren't available, so based on this answer, I created a remote catalog

Before

So do this

Go to [Windows] → [Preferences] → [Maven] → [Archetypes] → Add Remote Catalog and create the catalog, then Apply

For copy-pasting:

Go back to creating a new Maven project. Select the Remote Catalog from the dropdown. It will take a few moments to gather all the archetypes. You can see the progress at the very bottom right of the IDE. When it's done, you should be able to see the archetypes

After

Create your project with groupId and artifactId and such.

Right click the project, then from the context menu [Run As] &rarr [Maven Build]. In the dialog, type clean package into the goals. The run. The project should build and run the tests.

For me at first I got an error on the build. It was because my default environment is using Java 8. I'm pretty new to Scala, so I'm not sure is there is a problem with Scala and Java 8 or not (I think it's the Scala version in the pom (2.10.0)). But what I did to get it to work was just change the Java version used in the IDE to Java 7.

Basically just go to [Windows] → [Preferenes] → [Java] → [Installed JREs] → Add → [System VM] → Next → Directory → Find the directory of the Java home (version 7) → Finish → Then in the list tick Java 7.

Then build again. It should work. Good Luck!

Deepak Acharya

One point I want to add, If you are getting following error while installing the archetype showed in image 1

Can't resolve Archetype org.glassfish.jersey.archetypes:jersey-quickstart-webapp:2.21 org.eclipse.core.runtime.CoreException: Could not resolve artifact org.glassfish.jersey.archetypes:jersey-quickstart-webapp:pom:2.21

Image 1:

Then before procedding with the solution specified above, try to complete these steps in eclipse.

I faced the same problem and chanced upon this SO question, as well as the answer, given by @peeskillet (many thanks). I am using:

  • Maven 3.3.3
  • Eclipse Luna Scala IDE 4.0.0.-vfinal-20150305-1644-Typesafe
  • Scala 2.11.6
  • JDK 1.8

After following the steps exactly as given here, I hit a wall. When I chose the right archetype (net.alchim31.maven), I was greeted with this error: Could not resolve artifact net.alchim31.maven:scala-archetype-simple:pom:1.5 Suspecting that the maven embedded in eclipse was acting funny, I visited [Windows] -> [Maven] -> [Installations] and added local installation of maven (whatever is set to M2_HOME in my shell). But, no luck!

Exasperated, I visited this site: Scala Doc and switched back to command-line as this page instructs. Surprisingly (to me, at least), it worked. A maven-Scala project was created in the present directory, which I could import into Eclipse.

Just so that I am not misunderstood, I am not suggesting that @peeskillet's answer is wrong. Just wanted to share another way of creating a maven-scala project on Eclipse, in case it helps someone. I have not yet understood, why Eclipse-Scala-IDE is yet to give that 'Aha' feeling.

After you have successfully created the scala-maven project as described above, you will probably see an error "Type not found: type JUnitRunner specs.scala". In that case, manually add the following XML snippet to your pom.

<dependency>
    <groupId>org.specs2</groupId>
    <artifactId>specs2-junit_${scala.compat.version}</artifactId>
    <version>2.4.16</version>
    <scope>test</scope>
</dependency>

Moreover, to avoid errors when running mvn test,

[ERROR] scalac error: bad option: '-make:transitive'

You also need to delete the following line from the pom.xml file:

<arg>-make:transitive</arg>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!