[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 377
  • Last Modified:

Javacc run error

Hi i have started using javacc
I have compliled the simple1.jj file using javacc and it built everything successfully, when i javac everything they alll seem to compile.
But then when i java Simple1
it says..... can anybody help me fix this. I'am usinsing LINUX suse 11.0 ... but had the same problem in windows

Exception in thread "main" java.lang.NoClassDefFoundError: Simple1
Caused by: java.lang.ClassNotFoundException: Simple1
      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
0
pablo25
Asked:
pablo25
  • 6
  • 4
1 Solution
 
szigetiCommented:
Hi, try this:

java -classpath . Simple1

You need to add the current directory to the classpath.
0
 
szigetiCommented:
Or if the file is in a package, e.g. /use/some/package/Simple1.class, then go to /user and run it from there:

java -classpath . some.package.Simple1    (notice the "." indicating current directory).
0
 
pablo25Author Commented:
no thants not working i have java installed trough yast on suse
I tried those commands and to no avail.
the file is at my home directory as is the command and the java commands java javac javacc all work at this llocation
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
szigetiCommented:
Do you mean the java command is not working? if java is not on your path, then you have to use the commands with absolute path, e.g.:

Assume file is in:
/home/user/Simple1.class

Then:

cd /home/user
/usr/java/bin/java -classpath . Simple1
0
 
szigetiCommented:
type this to find out where java is located:

which java
0
 
pablo25Author Commented:
its at /usr/bin/java
0
 
pablo25Author Commented:

Thi sis what i got

linux-mzqf:/home # /usr/bin/java -classpath . Simple1
Exception in thread "main" java.lang.NoClassDefFoundError: Simple1
Caused by: java.lang.ClassNotFoundException: Simple1
      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
linux-mzqf:/home #

0
 
szigetiCommented:
Ok, then the class Simple1 must be in a package.

1. Open the Simple1.java source, look for the package x.y.z; declaration
2. Go to where your file is. If the file is already under /home/x/y/z/Simple1.class, then proceed to step 4
3. Create /home/x/y/z, move Simple1.class to /home/x/y/z
4. Go to /home
5. /usr/bin/java -classpath . x.y.z.Simple1

* Please make sure to substitite "x.y.z" and directories "x/y/z" with the package name you found in the source!
0
 
szigetiCommented:
Btw. if you don't see Simple1.class *anywhere*, then your build was not successful.
0
 
pablo25Author Commented:
Thanks!!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now