Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy unable to resolve java class

Tags:

java

groovy

ant

i got a problem by executing groovy from an ant file.

In Eclipse with a launcher, everything works fine but wehn i run the ant file i got the following output:

Main.groovy: 71: unable to resolve class InitializeDatabase
[groovyc] @ line 71, column 40. [groovyc] java.lang.Object javaClassInstance = new InitializeDatabase()
[groovyc]

[groovyc] 1 error

InitializeDatabase is a java class in the same package..

public class InitializeDatabase {

    public void test() {
        System.out.println("Hello Groovy");
    }
}

I guess the problem is located at the ant file:

<project name="tp" basedir="." default="dbsetup">
    <target name="dbsetup">
        <taskdef name="groovyc" classname="org.codehaus.groovy.ant.Groovyc">
            <classpath>
                <fileset dir="../files/lib/default" includes="*.jar" />
            </classpath>
        </taskdef>
        
        <delete dir="bin" />
        <mkdir dir="bin" />
        <groovyc srcdir="src" destdir="bin" />
        
        <java classname="groovy.ui.GroovyMain" dir="../.." fork="true" failonerror="true">
            <classpath>
                <fileset dir="../files/lib/default" includes="*.jar"/>
                <pathelement location="bin"/>
            </classpath>
            <arg line="build/scripts/src/build/Main.groovy" />
        </java>
    </target>
            
</project>

Can someone help me please?

like image 701
Michael S Avatar asked Feb 13 '26 04:02

Michael S


1 Answers

You need to include the javac task inside your groovyc one. Change:

    <groovyc srcdir="src" destdir="bin" />

to

    <groovyc srcdir="src" destdir="build">
        <javac/>
    </groovyc>

And it should work fine. As it says here:

Joint compilation means that the Groovy compilation will parse the Groovy source files, create stubs for all of them, invoke the Java compiler to compile the stubs along with Java sources, and then continue compilation in the normal Groovy compiler way. This allows mixing of Java and Groovy files without constraint.

...

The right way of working is, of course, to use a nested tag and all the attributes and further nested tags as required.

like image 95
tim_yates Avatar answered Feb 15 '26 17:02

tim_yates



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!