[scala-tools] Mixed Java/Scala projects in Eclipse

View: New views
8 Messages — Rating Filter:   Alert me  

[scala-tools] Mixed Java/Scala projects in Eclipse

by Erkki Lindpere-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is it currently possible (with the 2.7.2RC2 plugin) to have mixed
Java/Scala projects in Eclipse? If so, how should it be configured.

Ideally it should work with M2Eclipse as well.

Erkki

[scala-tools] Re: Mixed Java/Scala projects in Eclipse

by Ismael Juma :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Erkki Lindpere <erkki@...> writes:
> Is it currently possible (with the 2.7.2RC2 plugin) to have mixed
> Java/Scala projects in Eclipse? If so, how should it be configured.

Yes, just follow the instructions here:

http://www.scala-lang.org/node/94

> Ideally it should work with M2Eclipse as well.

I haven't used M2Eclipse in a while, but it should work. It certainly works with
mvn eclipse:eclipse.

Ismael


Re: [scala-tools] Re: Mixed Java/Scala projects in Eclipse

by Erkki Lindpere-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, I didn't notice that page said mixed Java/scala projects are
supported.
But when I tried to create a mixed project, the compile worked if I
cleaned the project, but if I changed a Scala file after that (and
didn't do clean again), it became full of errors.

Ismael Juma wrote:

> Erkki Lindpere <erkki@...> writes:
>  
>> Is it currently possible (with the 2.7.2RC2 plugin) to have mixed
>> Java/Scala projects in Eclipse? If so, how should it be configured.
>>    
>
> Yes, just follow the instructions here:
>
> http://www.scala-lang.org/node/94
>
>  
>> Ideally it should work with M2Eclipse as well.
>>    
>
> I haven't used M2Eclipse in a while, but it should work. It certainly works with
> mvn eclipse:eclipse.
>
> Ismael
>
>  

[scala-tools] Re: Mixed Java/Scala projects in Eclipse

by Ismael Juma :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Erkki Lindpere <erkki@...> writes:
> But when I tried to create a mixed project, the compile worked if I
> cleaned the project, but if I changed a Scala file after that (and
> didn't do clean again), it became full of errors.

Did you do the following?

"* The per-project properties should be set as follows,

Right click on the project in the Package explorer, select "Properties → Java
Compiler → Building". Enusre that "Enable project specific settings" is checked,
then uncheck "Scrub output folders when cleaning projects" and add "*.scala" to
the "Filtered resources" field."

Also make sure none of your plugins is changing that setting. Also, what do you
mean by "it became full of errors"? Are these errors shown in the Problems view?
Also, are they in the Scala editor or Java editor?

Regards,
Ismael


Re: [scala-tools] Re: Mixed Java/Scala projects in Eclipse

by Erkki Lindpere-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hmm... those settings are correct by default. For some reason it didn't
work earlier, but works now. Don't know that I did anything differently
this time.

Ismael Juma wrote:

> Erkki Lindpere <erkki@...> writes:
>  
>> But when I tried to create a mixed project, the compile worked if I
>> cleaned the project, but if I changed a Scala file after that (and
>> didn't do clean again), it became full of errors.
>>    
>
> Did you do the following?
>
> "* The per-project properties should be set as follows,
>
> Right click on the project in the Package explorer, select "Properties → Java
> Compiler → Building". Enusre that "Enable project specific settings" is checked,
> then uncheck "Scrub output folders when cleaning projects" and add "*.scala" to
> the "Filtered resources" field."
>
> Also make sure none of your plugins is changing that setting. Also, what do you
> mean by "it became full of errors"? Are these errors shown in the Problems view?
> Also, are they in the Scala editor or Java editor?
>
> Regards,
> Ismael
>
>  

Re: [scala-tools] Mixed Java/Scala projects in Eclipse

by Erkki Lindpere-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, this works, but another question (which perhaps has more to do with
Maven but maybe someone here knows?):

Is it possible to build with Maven while having source folders set up
like this:
src/main/java -- Java files that are needed by the Scala code
src/main/scala -- Scala files

So far I managed to get it working by moving the Java files to the
src/main/scala folder.

Erkki Lindpere wrote:
> Is it currently possible (with the 2.7.2RC2 plugin) to have mixed
> Java/Scala projects in Eclipse? If so, how should it be configured.
>
> Ideally it should work with M2Eclipse as well.
>
> Erkki
>

[scala-tools] Re: Mixed Java/Scala projects in Eclipse

by Ismael Juma :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Erkki,

Erkki Lindpere <erkki@...> writes:
> Is it possible to build with Maven while having source folders set up
> like this:
> src/main/java -- Java files that are needed by the Scala code
> src/main/scala -- Scala files
>
> So far I managed to get it working by moving the Java files to the
> src/main/scala folder.

I looked at the source for the maven-scala-plugin sometime back and starting
from the configured source directory (src/main/java by default), it does
../scala to find the scala directory. I consider this a bit of a hack, but it
means that you can use what you require by simply leaving the source directory
as the default instead of changing it to point at src/main/scala.

Having said that, I don't think that the maven plugin includes real support for
mixed compilation yet (particularly cyclic dependencies). I haven't verified
this, but I think it just compiles the Scala files after the Java ones.

Hope it helps,
Ismael


Re: [scala-tools] Re: Mixed Java/Scala projects in Eclipse

by Josh Suereth :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've actually just made a request for the Maven-scala-plugin to
support the new mixed compilation as well (I don't think they had time
to update the plugin since the new mixed-compilation feature).  For
now the easiest thing to do is configure the Maven-scala-plugin  and
the maven-compiler-plugin to use the same source directory.

Something like this (untested):
<plugin>
   <artifactId>maven-scala-plugin</artifactId>
   ...
  <configuration>
    ...
   <sourceDir>src/main/java</sourceDir>
</plugin>

This way, scalac will be able to "see" the java files that it needs in
order to compile them.  You also want to make sure the
scala-maven-plugin gets executed *before* the maven-compiler-plugin.

The next issue is your classpath within eclipse.  I haven't used
m2eclipse in some time, but at least with IAM you need to make sure
your project is depending on the same version of the scala-library as
the plugin uses (for me, 2.7.2-rc1).  You can then actually remove the
inclusing of the scala-library from the list of jars on the classpath
(as the plugin will find the maven dependency).  This should give you
the best results in terms of "same behavior in maven seen in eclipse".

Anyway, I hope that works for you until the infrastructure imrpoves!

-Josh

On 9/20/08, Ismael Juma <mlists@...> wrote:

> Hi Erkki,
>
> Erkki Lindpere <erkki@...> writes:
>> Is it possible to build with Maven while having source folders set up
>> like this:
>> src/main/java -- Java files that are needed by the Scala code
>> src/main/scala -- Scala files
>>
>> So far I managed to get it working by moving the Java files to the
>> src/main/scala folder.
>
> I looked at the source for the maven-scala-plugin sometime back and starting
> from the configured source directory (src/main/java by default), it does
> ../scala to find the scala directory. I consider this a bit of a hack, but
> it
> means that you can use what you require by simply leaving the source
> directory
> as the default instead of changing it to point at src/main/scala.
>
> Having said that, I don't think that the maven plugin includes real support
> for
> mixed compilation yet (particularly cyclic dependencies). I haven't verified
> this, but I think it just compiles the Scala files after the Java ones.
>
> Hope it helps,
> Ismael
>
>
LightInTheBox - Buy quality products at wholesale price!