Kyle
Kyle

Reputation: 3885

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

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

Upvotes: 15

Views: 10036

Answers (2)

Musaddique
Musaddique

Reputation: 443

if your jar is in lib folder and also entry in buildconfig.groovy and if you can't find jar in your build path then try to use below command.

grails compile --refresh-dependencies

Upvotes: 0

Kyle
Kyle

Reputation: 3885

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

Upvotes: 26

Related Questions