aspose file tools*
The moose likes Beginning Java and the fly likes java classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java classpath" Watch "java classpath" New topic
Author

java classpath

Judith
Greenhorn

Joined: Jan 11, 2005
Posts: 18
java classpath
Hi all. i am having the same problem as the others who are getting the

"""Exception in thread "main" java.lang.NoClassDefFoundError""
I have read thru and followed as best i could, but i can't get the compilier to do anything.
here's what i have done to try and get this
helloworld program.
1. created a folder on my desktop for just notepad entries.
2. at the command prompt, i type in c:and then the folder but in won't run.
3. i tried using a zip disk, but it won't run either.
4. when i do type in set classpath= it changes nothing 'viewable' that i can see. is this correct.
i hate being new!!! lol
thank you for a great site.
moxyi3
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

Welcome to JavaRanch.

If you have not already, take a look at the FAQ How To Set Your Classpath.

To answer your one question, when you set your classpath with a command such as

you will not see anything visible happen, other then returning to the command prompt. You can check the results by echoing back the value of the classpath environment variable. Do this by typing:


If you are still having problems after reading the above FAQ, post a reply listing your actual path stucture and file names, the exact commands you are typing in, and the exact error you get, and someone can help you.
[ January 11, 2005: Message edited by: Mark Vedder ]
Judith
Greenhorn

Joined: Jan 11, 2005
Posts: 18
G:\> javac App.java
'javac' is not recognized as an internal
command or external command, operable program or batch file.

i tried to run this from a zip disk and then off a folder i created for just text files in notepad.

i can't get it to run.

thanks..
moxyi3
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

The error 'javac' is not recognized as an internal command or external command, operable program or batch file. indicates that Windows cannot find the program javac. This means that your jdk installation is not in the PATH environment variable, or in the current working directory (G:\ in the sample you posted). The PATH variable is the list of directories Windows searches to find a program when you type just its name ('javac' in this case). You can see what directories are in your PATH by typing echo %PATH% at a command prompt.

The easiest way to solve this is to fully qualify the javac command. So if you installed the jdk in C:\java\jdk1.5.0 you would type:

G:\>C:\java\jdk1.5.0\bin\javac App.java

to compile your App class (and this assumes that 'App.java' is stored the directory G:\ since that is your current directory. If not, you need to specify its path as well.

Once it is compiled, you should be able to run it using the java command.

To prevent needing to type in the fully qualified path of the javac each time, you can add the jdk's bin directory to your PATH environment variable; search Windows help for info on doing so. Be careful when doing such though since a typo or mistake can cause a lot of programs to stop working.
[ January 11, 2005: Message edited by: Mark Vedder ]
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

p.s. you can also look at Step 5 of the JDK installation notes: http://java.sun.com/j2se/1.5.0/install-windows.html

The basic instructions are the same regardless of what version of JDK you installed. Just be sure to seperate any directory entries in the path environment variable with a semi-colon (in Windows).

There are also instructions posted here. (Gotta love Google)
Judith
Greenhorn

Joined: Jan 11, 2005
Posts: 18
variable value
-------- -------------------
java C:\Desktop\java notepad



ok,, AM VERY grateful for your help. I understand the pathway, but does it matter what i call the variable??
can i type this?
I didn't know what else to name the variable. so i just put in the name java.
c:\desktop\java notepad is my folder on my desktop for the text editing.
You rock!!
moxyi3
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

I am not sure to what you are referring to when you say "variable" and ask "but does it matter what i call the variable??" You then indicate that you put the name 'java'.

From what I understand of what you are trying to do, you will need to execute some commands. These commands in turn take arguments. But before we go any further, let's go back to the beginning and verify what it is you are trying to accomplish...

It sounds like you wrote a helloworld program and saved it in the directory "C:\Desktop\java notepad". (What did you name your file?) You now want to compile and then run that program. Is that correct?
Judith
Greenhorn

Joined: Jan 11, 2005
Posts: 18
The name of the hello world is App.java.

i have a copy of this both on zip and desktop.
when trying to set the variables, there are system variable and user variables. my example i gave was for a user variable. it asks that you
provide a 'variable name' (that's what the java was for in my example of what to type in), i just gave it any old name) and a varible value.
if i use the run time path at the c prompt, do i then have to save
each and every text file in the exact same place?
(how can you create two paths at the same time?)
i think this is why i am confused..
thanks again.
moxyi3
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
The "variable" name is "PATH". The value is the path to the Java file containing an entry point, eg, the main method of your class.

If you have your class file in the C:\java directory of a Windows machine, you would:

SET PATH="C:\java;."

Then you run your App.class (NOT App.java -- you have to compile the source code before you can run it...)

java App

If you need to compile first, run:

javac App.java

This will create the App.class file.

As for that randomly named environment variable you created, I suggest deleting it.


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

It looks like Jeff answered your question/confusion on variable names and values. To answer your question

if i use the run time path at the c prompt, do i then have to save
each and every text file in the exact same place?
(how can you create two paths at the same time?)


No, you do not have to save all your files in the same place. You can only set one PATH variable and one CLASSPATH variable, but the value of those variables can contain a list of directories to search. The list needs to be seperated by a semicolon (in windows). So you can enter the command:

set PATH=C:\jdk1.5.0\bin;C:\dev;C:\myFiles\javaStuff;C:\Temp

Now your PATH variable has four directories in it, each of which will be searched (in the order listed) for any execuable (such as java or javac).

Likewise the CLASSPATH variable can contain multiple directories, which are then searched for files when compilying or running a program.

set CLASSPATH=C:\dev;C:\foo;G:\
[ January 11, 2005: Message edited by: Mark Vedder ]
Judith
Greenhorn

Joined: Jan 11, 2005
Posts: 18
Thank you SOOOOOOOOOOOO
MUCH!!
can you guys fix my car too??
jk
thank you for your time and brains.
moxyi3
Judith
Greenhorn

Joined: Jan 11, 2005
Posts: 18
I have tried ALL of what you have said, but i can't anything do anything.
i checked all your help 5 times and etc..i understand what you want me to do, but no matter how i type it in, nothing will work at the c:\ prompt.
i am afraid now that i may have set the SYSTEM wrong and am afraid to re-boot. very sorry for all the hassle. all i get at the c: prompt is
this C:\Documents and Settings\ etc
i can never just C:\ ..etc..

This is the I typed in the SYSTEM part.
C:\JDK.1.4.2\bin;C:\documents and settings\judith\desktop\java notepad;C:\Temp
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
At the command prompt, type "cd .." and press enter. That will take you up one level. Repeat until you only see "C:\"...

Then try your other commands. Remember, the PATH needs to point to the directory containing the SDK's bin directory. I always point directly to the bin directory itself.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
It looks like this saga is continued over here.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Judith
Greenhorn

Joined: Jan 11, 2005
Posts: 18
I don't understand your link to my orginal post.
If you do want me asking, just say so.
moxyi3
Judith
Greenhorn

Joined: Jan 11, 2005
Posts: 18
it keeps telling me
it is not recognized or not an internal command.
i have even typed 'javac' after bin, but nothing happens that

way either.

I have actually put the text file of the application that
i want to compile right in with the javac files.

???
I can get to C:\Temp\Sun\AppServer\Bin at the dos prompt,
but nothing with javac.


I have CLASSPATH listed as the title of each of these.

User Variable is listed as:
C:\Temp\Sun\AppServer\Bin;


System Variable is listed as this:

C:\Temp\Sun\AppServer\Bin;C:\Documents and Settings\My Name
I have rebooted 3 times.
I went to the site you listed and did as it explained.
Thank you for bearing with me.
moxyi3
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
It looks like you have posted this question twice. Please do not do this. It causes much confusion and wastes time when people try to answer your question. This is why Barry gave a link to your other post. Please see my answer there. Hopefully it will help clear some of the confusion.

Layne


Java API Documentation
The Java Tutorial
Judith
Greenhorn

Joined: Jan 11, 2005
Posts: 18
i have explained that i have tried to set the variables.
so, i still don't get it, and i have tried everything.
i have set a PATH and a CLASSPATH..
simple as this may be to you, i can't get it to work.
i have the paths going right straight to where the program is.
i have no idea what i am doing wrong.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Just to clarify, can you please show us what the value of the PATH variable? Also, tell us what directory you used to install the JDK. At the moment you don't need CLASSPATH, so get rid of it.

Layne
Judith
Greenhorn

Joined: Jan 11, 2005
Posts: 18
Under SYSTEM VARIABLES:
VARIABLE: CLASSPATH
VALUE : C:\Temp\Sun\AppServer\Bin;
i also have
Variable
PATH
VARIABLE VALUE C:\Temp\Sun\AppServer\Bin;
___________________________________________________
FOR user variable
i have only CLASSPATH
value C:\Temp\Sun\AppServer\Bin

i will get rid of the classpath as you have stated.
thank you.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Okay, now you need to find which directory contains the javac.exe and java.exe programs. Then change the PATH variable to contain this directory. I don't think you need to use C:\Temp\Sun\AppServer\Bin in the PATH at all unless it is the directory that contains these two programs.

Layne
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9043
    
  10
Hi, Judith

Welcome to JavaRanch! Please adjust your display name to meet the JavaRanch Naming Policy.
You can change it here.

Thanks!


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java classpath
 
Similar Threads
Displaying * in contrast to individual classes in imports
Netbeans Experts...
Oracle JPublisher command line
I can't run my first program on command line
Run jar file