- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Referencing Java libraries in Eclipse?
Wed, 2009-03-04, 01:33
Howdy, folks. I'm a longtime programmer but a Scala newbie. I'm bootstrapping a company, and after a year of getting increasingly annoyed with Java, I've decided to try switching over to Scala for the next phase of the project. (Besides liking the look of the language, I think the Actors model suits my app rather well.) So I'm trying to build a Scala-actors layer on top of my existing Java code. I'll probably have a bunch of dumb questions -- feel free to point me at relevant FAQs.
My first problem is (I think) specifically with the Eclipse plugin, which is why I'm writing to this list. I understand the broad strokes of how to mix Java and Scala at the language and code-organization level, and they don't bother me -- I'm pretty fanatical about decoupling, so everything's pretty well-designed for that to begin with, with most communication happening between interfaces. In theory, the modules should work together properly.
The problem is, the Scala Eclipse plugin isn't acknowledging my Java libraries in the first place. I have two Java Eclipse projects that I want the Scala code to rely on, QuerkiLib (the central utility classes) and CommYouCore (the guts of the app logic). I've created a Scala project, CommYouActors; this references both of those projects. I've put both projects on the build path (although I suspect that that's just for Java, and irrelevant to the Scala compiler). I've even tried placing a JAR into CommYouActors containing the classes from both Java projects. In all cases, the simplest
import org.querki.Library._
is giving me errors.
So I'm clearly missing something, probably in the project properties. How am I supposed to tell a Scala project to include a Java project on its build path? I think I understand what this should look like in ant, but I do the guts of my development in Eclipse, so I'd like to get things cleaned up in there...
My first problem is (I think) specifically with the Eclipse plugin, which is why I'm writing to this list. I understand the broad strokes of how to mix Java and Scala at the language and code-organization level, and they don't bother me -- I'm pretty fanatical about decoupling, so everything's pretty well-designed for that to begin with, with most communication happening between interfaces. In theory, the modules should work together properly.
The problem is, the Scala Eclipse plugin isn't acknowledging my Java libraries in the first place. I have two Java Eclipse projects that I want the Scala code to rely on, QuerkiLib (the central utility classes) and CommYouCore (the guts of the app logic). I've created a Scala project, CommYouActors; this references both of those projects. I've put both projects on the build path (although I suspect that that's just for Java, and irrelevant to the Scala compiler). I've even tried placing a JAR into CommYouActors containing the classes from both Java projects. In all cases, the simplest
import org.querki.Library._
is giving me errors.
So I'm clearly missing something, probably in the project properties. How am I supposed to tell a Scala project to include a Java project on its build path? I think I understand what this should look like in ant, but I do the guts of my development in Eclipse, so I'd like to get things cleaned up in there...
Wed, 2009-03-04, 02:07
#2
Re: Referencing Java libraries in Eclipse?
Humph. I deleted the project and rebuilt it, and now it's working. Odd. Possibly an error-caching problem of some sort? The first time, I first wrote the code, got the expected unresolveable-import error, then added the projects to the path, but the error wouldn't go away. I think that misled me into believing the path wasn't working. The second time, I added the projects to the path from the beginning (before writing any code), and the import now seems to be working fine.
Is there any sort of introduction to working on the Eclipse plugin itself? While I'm by no means an Eclipse expert, I know my way around code -- it may be helpful to start reading myself into it a bit, so I can help diagnose these things better in future. (Related question: how stable is the plugin's trunk? While I'm happy to help out as I can, I do need to focus on getting work done, so I have to be a little careful...)
On Tue, Mar 3, 2009 at 7:39 PM, Miles Sabin <miles@milessabin.com> wrote:
Is there any sort of introduction to working on the Eclipse plugin itself? While I'm by no means an Eclipse expert, I know my way around code -- it may be helpful to start reading myself into it a bit, so I can help diagnose these things better in future. (Related question: how stable is the plugin's trunk? While I'm happy to help out as I can, I do need to focus on getting work done, so I have to be a little careful...)
On Tue, Mar 3, 2009 at 7:39 PM, Miles Sabin <miles@milessabin.com> wrote:
On Wed, Mar 4, 2009 at 12:33 AM, Justin du coeur <jducoeur@gmail.com> wrote:
> So I'm clearly missing something, probably in the project properties. How
> am I supposed to tell a Scala project to include a Java project on its build
> path?
It should work in exactly the same way as for Java project
dependencies ... you add the projects to the (Java) build path for the
Scala project.
You say the import is giving you errors ... what errors exactly?
Cheers,
Miles
--
Miles Sabin
tel: +44 (0)1273 720 779
mobile: +44 (0)7813 944 528
skype: milessabin
Wed, 2009-03-04, 11:27
#3
Re: Referencing Java libraries in Eclipse?
On Wed, Mar 4, 2009 at 12:56 AM, Justin du coeur wrote:
> Is there any sort of introduction to working on the Eclipse plugin itself?
Yes, here,
http://lampsvn.epfl.ch/trac/scala/wiki/EclipsePlugin
> While I'm by no means an Eclipse expert, I know my way around code -- it may
> be helpful to start reading myself into it a bit, so I can help diagnose
> these things better in future.
That would be fantastic! Thanks!
> (Related question: how stable is the plugin's trunk? While I'm happy to help
> out as I can, I do need to focus on getting work done, so I have to be a little
> careful...)
There are a couple of annoying issues on trunk at the moment which I'm
dealing with right now (markers and annotations are a bit flaky, but
otherwise things are reasonable functional).
Cheers,
Miles
On Wed, Mar 4, 2009 at 12:33 AM, Justin du coeur wrote:
> So I'm clearly missing something, probably in the project properties. How
> am I supposed to tell a Scala project to include a Java project on its build
> path?
It should work in exactly the same way as for Java project
dependencies ... you add the projects to the (Java) build path for the
Scala project.
You say the import is giving you errors ... what errors exactly?
Cheers,
Miles