Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a "non-mavenized" jar dependency to a grails project

Tags:

grails

I'm a grails newby. I am using grails 2.0.3 from the command line (no IDE) on windows 7.

I am just running the 'hello world' example from the grails documentation.

I have a custom jar that is not in maven that I would like to use in my project. I added it to the lib folder and did a refresh-dependencies. I modified the controller to import a class from the jar. When I did 'run-app', the compiler complained that it could not find the class.

I saw several example online where people had to add a line to their BuildConfig.groovy like this: runtime 'httpclient:httpclient:3.0.1' . But since I'm not using maven or ivy, how do I get that jar on my classpath?

The example I am referring to above is http://grails.1312388.n4.nabble.com/External-Jar-in-Grails-td4388010.html

like image 492
Kyle Avatar asked Apr 21 '12 05:04

Kyle


1 Answers

Grails 2.0-2.2

Ok, I finally figured out what I need to do. Suppose my jar is named 'mylib.jar'. I need to rename it to mylib-1.0.jar and move it to the lib directory. Then I need to add the following to BuildConfig.groovy:

dependencies {
        // specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.

        // runtime 'mysql:mysql-connector-java:5.1.16'
    runtime 'mylib:mylib:1.0'
    }

I guess that was obvious to everyone but me. Hope this helps someone else.

Grails 2.3-...

Just put a jar into the lib/. Do not modify BuildConfig.groovy (c) kaskelotti

like image 136
Kyle Avatar answered Oct 18 '22 09:10

Kyle