Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I'm having problems trying to just create a Maven project using Scala (v2.11.6) within Eclipse (Luna). The instructions here says to install both plugins below.

  • Maven Integration in Eclipse
  • m2eclipse-scala connector

Both plugins can be installed by using the m2eclipse-scala update site. So here's what I did in my first attempt.

  • Download Eclipse Luna (for JavaEE developers)
  • Install "both" plugins above by using the m2eclipse-scala update site.

When Eclipse loads up, I attempt to create a Maven project, and the archetype I want to use is Group Id=net.alchim31.maven, Artifact Id=scala-archetype-simple, Version=1.5. However, this archetype never shows up when I enter in "scala-arch" in the filter text field.

The only project I see is the one with Group Id=org.scala-tools.archetypes, Artifact Id=scala-archetype-simple, Version=1.2. When I select this archetype to use, I get a bunch of error messages in Eclipse.

  • error while loading ConsoleRunner, Scala signature ConsoleRunner has wrong version expected: 5.0 found: 4.1 in ConsoleRunner.class
  • error while loading JUnit4, Scala signature JUnit4 has wrong version expected: 5.0 found: 4.1 in JUnit4.class
  • error while loading Specification, Scala signature Specification has wrong version expected: 5.0 found: 4.1 in Specification.class

In my second attempt, I try to download the pre-packaged bundle (Scala IDE for Eclipse). Again, when I attempt to create a Scala Maven project, I don't see the Maven archetype for Group Id=net.alchim31.maven (only for Group Id=org.scala-tools.archetypes).

Any ideas on what I'm doing wrong here? Or where I can find a vanilla Scala Maven project to import/modify and use for my own purpose?

like image 704
Jane Wayne Avatar asked Mar 18 '15 05:03

Jane Wayne


People also ask

What archetype should I choose for Maven project?

If you want a web application, use maven-archetype-webapp, or if you want a simple application use maven-archetype-quickstart. They are useful because you will be able to expand them with no problem. Note that this is in the Eclipse plugin by default (at least it is today).

How do I know my Maven project archetype?

Archetype configurationYou can see the packaging maven-archetype . You can customize build of your archetype here as with any other pom. However, there is another pom. xml file located under src\main\resources\archetype-resources which is the pom file of the generated project.


1 Answers

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

Image showing the original dialog with missing entry

So do this

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

Image showing "Remote Archetype Catalog" modal window

For copy-pasting:

  • Catalog File: http://repo1.maven.org/maven2/archetype-catalog.xml
  • Description: Remote Archetypes

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

Image showing "scala-archetype" entry in the dialog

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!

like image 108
Paul Samsotha Avatar answered Sep 21 '22 00:09

Paul Samsotha