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...
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 ;-)
Joined: Jul 09, 2008
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..
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:
Joined: Jul 09, 2008
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?
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...