How to generate a runnable JAR file in a Groovy project?

Hello,  I am new both to Groovy and to IntelliJ IDEA, so please forgive me if my question is too simple. I have been playing with IntelliJ IDEA for a couple of hours trying to find a solution to my problem but I was not able to find one. FYI: I am using IntelliJ IDEA version 8.1.2 on Windows Vista with the JetGroovy plugin activated (JDK 1.6.0_13).  Building classes from groovy source files is not a problem with the nice JetGroovy plugin: for Main.groovy, java Main works as expected. But when I build a JAR file for my project and try to run it I get the following error:  Exception in thread "main" java.lang.NoClassDefFoundError: groovy/lang/GroovyObject (...)  After researching on this quite a bit, I found out that the problem is the way the JAR file has to be built: my solution on the command-line is to add a "Class-Path" attribute pointing out to the Groovy JAR file (groovy-all-1.6.3.jar) in the JAR manifest and including this when building the JAR file:  jar cmf MANIFEST.MF Project.jar *.class  Only then I am able to run the JAR file.  Is there a way to include this dependency automatically from within IntelliJ IDEA? Ideally, it would be perfect if it would be possible to include in the JAR file those Groovy classes used in the project in order to make the JAR file not dependent on the Groovy JAR (groovy-all-1.6.3.jar).  Thanks in advance for any help or advice,  Alexis

0
1 comment
Avatar
Permanently deleted user

Well, I think I found the answer myself.

A JAR file with the correct dependencies can be built changing the settings in Build - Build Jars - Include in Jar file: then selecting Add... and adding the libraries or modules that are needed for running the application. Still, for this to work, I had to change the packaging method of the library properties to "Link via manifest and copy files to". The "output relative path" can be made also absolute (something that I found out before solving the present issue), for example: file:/C:/Program%20Files/Java/groovy-1.6.3/embeddable. Notice that in this case nothing is copied. This is useful when the required library is installed in the same place for all users that will use the module to be distributed. Otherwise, lib/ is a good choice.

Regards.

0

Please sign in to leave a comment.