• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help getting javac/java commands working

 
Ranch Hand
Posts: 54
C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I've been programming and in school for it for quite awhile, but have never ran code from a terminal.

I added the environment variable which points to the JRE \bin directory. The javac and java commands are recognized. My problem is in running the .class file. When doing so, I receive this terrifying error:

C:\Users\troberts\Documents\Java Projects>java ProjectThree
Exception in thread "main" java.lang.NoClassDefFoundError: ProjectThree (wrong n
ame: projectthree/ProjectThree)
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$100(Unknown Source)
at java.net.URLClassLoader$1.run(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 sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)

I've done some google research and found that some additional environment variables may need to be added... but when I did that, the result doesn't change. There were some additional comments about adding the dot opr at the end, but that didn't seem to work for me either.

Please help.. this is an annoying problem for me to have.
 
Ranch Hand
Posts: 859
IBM DB2 Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the name of your Java file? ProjectThree.java or projectthree.java
What is the package name and what is the name of the folder?

WP
 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems that you did not use the fully qualified name of that class. Do you have the ProjectThree java file in a package called projectthree? If so, you should use the package name when trying to run your file. See here, under "Setting up the CLASSPATH" to understand how this works:
http://www.jarticles.com/package/package_eng.html
 
Travis Roberts
Ranch Hand
Posts: 54
C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello again,

I am not sure where projectthree is coming from.

My project sits in a folder called Java Projects and it contains:

Directory of c:\Users\troberts\Documents\Java Projects

05/02/2012 02:38 PM <DIR> .
05/02/2012 02:38 PM <DIR> ..
05/02/2012 12:32 PM 472 ProjectOne.class
05/02/2012 12:42 PM 249 ProjectOne.java
05/02/2012 02:26 PM 443 ProjectThree.class
05/02/2012 02:25 PM 322 ProjectThree.java
05/02/2012 12:56 PM 418 ProjectTwo.class
05/02/2012 12:55 PM 347 ProjectTwo.java
05/02/2012 02:39 PM <DIR> Test
6 File(s) 2,251 bytes
3 Dir(s) 194,949,726,208 bytes free

projectthree apparently exists only in the terminals mind. When I run java ProjectThree, I get that error. Same with the other projects...

Thanks for that link. I learned something reading about the fully qualified names and using the dot operator there, but that's not the issue I'm having; this is only a hello world program.

Whats interesting is I got it to work running it from the root of my documents. Does the IDE do anything that can mess this up?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Travis Roberts wrote:Hello again,

I am not sure where projectthree is coming from.

My project sits in a folder called Java Projects and it contains:

Directory of c:\Users\troberts\Documents\Java Projects

05/02/2012 02:38 PM <DIR> .
05/02/2012 02:38 PM <DIR> ..
05/02/2012 12:32 PM 472 ProjectOne.class
05/02/2012 12:42 PM 249 ProjectOne.java
05/02/2012 02:26 PM 443 ProjectThree.class
05/02/2012 02:25 PM 322 ProjectThree.java
05/02/2012 12:56 PM 418 ProjectTwo.class
05/02/2012 12:55 PM 347 ProjectTwo.java
05/02/2012 02:39 PM <DIR> Test
6 File(s) 2,251 bytes
3 Dir(s) 194,949,726,208 bytes free

projectthree apparently exists only in the terminals mind. When I run java ProjectThree, I get that error. Same with the other projects...

Thanks for that link. I learned something reading about the fully qualified names and using the dot operator there, but that's not the issue I'm having; this is only a hello world program.

Whats interesting is I got it to work running it from the root of my documents. Does the IDE do anything that can mess this up?




"projectthree" is the package name -- take a look at your source to see if you defined the class in a package. An IDE takes care of everything for you in this regard -- if you define a class in a package, it will automatically put it into a directory structure for you. Without an IDE, it is your responsibility to keep these in sync.

Henry

 
Travis Roberts
Ranch Hand
Posts: 54
C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm still lost. I can be stubbornly dim-witted sometimes.

The problem is isolated to just code in packages.

Fortunately, I've unearthed my Sybex SCJP book and it discusses this at length. I will give it a good read.

Thanks to all for the guidance.
 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henry Wong wrote:"projectthree" is the package name -- take a look at your source to see if you defined the class in a package.


Did you check the source code for package declaration as Henry suggested. Can you show us the code?
 
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Travis Roberts wrote:Hello again,

I am not sure where projectthree is coming from.

My project sits in a folder called Java Projects and it contains:

Directory of c:\Users\troberts\Documents\Java Projects

05/02/2012 02:38 PM <DIR> .
05/02/2012 02:38 PM <DIR> ..
05/02/2012 12:32 PM 472 ProjectOne.class
05/02/2012 12:42 PM 249 ProjectOne.java
05/02/2012 02:26 PM 443 ProjectThree.class
05/02/2012 02:25 PM 322 ProjectThree.java
05/02/2012 12:56 PM 418 ProjectTwo.class
05/02/2012 12:55 PM 347 ProjectTwo.java
05/02/2012 02:39 PM <DIR> Test
6 File(s) 2,251 bytes
3 Dir(s) 194,949,726,208 bytes free

projectthree apparently exists only in the terminals mind. When I run java ProjectThree, I get that error. Same with the other projects...

Thanks for that link. I learned something reading about the fully qualified names and using the dot operator there, but that's not the issue I'm having; this is only a hello world program.

Whats interesting is I got it to work running it from the root of my documents. Does the IDE do anything that can mess this up?



You are running this from the IDE then? If you are, instead go to c:\Users\troberts\Documents\Java Projects and do the following:

c:\Users\troberts\Documents\Java Projects>java ProjectThree

... if that does not work, try this:

c:\Users\troberts\Documents\Java Projects>java -cp . ProjectThree

If that still does not work, as mentioned, please post the ProjectThree.java file.

If though it does work, then tell us how you are executing the file from within the IDE.
 
Travis Roberts
Ranch Hand
Posts: 54
C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the code:



When I go all the way to the .class file

C:\Users\troberts\Documents\Java Projects\ProjectThree\build\classes\projectthree>java ProjectThree

I get:

Error: Could not find or load main class ProjectThree

C:\Users\troberts\Documents\Java Projects\ProjectThree\build\classes\projectthree>java projectthree.ProjectThree
Error: Could not find or load main class projectthree.ProjectThree

C:\Users\troberts\Documents\Java Projects\ProjectThree\build\classes\projectthree>java projectthree\ProjectThree
Error: Could not find or load main class projectthree\ProjectThree


These results are the same when I use CLASSPATH=C:\Users\troberts\Documents\Java Projects\ProjectThree

The command with the -cp options doesn't seem to work either.

Man... I'm having a harder time with Java than I did with Assembler so far. I can't even get Java to run!



 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure that classpath is correct? I thought that you used DocumentsAndSettings or Documents%20And%20Settings on Windows®, rather than users. Also check the spelling of project three. You have capital letters in what you quoted, but the package name is (as it ought to be) in lower-case throughout.
 
Travis Roberts
Ranch Hand
Posts: 54
C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The path is correct.

The lower case is the package. The second ProjectThree is the .class file I am trying to make run.

 
Bill Johnston
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Travis Roberts wrote:The path is correct.

The lower case is the package. The second ProjectThree is the .class file I am trying to make run.



Then it is just as Henry suggested above. back up to:

C:\Users\troberts\Documents\Java Projects\ProjectThree\build\classes

and run as this:

C:\Users\troberts\Documents\Java Projects\ProjectThree\build\classes>java -cp . projectthree.ProjectThree
 
Travis Roberts
Ranch Hand
Posts: 54
C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This works at home!

The issue is probably with my system at work or perhaps the java install.

Thanks for all the help offered. Onward to the Cattle Drive, then.
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic