简体   繁体   English

如何从Grails项目中使用或引用Java项目?

[英]How to use or reference a Java project from a Grails project?

I have a grails project that works normally. 我有一个正常工作的grails项目。 Lately, our team decided to put an extra feature in the app that was already implemented in a Java standalone app of our own. 最近,我们的团队决定在应用程序中添加一个额外的功能,该功能已经在我们自己的Java独立应用程序中实现。 "So", I thought, "I only need to reference the standalone Java project in my workspace". “那么”,我想,“我只需要在我的工作区中引用独立的Java项目”。 So I did that - referenced my Java project from the Grails one and called the service from a Groovy class located in src/groovy. 所以我这样做了 - 从Grails one引用了我的Java项目,并从位于src / groovy的Groovy类中调用了该服务。 When I tried to run the web project I got a compilation error: 当我尝试运行Web项目时,出现了编译错误:

Error Compilation error: startup failed: 
unable to resolve class com.CycleManager

And it says that the error is the import line for the CycleManager class. 它说错误是CycleManager类的导入行。

Why can't groovy find the referenced project? 为什么不能groovy找到引用的项目? What am I doing wrong? 我究竟做错了什么?

Thanks. 谢谢。

This happens because grails cannot see the jar/classes which is exposing the service. 发生这种情况是因为grails无法看到暴露服务的jar /类。 You need to include the jar(s) in your grails classpath(which is not in your workspace). 您需要在grails类路径中包含jar(不在您的工作区中)。 This can be done by mentioning about the jar in the BuildConfig.groovy file of your grails application in dependencies section. 这可以通过在依赖关系部分的grails应用程序的BuildConfig.groovy文件中提及jar来完成。

dependencies {
             // your jar name
    compile ("com.CycleManager")
}

This is the proper way to include the jars in your application. 这是在您的应用程序中包含jar的正确方法。

PS : Grails expects your jar to be in its ivy-cache. PS:Grails希望你的jar在其常春藤缓存中。 If it is not present in ivy-cache it will be pulled from your snapshots folder. 如果它不存在于ivy-cache中,它将从快照文件夹中提取。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM