문제

I've written a Groovy script which has a dependency on a SQL Server driver (sqljdbc4.jar). I can use the GroovyWrapper (link below) to compile it into a JAR, however how can I get dependencies into the Jar? I'm looking for a "best practice" sort of thing.

https://github.com/sdanzan/groovy-wrapper

Both of the replies below have been helpful, but how can I do this for signed Jar files? For instance:

Exception in thread "main" java.lang.SecurityException: Invalid signature file d igest for Manifest main attributes

도움이 되었습니까?

해결책

In the groovy wrapper script, you'll see this line near the bottom:

// add more jars here

That's where you can add your dependencies. If the jar file is in the same directory you're building from, add a line like this:

zipgroupfileset( dir: '.', includes: 'sqljdbc4.jar' )

Then rerun the script and your jar will include the classes from sqljdbc4.jar.

Edit:

If the jar file you depend on is signed and you need to maintain the signature, you'll have to keep the external jar. You can't include jar files inside of other jar files without using a custom classloader. You can, however, specify the dependency in the manifest to avoid having to set the classpath, i.e. your jar still executable with java -jar myjar.jar. Update the manifest section in the wrapping script to:

manifest {
    attribute( name: 'Main-Class', value: mainClass )
    attribute( name: 'Class-Path', value: 'sqljdbc4.jar' )
}

다른 팁

From your link, if you look at the source of the GroovyWrapper script, there's this line:

zipgroupfileset( dir: GROOVY_HOME, includes: 'embeddable/groovy-all-*.jar' )
zipgroupfileset( dir: GROOVY_HOME, includes: 'lib/commons*.jar' )
// add more jars here

I'd explicitly add it there.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top