简体   繁体   English

在Grails中导入/使用Java类

[英]Importing/using Java classes in Grails

I have an existing RESTful service created with Jersey, for which I created 2 clients (also Java), one using the Jersey client API, and one using Apache HTTP client. 我使用Jersey创建了一个现有的RESTful服务,为此我创建了2个客户端(也是Java),一个使用Jersey客户端API,一个使用Apache HTTP客户端。

I don't have much frontend experience- I've used Spring/Java a little bit and understand the basic concepts, but I thought I would try learning Grails. 我没有太多的前端经验-我曾经使用过Spring / Java并了解一些基本概念,但是我认为我会尝试学习Grails。 I wanted to just use Grails for the front-end (So, no reliance on GORM), and use my existing service for business logic/interaction with storage). 我只想将Grails用于前端(因此,不依赖GORM),而将现有服务用于业务逻辑/与存储的交互)。 Would it be possible for me to just include the jar w/ my existing client and use it in my Grails controller, or will I need to write a new Groovy client for it using a Groovy (or an already included java library)? 对我来说,是否可以仅将w / w /现有客户端包括在内并在Grails控制器中使用它,还是需要使用Groovy(或已经包含的java库)为其编写新的Groovy客户端?

I'd also be happy to get opinions on if this seems like a good idea, or if it seems pointless to use Grails if I'm not taking advantage of GORM/Grails data persistence functionality? 如果这似乎是个好主意,或者如果我没有利用GORM / Grails数据持久性功能,使用Grails似乎毫无意义,我也很乐意就此发表意见。 I figured I could still get the advantage of 'convention over configuration', and maybe some other advantages of the framework, but again I'm pretty new to web development so I'd appreciate any advice. 我认为我仍然可以获得“约定优先于配置”的优势,也许还有框架的其他优势,但是我还是Web开发的新手,所以我很乐意提供任何建议。

You can use your existing java client in grails. 您可以在grails中使用现有的Java客户端。 If your existing client jar is in a maven repo then you can specify dependency for the jar in BuildConfig.groory. 如果您现有的客户端jar位于Maven存储库中,则可以在BuildConfig.groory中为该jar指定依赖项。 or else you can just drop the jar inside your grails projects lib directory. 否则,您可以将jar放到grails项目的lib目录中。

Also, if your client code depends on any third party jars, you will have to specify dependency for that third party jars in BuildConfig.groovy - See grails docs for how to specify dependencies. 另外,如果您的客户端代码依赖于任何第三方jar,则必须在BuildConfig.groovy中为该第三方jar指定依赖关系-有关如何指定依赖关系的信息,请参阅grails文档。

If you want, you can use grails rest-client-builder plugin to write your client too. 如果需要,您也可以使用grails rest-client-builder插件编写客户端。

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

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