java - Groovy 无法解析 Java 类

标签 java ant groovy

我在从 ant 文件执行 groovy 时遇到了问题。

在带有启动器的 Eclipse 中,一切正常,但是当我运行 ant 文件时,我得到了以下输出:

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 是同一个包中的java 类..

public class InitializeDatabase {

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

我猜问题出在 ant 文件上:

<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>

有人可以帮帮我吗?

最佳答案

您需要在您的groovyc 任务中包含javac 任务。变化:

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

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

它应该可以正常工作。作为它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.

关于java - Groovy 无法解析 Java 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9942628/

相关文章:

Java Webstart 启动时出错

java - 返回两个集合的交集的具有不同签名的方法 (Java)

java - 你能对混淆代码进行单元测试吗?

list - Groovy 列表应用闭包

java - 转义=java字符串中的字符

java - 我如何在 Kotlin 中编写 Java 括号 "[ ]"?

tomcat - 远程部署在tomcat 6.0.14服务器

android - Apache Cordova 和 PhoneGap 有什么区别?

grails - 在运行时编译用户输入的Groovy脚本

xml - 将 XML 导入 Grails 域类