Groovy variable not accessible in java class of same project in eclipse

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Groovy variable not accessible in java class of same project in eclipse

Bhushan Bhangale

I have a maven java project in eclipse. I added a groovy file in the project having a public variable. I access the groovy variable in another java class but i get compilation error (see below). I have the GRECLIPSE plugin installed. Also via command line when I build the project using mvn it compiles successfully. 

How do I resolve this? 

Groovy class - 

package com.impl 

class UserConstants { 
    public static final String USER_PREFERENCES = 
        """Some value""" 
} 
Java class in the same package. At the import line I get error "The import cannot be resolved" and due to that I get error at the Sysout line also "USER_PREFERENCES cannot be resolved to a variable" 

package com.impl 

import static com.impl.UserConstants.USER_PREFERENCES; 

public class UserPreferences { 
    public UserPreferences() { 
        System.out.println(USER_PREFERENCES); 
    } 
}

Reply | Threaded
Open this post in threaded view
|

Re: Groovy variable not accessible in java class of same project in eclipse

Andrew Eisenberg
It seems like your project is not a groovy project.  Are you using
m2eclipse?  And if so, do you have the groovy-eclipse configurator for
m2eclipse installed?  That's probably the easiest way of getting
things working.  Otherwise, you will have to use the maven-eclipse
plugin with some extra configuration.



On Wed, Feb 1, 2012 at 10:28 PM, Bhushan Bhangale
<[hidden email]> wrote:

> I have a maven java project in eclipse. I added a groovy file in the project
> having a public variable. I access the groovy variable in another java class
> but i get compilation error (see below). I have the GRECLIPSE plugin
> installed. Also via command line when I build the project using mvn it
> compiles successfully.
>
> How do I resolve this?
>
> Groovy class -
>
> package com.impl
>
> class UserConstants {
>     public static final String USER_PREFERENCES =
>         """Some value"""
> }
> Java class in the same package. At the import line I get error "The import
> cannot be resolved" and due to that I get error at the Sysout line also
> "USER_PREFERENCES cannot be resolved to a variable"
>
> package com.impl
>
> import static com.impl.UserConstants.USER_PREFERENCES;
>
> public class UserPreferences {
>     public UserPreferences() {
>         System.out.println(USER_PREFERENCES);
>     }
> }

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

RE: Groovy variable not accessible in java class of same project in eclipse

Bhushan Bhangale
No it's not a groovy project. It is a java project having some groovy classes. These classes are accessed by java classes of the same project but I get compilation errors.

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Andrew Eisenberg
Sent: 02 February 2012 08:52
To: [hidden email]
Subject: Re: [groovy-eclipse-plugin-user] Groovy variable not accessible in java class of same project in eclipse

It seems like your project is not a groovy project.  Are you using m2eclipse?  And if so, do you have the groovy-eclipse configurator for m2eclipse installed?  That's probably the easiest way of getting things working.  Otherwise, you will have to use the maven-eclipse plugin with some extra configuration.



On Wed, Feb 1, 2012 at 10:28 PM, Bhushan Bhangale <[hidden email]> wrote:

> I have a maven java project in eclipse. I added a groovy file in the
> project having a public variable. I access the groovy variable in
> another java class but i get compilation error (see below). I have the
> GRECLIPSE plugin installed. Also via command line when I build the
> project using mvn it compiles successfully.
>
> How do I resolve this?
>
> Groovy class -
>
> package com.impl
>
> class UserConstants {
>     public static final String USER_PREFERENCES =
>         """Some value"""
> }
> Java class in the same package. At the import line I get error "The
> import cannot be resolved" and due to that I get error at the Sysout
> line also "USER_PREFERENCES cannot be resolved to a variable"
>
> package com.impl
>
> import static com.impl.UserConstants.USER_PREFERENCES;
>
> public class UserPreferences {
>     public UserPreferences() {
>         System.out.println(USER_PREFERENCES);
>     }
> }

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Groovy variable not accessible in java class of same project in eclipse

Andrew Eisenberg
If you want your Java classes to access Groovy classes, then you must
convert your project into a groovy project.

On Thu, Feb 2, 2012 at 8:54 AM, Bhushan Bhangale
<[hidden email]> wrote:

> No it's not a groovy project. It is a java project having some groovy classes. These classes are accessed by java classes of the same project but I get compilation errors.
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On Behalf Of Andrew Eisenberg
> Sent: 02 February 2012 08:52
> To: [hidden email]
> Subject: Re: [groovy-eclipse-plugin-user] Groovy variable not accessible in java class of same project in eclipse
>
> It seems like your project is not a groovy project.  Are you using m2eclipse?  And if so, do you have the groovy-eclipse configurator for m2eclipse installed?  That's probably the easiest way of getting things working.  Otherwise, you will have to use the maven-eclipse plugin with some extra configuration.
>
>
>
> On Wed, Feb 1, 2012 at 10:28 PM, Bhushan Bhangale <[hidden email]> wrote:
>> I have a maven java project in eclipse. I added a groovy file in the
>> project having a public variable. I access the groovy variable in
>> another java class but i get compilation error (see below). I have the
>> GRECLIPSE plugin installed. Also via command line when I build the
>> project using mvn it compiles successfully.
>>
>> How do I resolve this?
>>
>> Groovy class -
>>
>> package com.impl
>>
>> class UserConstants {
>>     public static final String USER_PREFERENCES =
>>         """Some value"""
>> }
>> Java class in the same package. At the import line I get error "The
>> import cannot be resolved" and due to that I get error at the Sysout
>> line also "USER_PREFERENCES cannot be resolved to a variable"
>>
>> package com.impl
>>
>> import static com.impl.UserConstants.USER_PREFERENCES;
>>
>> public class UserPreferences {
>>     public UserPreferences() {
>>         System.out.println(USER_PREFERENCES);
>>     }
>> }
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email