Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails JAR file in lib directory not found

Tags:

java

jar

grails

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.

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?

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

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

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)
like image 854
Steve Kuo Avatar asked Jan 09 '12 06:01

Steve Kuo


3 Answers

Very odd, I ran grails clean and then grails run-app and it compiled and ran fine.

like image 120
Steve Kuo Avatar answered Oct 22 '22 00:10

Steve Kuo


When you add or remove jar files in lib you need to run

grails compile --refresh-dependencies

in order to get Grails to notice the changes.

like image 42
Ian Roberts Avatar answered Oct 22 '22 00:10

Ian Roberts


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'
} 

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

See "Dependency Resolution" section here.

like image 5
Manish Avatar answered Oct 21 '22 22:10

Manish