aspose file tools*
The moose likes Java in General and the fly likes Running Javaflow Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Running Javaflow" Watch "Running Javaflow" New topic
Author

Running Javaflow

puff li
Greenhorn

Joined: Jul 28, 2010
Posts: 22
Hi Everyone,

I am writing a model checker and need to store and restore state of programs. After googling, I found Apache Javaflow appears to be a neat tool to do it. However, I got problem running it. Can someone kindly help?

I download the commons-javaflow-2006.jar and asm-3.3.jar and try to test it with the example on Apache: http://commons.apache.org/sandbox/javaflow/tutorial.html
This is the code:



I write build.xml like this:



Below is the output:


Buildfile: build.xml

clean:

build:
[javac] Compiling 1 source file to /home/lihao/Desktop/JavaflowTest/class
[javaflow] Rewriting /home/lihao/Desktop/JavaflowTest/class/MyRunnable.class

run:
[java] Exception in thread "main" java.lang.NoClassDefFoundError: MyRunnable
[java] Caused by: java.lang.ClassNotFoundException: MyRunnable
[java] at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
[java] at java.security.AccessController.doPrivileged(Native Method)
[java] at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
[java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
[java] at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
[java] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
[java] Could not find the main class: MyRunnable. Program will exit.
[java] Java Result: 1

BUILD SUCCESSFUL
Total time: 1 second

And the compilation seems fine. But when running, it turns out "Could not find the main class".
We I run the instrumented Myrunnable.class from commandline, it report error like this:


Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/javaflow/bytecode/Continuable
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.javaflow.bytecode.Continuable
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
... 12 more
Could not find the main class: MyRunnable. Program will exit.


I don't understand why. I have included every possible lib in my classpath. Please help!

Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
How did you set the CLASSPATH?
puff li
Greenhorn

Joined: Jul 28, 2010
Posts: 22
Campbell Ritchie wrote:How did you set the CLASSPATH?


Thanks for reply~

In build.xml:





Is it right?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'd assume the classname needs to be fully qualified.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
And does your classpath still include the . for current directory? If you are putting your compiled files into the "class" directory, is that in the classpath?
puff li
Greenhorn

Joined: Jul 28, 2010
Posts: 22
David Newton wrote:I'd assume the classname needs to be fully qualified.


What do you mean by fully qualified?
puff li
Greenhorn

Joined: Jul 28, 2010
Posts: 22
Campbell Ritchie wrote:And does your classpath still include the . for current directory? If you are putting your compiled files into the "class" directory, is that in the classpath?


Wow, it works when I add "class" directory in the classpath!

Thank you so much Campbell!!! Thank you David as well!!! I spent a whole day yesterday working on it!

So can you explain why I have to add "class" directory in the classpath. It just contains one compiled file. I specified to run it as main class in



why should I add it again? I suppose classpath means where needed libraries are located?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
The classpath variable tells the JVM where to look for .class files. If you have your .class files in the "class" directory, you have to instruct it to try there for .class files.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running Javaflow
 
Similar Threads
Glassfish from myeclipse is throwing exception
How to change the CLASSPATH in Linux?
java oracle conectivity
Cant connect to oracle.
Problem with com.mysql.jdbc.Driver driver