Grails无法识别Java类 [英] Grails fails to recognize Java class

查看:77
本文介绍了Grails无法识别Java类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 7(32位)上使用Groovy / Grails Tool Suite 3.1.0。我不能在我的生活中让Grails识别我在我的Grails应用程序的/ src / java目录中创建的简单Java类。



这是我的java类:

  public class PleaseWork {

public static void hello()
{
System.out.println(来自java类的Hello。);




$ b我从我创建的服务调用java类:

  package mypackage $ b $ class CreatePdfService {

def serviceMethod(){

PleaseWork.hello()
}
}

I已经检查了我的项目的.classpath,我看到以下内容:

 < classpath> 
< classpathentry kind =srcpath =src / java/>
< classpathentry kind =srcpath =src / groovy/>
< classpathentry kind =srcpath =grails-app / conf/> ....

它看起来像我的java源代码目录,并且没有设置将它排除在外。一切看起来都不错。



我的理解是我应该可以毫无问题地调用那个java类。我可以做一个没有问题的Grails运行应用程序。但是,当我运行我的应用程序并且代码尝试调用PleaseWork.hello()时,我得到以下内容:

  |错误2013-02-18 15:59:10,898 [http-bio-8080-exec-4]错误errors.GrailsExceptionResolver  -  
处理请求时发生MissingPropertyException:[POST] / mypackage / main / createPdf
没有这样的属性:请为类class:mypackage.CreatePdfService工作。 Stacktrace如下:
消息:没有这样的属性:PleaseWork for class:mypackage.CreatePdfService

I已经完成了grails刷新依赖,没有任何工作。什么给了?

解决方案

您不能从包中的类的默认包中访问类。将该类移动到与该服务相同的包中,或者将其放入不同的包中并添加一个导入。


I'm using Groovy/Grails Tool Suite 3.1.0 on Windows 7(32 bit). I cannot for the life of me get Grails to recognize a simple Java class I created in the /src/java directory of my Grails application.

Here is my java class:

public class PleaseWork {

    public static void hello()
    {
        System.out.println("Hello from a java class.");
    }
}

I am calling the java class from a service I created:

package mypackage
class CreatePdfService {

    def serviceMethod() {

        PleaseWork.hello()
    }
}

I've checked my .classpath for my project and I see the following:

<classpath>
<classpathentry kind="src" path="src/java"/>
<classpathentry kind="src" path="src/groovy"/>
<classpathentry kind="src" path="grails-app/conf"/>....

It looks like my java source directory is included and there are no settings that are excluding it. Everything looks good.

My understanding is that I should be able to call that java class with no problem. And I can do a grails run-app with no issues. But... when I run my application and the code attempts to call PleaseWork.hello() I get the following:

| Error 2013-02-18 15:59:10,898 [http-bio-8080-exec-4] ERROR errors.GrailsExceptionResolver  -   
MissingPropertyException occurred when processing request: [POST] /mypackage/main/createPdf
No such property: PleaseWork for class: mypackage.CreatePdfService. Stacktrace follows:
Message: No such property: PleaseWork for class: mypackage.CreatePdfService

I've done grails refresh-dependencies and nothing works. What gives?

解决方案

You can't access classes from the "default" package from a class in a package. Either move the class to the same package as the service, or put it in a different one and add an import.

这篇关于Grails无法识别Java类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆