wood burning stoves 2.0*
The moose likes Scala and the fly likes Maven + scala + java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Languages » Scala
Bookmark "Maven + scala + java" Watch "Maven + scala + java" New topic
Author

Maven + scala + java

Pankaj Mittal
Ranch Hand

Joined: Jul 09, 2008
Posts: 32
I need scala and java code integration in my project so thought of going for Maven but don't have much exposure to maven and scala integration....so if anybody can post an example showing calling java function from scala and scala functions from java and maven setting for this project or any useful link...I'll be thankful...

Pankaj


2008 SCJP(5.0) 88%
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi Pankaj,

I've not yet used Scala together with Maven, but I'm sure that Maven doesn't change anything for the integration of Scala and Java. You will just need the additional Maven plugin which is able to compile Scala code. Have a look at this for examples ;-)


Marco
Pankaj Mittal
Ranch Hand

Joined: Jul 09, 2008
Posts: 32
hii

Thanks for the link....actually problem is when I'm calling scala function from java code....It is not able to find the classfile even when class files are in classfiles folder only....when I tried to import it....it is not even showing class names...set POM files...done all settings....still not working..working from last 2 days on the same thing...I'll b thankful if you can help in any way..

Pankaj
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

I haven't yet tested the Scala/Maven approach. But if you can wait a few hours, I'll try a little example and give you feedback. Unfortuantely I'm not at home at the moment...

Marco
Pankaj Mittal
Ranch Hand

Joined: Jul 09, 2008
Posts: 32
Thanks for the prompt reply... I'll wait..I guess there is some problem in nbactions.xml...for java files it is working fine....so I guess action has to be added for scala files..

Pankaj
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi Pankaj,

sorry, it took quite a while, but I think I got it working now

Basically I followed the instructions on the Scala homepage and the project page of the Scala Maven plugin to create a new Maven project based on the Scala archetype 1.1. Then I created the few classes accordingly to this example. This example has even circular cross dependencies between Java and Scala, but it works as expected with my current Maven setup.

The POM file is a best-of from the URLs above The only problem I experienced was caused by the initial archetype POM which defined a <sourceDirectory> and <outputDirectory> element. Obviously this doesn't work for project with Scala AND Java. So I Just removed it.

Another thing that still doesn't work is my IDE support. I used the Scala plugin for NetBeans 6.7 to create and edit the files. But as the plugin is very new it seems that it has problems to find Scala classes from within Java classes. Maybe this is just because it's additionally a Maven project. Maybe I'm doing something wrong... I don't know at the moment. And even if the editor complains about a missing Scala class "Foo" the project still can be compiled with or without IDE.

I'm going to send you an email with the whole project as a ZIP file so that you can verify it yourself. I hope it works for you, too! As I said I used NetBeans 6.7! Maven is installed with Version 2.0.10 on Gentoo Linux. The Scala version is 2.7.5 and declared directly inside the POM file. Good luck If anyone else is interested, just let me know and I'll send you the project, too (although it's a really useless project :-)).

And here's the complete version of the POM file I created:


Cheers
Marco
Pankaj Mittal
Ranch Hand

Joined: Jul 09, 2008
Posts: 32
Hi Marco,

Thanks for prompt reply !! This project is not working in my netbeans 6.5.1, with maven plugin. I'm getting error in java file which is saying Foo class doesn't exist. Which archetype you did use? Can you exactly tell me? When I'm compiling it through bash without maven, it's working but not through netbeans. Any suggestions?

Regards,
Pankaj
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi Pankaj,

as I wrote there's a similar problem with NetBeans 6.7 and its standard Maven support. In fact NetBeans 6.7 is able to compile the Maven project but the editor also complains that it can't find the (Scala) class "Foo". Compilation from the console works perfectly, too.

I still don't the exact reason why the IDE complains about the missing class, although I guess it's just a problem with the Scala+Java mix and two different source folders for each language. I don't know if this a problem with the Maven support, Scala plugin or a general NetBeans problem when using multiple programming languages in one project.

Besides this minor problem you should still be able to compile the project from within NetBeans. At the moment I don't have NetBeans 6.5.x at hand, so I can't test it. I think you will just have to bind the correct Maven goals to the IDE's clean & build actions (sorry, don't know how this is done in NetBeans 6.5). If I remember it correctly you should at least be able to call Maven goals directly. Have you tried to call "clean" and "compile" manually? Because compilation is done entirely with Maven, I think it should work for any IDE...

Marco
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Maven + scala + java
 
Similar Threads
Which tools do you recommend for learning Scala ?
Maven 1.0.2 Report Generation.
Make a project be dynamic web project
Questions on Lift
maven - conventions for integration tests