未找到lib目录中的Grails JAR文件 [英] Grails JAR file in lib directory not found

查看:110
本文介绍了未找到lib目录中的Grails JAR文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个位于 src / java 中的Java类,它引用了来自外部JAR的类。我将JAR文件复制到 lib 目录中。当我使用 grails run-app 运行应用程序时,出现无法找到导入类的错误。

I have a Java class which is located in src/java that references classes from an external JAR. I copied the JAR file to the lib directory. When I go to run the app using grails run-app I get an error that it can't find the imported class.

为Grails项目放置JAR的正确位置是什么?是否有一些特殊命令让Grails识别新添加的JAR文件?

What is the correct location to put JARs for a Grails project? Is there some special command to get Grails to recognize the newly added JAR files?

我在OS X上运行带有Java 1.6.0_29的Grails 2.0.0。

I am running Grails 2.0.0 with Java 1.6.0_29 on OS X.

后续: JARs的问题来自 Apache HttpComponents 。更具体地说:

Follow-up: The JARs are question are from Apache HttpComponents. More specifically:

commons-codec-1.4.jar
commons-logging-1.1.1.jar
httpclient-4.1.2.jar
httpclient-cache-4.1.2.jar
httpcore-4.1.2.jar
httpmime-4.1.2.jar

其中的类文件被编译为Java 1.3,这应该不成问题。

The class files in them are compiled to Java 1.3, which shouldn't be a problem.

~/temp/org/apache/http $ file HttpResponse.class 
HttpResponse.class: compiled Java class data, version 47.0 (Java 1.3)


推荐答案

添加jar的正确方法是将它添加到 BuildConfig.groovy。例如:

The correct way to add jar's is by adding it to your "BuildConfig.groovy". You can specify if it is needed at compile time, runtime etc. For example:

dependencies {        
        build 'org.apache.httpcomponents:httpcore:4.1.2' 
        build 'org.apache.httpcomponents:httpclient:4.1.2' 
        runtime 'org.apache.httpcomponents:httpcore:4.1.2'
        runtime 'org.apache.httpcomponents:httpclient:4.1.2'
} 

请注意,您可能还需要取消注释Buildconfig.groovy中的mavenCentral()行,以便依赖关系得到解决。

Please note, you may also need to uncomment the mavenCentral() line in your Buildconfig.groovy in order for the dependencies to get resolved.

请参阅依赖关系解析一节 here

See "Dependency Resolution" section here.

这篇关于未找到lib目录中的Grails JAR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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