如何为grails项目添加一个“非mavenized”jar依赖项(Grails 3.x) [英] How to add a “non-mavenized” jar dependency to a grails project (Grails 3.x)

查看:114
本文介绍了如何为grails项目添加一个“非mavenized”jar依赖项(Grails 3.x)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到关于如何将本地/非maven jar文件添加到我的Grails 3.x项目的文档和代码示例?



我发现单独的线程如何添加非-maven jar to grails - 但这只是为了grails 2.3,并且文件结构和配置在3.x中经历了一次大的改动。



任何帮助和(特别是)代码示例将是美好的! .jar位于本地项目目录中,我打算使用.war打包进行部署。



另外,一旦我添加了依赖项,我应该能够从控制器中调用它的方法&服务档案?或者我是否需要将它们包含在这些内容中?

thx!

解决方案

Grails 3使用Gradle,所以Grails没有关于包含本地jar的具体内容。这很简单,只需将文件依赖项添加到 build.gradle 文件的依赖项块中即可。



根据文件相关性的 Gradle文档
$ b


要将某些文件作为配置的依赖项添加,只需将文件集合作为依赖项传递即可:




 依赖关系{

...

编译文件('libs / a.jar','libs / b.jar')
//或
编译fileTree(dir:'libs',include:'* .jar')





$ b

上面的例子展示了两种包含存在于本地 libs / 目录;你可以做/或。 jar文件可以在文件系统的任何地方,只要确保指向正确的路径即可。



要在应用程序中使用依赖关系中的类,将它们包括在你的服务,控制器和所有其他类中,就像你通常那样。说 libs / a.jar 有一个类 org.example.Something ,你可以在上面添加一个导入你的Grails类就像这样:

  import org.example.Something 


I'm trying to find documentation and code samples on how to add a local / non-maven jar file to my Grails 3.x project?

I found the separate thread How to add a non-maven jar to grails - but that's only to grails 2.3, and the file structure and configuration has undergone a big overhaul in 3.x.

Any help and (especially) code samples would be wonderful! The .jar is in the local project directory, and I intend to package with the .war for deployment.

Additionally, once i add the dependency, should i just be able to call it's methods from the controller & service files? or do i need to include them in those as well?

thx!

解决方案

Grails 3 uses Gradle, so there's nothing Grails specific about including a local jar. It's as easy as adding a file dependency to the dependencies block of your build.gradle file.

Per the Gradle documentation on File Dependencies:

To add some files as a dependency for a configuration, you simply pass a file collection as a dependency:

dependencies {

    ...

    compile files('libs/a.jar', 'libs/b.jar')
    // or
    compile fileTree(dir: 'libs', include: '*.jar')
}

The above example shows two ways to include jars that exist in a local libs/ directory; you can do either/or. The jar(s) can be anywhere on the filesystem, just make sure you point to the correct path.

To use the classes from the dependency in your application, you'll include them in your services, controllers and all other classes like you normally would. Say libs/a.jar has a class org.example.Something, you'd add an import to the top of your Grails class like so:

import org.example.Something

这篇关于如何为grails项目添加一个“非mavenized”jar依赖项(Grails 3.x)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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