Using Groovy bytecode from java command line

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Using Groovy bytecode from java command line

Thomas Burleson
I have a class Synchronizer.groovy that compiles and runs great with Groovy and GroovySh.
I have the bytecode files in my "out" directory

    src
       - Syncrhonizer.groovy
   
    out
       - Synchronizer.class

[    ** my %JAVA_HOME% points to:

    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-b05)
    Java HotSpot(TM) Client VM (build 1.4.2_09-b05, mixed mode)
]

In a command window, I set the current directory to "out". Then I type "java -cp %GROOVY_JAR% Synchronizer".... to run the "main()" function in the bytecode.
I get an error:
         "Exception in thread "main" java.lang.NoClassDefFoundError: Synchronizer/class"
Why?

Reply | Threaded
Open this post in threaded view
|

Re: Using Groovy bytecode from java command line

Jochen Theodorou
Thomas Burleson schrieb:

> I have a class Synchronizer.groovy that compiles and runs great with Groovy
> and GroovySh.
> I have the bytecode files in my "out" directory
>
>     src
>        - Syncrhonizer.groovy
>    
>     out
>        - Synchronizer.class
>
> [    ** my %JAVA_HOME% points to:
>
>     Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-b05)
>     Java HotSpot(TM) Client VM (build 1.4.2_09-b05, mixed mode)
> ]
>
> In a command window, I set the current directory to "out". Then I type "java
> -cp %GROOVY_JAR% Synchronizer".... to run the "main()" function in the
> bytecode.
> I get an error:
>          "Exception in thread "main" java.lang.NoClassDefFoundError:
> Synchronizer/class"
> Why?

This looks very much like the newbe problem of having typed

java  Synchronizer.class

You are sure you haven't done this? Maybe because of autocompletion int
the shell or something alike?

bye blackdrag

--
Jochen Theodorou
Groovy Tech Lead
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Using Groovy bytecode from java command line

Thomas Burleson
No that is not the problem. Here is another example: TestMain.groovy ------------------------ class TestMain { static void main(args) { def msg = (args.size() < 1) ? "1+ Arguments needed" : args[0]; println msg; } } compiles to ../out/TestMain.class runs fine in Eclipse plugin No open command window. Cd ../out java -verbose -cp %JRE_PATH%;%GROOVY_EMBED%\groovy-all.jar; TestMain get the attached output TestMain.log (which does nothing.) So what gives?
Jochen Theodorou wrote
>>Thomas Burleson schrieb: >> I have a class Synchronizer.groovy that compiles and runs great with Groovy >> and GroovySh. >> I have the bytecode files in my "out" directory >> >> src >> - Syncrhonizer.groovy >> >> out >> - Synchronizer.class >> >> [ ** my %JAVA_HOME% points to: >> >> Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-b05) >> Java HotSpot(TM) Client VM (build 1.4.2_09-b05, mixed mode) >> ] >> >> In a command window, I set the current directory to "out". Then I type "java >> -cp %GROOVY_JAR% Synchronizer".... to run the "main()" function in the >> bytecode. >> I get an error: >> "Exception in thread "main" java.lang.NoClassDefFoundError: >> Synchronizer/class" >> Why? >This looks very much like the newbe problem of having typed >java Synchronizer.class >You are sure you haven't done this? Maybe because of autocompletion int >the shell or something alike? >bye blackdrag -- Jochen Theodorou Groovy Tech Lead http://blackdragsview.blogspot.com/ --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

Re: Using Groovy bytecode from java command line

Thomas Burleson
In reply to this post by Jochen Theodorou
No that is not the problem. Here is another example:

TestMain.groovy
------------------------
class TestMain {

  static void main(args) {
            def msg = (args.size() < 1) ? "1+ Arguments needed" : args[0];
                println msg;    
  }

}

compiles to ../out/TestMain.class
runs fine in Eclipse plugin

No open command window.
Cd ../out

java -verbose -cp %JRE_PATH%;%GROOVY_EMBED%\groovy-all.jar; TestMain

get the attached output
TestMain.log
(which does nothing.)
So what gives?


Jochen Theodorou wrote
>>Thomas Burleson schrieb:
>> I have a class Synchronizer.groovy that compiles and runs great with Groovy
>> and GroovySh.
>> I have the bytecode files in my "out" directory
>>
>>     src
>>        - Syncrhonizer.groovy
>>    
>>     out
>>        - Synchronizer.class
>>
>> [    ** my %JAVA_HOME% points to:
>>
>>     Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_09-b05)
>>     Java HotSpot(TM) Client VM (build 1.4.2_09-b05, mixed mode)
>> ]
>>
>> In a command window, I set the current directory to "out". Then I type "java
>> -cp %GROOVY_JAR% Synchronizer".... to run the "main()" function in the
>> bytecode.
>> I get an error:
>>          "Exception in thread "main" java.lang.NoClassDefFoundError:
>> Synchronizer/class"
>> Why?

>This looks very much like the newbe problem of having typed

>java  Synchronizer.class

>You are sure you haven't done this? Maybe because of autocompletion int
>the shell or something alike?

>bye blackdrag

--
Jochen Theodorou
Groovy Tech Lead
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

Re: Using Groovy bytecode from java command line

Jochen Theodorou
Thomas Burleson schrieb:
[...]

try:

  java -cp %GROOVY_EMBED%\groovy-all.jar;. TestMain

bye blackdrag

--
Jochen Theodorou
Groovy Tech Lead
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Using Groovy bytecode from java command line

Thomas Burleson
that command you suggested simply gives me the same output as "java -version"
Honestly this is making me crazy... any other ideas.

(sorry for the stupid question: but did you try TestMain.groovy & TestMain.class on your machine?)

Jochen Theodorou wrote
Thomas Burleson schrieb:
[...]

try:

  java -cp %GROOVY_EMBED%\groovy-all.jar;. TestMain

bye blackdrag

--
Jochen Theodorou
Groovy Tech Lead
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

Re: Using Groovy bytecode from java command line

Jochen Theodorou
Thomas Burleson schrieb:
> that command you suggested simply gives me the same output as "java -version"
> Honestly this is making me crazy... any other ideas.
>
> (sorry for the stupid question: but did you try TestMain.groovy &
> TestMain.class on your machine?)

I have no problems, and if you look in the log you posted you will see
the version information too. I don't think this is a groovy problem at
all, it looks much more like you made a mess of your Java or something
else in your enviroment. But let us go through this step-by-step and we
will find the problem. Do not in any of these cases use eclipse please.
Do it completly from the command line.

1) write a simple hello world in Java, compile it, run it, be happy that
something is still working ;)

HelloWorld.java
public class HelloWorld{
   public static void main(Stirng[] args) {
     System.out.println("Hello World");
   }
}

run it with "java HelloWorld"

2) if that works, then then change the run command to

java -cp %GROOVY_EMBED%\groovy-all.jar;. HelloWorld

even though we include the groovy jar, it won't have an effect. If it
doesn't work then you should check the GROOVY_EMBED variable for whitespace

3) assuming the above works. Write a new HelloWorld in Groovy:

HelloWorld2.groovy:

println "hello from groovy"

run it using the groovy command:

groovy HelloWorld2.groovy

4) if that works, compile it using groovyc and run it using the java
command.

java -cp %GROOVY_EMBED%\groovy-all.jar;. HelloWorld2

And tell me if it all worked.

bye blackdrag

--
Jochen Theodorou
Groovy Tech Lead
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Using Groovy bytecode from java command line

Thomas Burleson
BlackDrag,

Thx for the help. It works great now.
I should always remember to go "back to basics..."

Turns out my javac command could not be found. So my JAVA_HOME, JRE_PATH were not configured properly with my PATH and CLASSPATH variables
Got that fixed. Compiled and ran HelloWorld with no problem.
Then confirmed:

java -cp %JRE_PATH%;%GROOVY_EMBED%\groovy-all.jar;.\CFUnitSynch.jar  com.universalmind.cfml.cfunit.Synchronizer

works!

Jochen Theodorou wrote
Thomas Burleson schrieb:
> that command you suggested simply gives me the same output as "java -version"
> Honestly this is making me crazy... any other ideas.
>
> (sorry for the stupid question: but did you try TestMain.groovy &
> TestMain.class on your machine?)

I have no problems, and if you look in the log you posted you will see
the version information too. I don't think this is a groovy problem at
all, it looks much more like you made a mess of your Java or something
else in your enviroment. But let us go through this step-by-step and we
will find the problem. Do not in any of these cases use eclipse please.
Do it completly from the command line.

1) write a simple hello world in Java, compile it, run it, be happy that
something is still working ;)

HelloWorld.java
public class HelloWorld{
   public static void main(Stirng[] args) {
     System.out.println("Hello World");
   }
}

run it with "java HelloWorld"

2) if that works, then then change the run command to

java -cp %GROOVY_EMBED%\groovy-all.jar;. HelloWorld

even though we include the groovy jar, it won't have an effect. If it
doesn't work then you should check the GROOVY_EMBED variable for whitespace

3) assuming the above works. Write a new HelloWorld in Groovy:

HelloWorld2.groovy:

println "hello from groovy"

run it using the groovy command:

groovy HelloWorld2.groovy

4) if that works, compile it using groovyc and run it using the java
command.

java -cp %GROOVY_EMBED%\groovy-all.jar;. HelloWorld2

And tell me if it all worked.

bye blackdrag

--
Jochen Theodorou
Groovy Tech Lead
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|

Re: Using Groovy bytecode from java command line

Jochen Theodorou
Thomas Burleson schrieb:
> BlackDrag,
>
> Thx for the help. It works great now.
> I should always remember to go "back to basics..."

hehe, yes, sometimes you need to throw all away and start from scratch.
good to hear that it works now!

bye blackdrag

--
Jochen Theodorou
Groovy Tech Lead
http://blackdragsview.blogspot.com/

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email