Reputation: 63134
How can I reference a Groovy domain class from Java class using Eclipse?
I've put my domain class in package:
package com.me.myproject
public class Person {
String name
int age
}
Then in my Java class I attempt to reference com.me.myproject.Person
. This works for grails run-app
(command line) but not Eclipse. Eclipse can't resolve the Groovy domain class.
I'm running Eclipse 3.4.1 with the latest Groovy and Grails Eclipse plugins:
I've tried setting the Eclipse default output folder to the same as Groovy compiler output location. I've also tried both enabling and disabling the “Disable Groovy Compiler Generating Class Files” setting. I've also tried not putting any of my classes in a package. None of these work.
Upvotes: 4
Views: 3724
Reputation: 2039
It seems I'm a little late to this party but I was running into the same problem. I was able to resolve referencing a Groovy domain class from a Java class by converting the project to a Groovy Project. Instructions are as follows:
My Environment is as follows:
Finally, I did not mess with any "Disable Groovy Compiler Generating Class Files" option.
Upvotes: 0
Reputation: 4643
I am not sure if referencing files or folders is the good way. You should use modularization. So you domain classes will be stored in separate "project". It is possible to do it by creating plugins. You can find great explanation and source code here.
Upvotes: 0
Reputation: 28757
Please upgrade to V2 of the groovy-eclipse plugin as this problem has been fixed. V2 of the plugin does not build stubs and does not have any problem with circular dependencies between Java and Groovy. The plugin now ships with a feature patch that patches the JDT compiler so that it can natively work with groovy files.
Upvotes: 0
Reputation: 2395
I also wasn't able to get it to work using the same output folder for Groovy and Java, but it does seem to work if you use different output folders.
Here's what I did. Via the project properties dialog:
web-app/WEB-INF/groovy-classes
You should now be able to use the compiled Groovy classes from Java.
I think this is more of a hack than a solution, but it's doing the job for me for now.
Upvotes: 0
Reputation: 14640
While I haven't tried it, I believe you'll need to add the Domain folder as a src folder in your Java build path.
Right-click on project select Properties. Click on Java Build Path, then the Source tab. Click add-folder and make sure your project/grails-app/domain is in the path.
If that doesn't work, then you're right, I'm not sure what the issue is.
FYI, Spring-Source being such an Eclipse sponsor, I'd look forward to a much improved Eclipse plugin in the near future. But you're right. For now, it's annoying.
Upvotes: 0
Reputation: 4251
I haven't been able to make this work in eclipse either. Until spring gets the groovy / grails eclipse plugins whipped up to do something other than mere color coding your best bet is to use an IDE like Intelij which has the best groovy support at the moment.
Upvotes: 1