I am new to Groovy and to this forum and it is possible that the problem
I explain below has been solved already or it is not a problem at all (I
am doing the wrong thing).
My problem is that I am not able to run an application packaged as a JAR
file from Groovy source files. I do not have problems doing the same
from classes compiled with the Java compiler (javac).
For testing, I used the following three files: Book.groovy,
BookApp.groovy and the manifest books.mf (the examples are taken from
the book "Groovy in Action"):
Book.groovy:
class Book {
String title
Book (String theTitle) {
title = theTitle
}
String getTitle(){
return title
}
static void main(String[] args){
}
}
---
BookApp.groovy:
public class BookApp {
public static void main(String[] args) {
Book gina = new Book('Groovy in action')
print(gina.getTitle())
}
}
---
books.mf:
Main-Class: BookApp\n
(\n means that the line is terminated as required)
---
Then I compile the source files with groovyc:
groovyc BookApp.groovy
--> FILES:
Book.class
BookApp.class
And I test and confirm that I can run them successfully with java:
java BookApp
--> OUTPUT:
Groovy in action
I build an application packaged as a JAR file:
jar cmf books.mf BookApp.jar Book.class BookApp.class
--> FILE:
BookApp.jar
I make sure that both classes are in JAR file using the jarlook.jar
utility ()
java -jar jarlook.jar BookApp.jar
--> OUTPUT:
Book.class
BookApp.class
META-INF/
META-INF/MANIFEST.MF
I checke and confirme that MANIFEST.MF contains the line:
Main-Class: BookApp
I finally try and fail to run the application running the java program
with the -jar switch:
javaw.exe -jar BookApp.jar
--> OUTPUT:
Could not find the main class: BookApp. Program will exit.
I do not know what is going on and I would appreciate your help and
advice very much.
Thanks in advance,
Alexis
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Alexis
If he had a classpath problem, then it should show itself as
ClassNotFoundException for a groovy runtime class. But the main class
itself was not found.
bye blackdrag
Exception in thread "main" java.lang.NoClassDefFoundError:
groovy/lang/Script
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Caused by: java.lang.ClassNotFoundException: groovy.lang.Script
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
... 12 more
Could not find the main class: BookApp. Program will exit.
Notice the first line: Exception in thread "main"
java.lang.NoClassDefFoundError: groovy/lang/Script. This message
incidentally is the same one I get when trying to run the Application class
file without setting the CLASSPATH variable to point to the Groovy
embeddable JAR file. It seems that it could have to do with failing
dependencies, as Martin pointed out. However the question, if this is true,
is then: why is setting the CLASSPATH works with class files but not with
the JAR file? Is it possible to solve this problem without embedding the
Grroovy JAR file (>4MB)? By the way: I did not manage yet to embed it into
the target application, so I cannot confirm yet that embedding solves the
problem.
Greetings: Alexis
Class-Path:
file:/C:/Program%20Files%20(x86)/Groovy/Groovy-1.6.3/embeddable/groovy-all-1.6.3.jar
The JAR File Specification speaks of "relative URLs" but the above setting
works for me. It would be nice though to be able to use environment
variables in the Class-Path attribute (like ${GROOVY_HOME}); this way the
generated JAR could be easily shared among different users.
My question did not have anything to do with Groovy itself and therefore I
apologize for eventually bothering this list with it.
Thanks: Alexis