This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Setting up Java Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Setting up Java Problem" Watch "Setting up Java Problem" New topic
Author

Setting up Java Problem

Nikhil Nagrani
Greenhorn

Joined: Dec 23, 2010
Posts: 24
ENVIRONMENT VARIABLES:-
UserVariables:-
ClassPath=C:\Program Files\Java\jdk1.6.0_22\bin;.\

Path=C:\Program Files\Java\jdk1.6.0_22\bin;.\

System Variables:-
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_22\bin

Path= ;C:\Program Files\Java\jdk1.6.0_22\bin;=%JAVA_HOME%\bin


These are the environment variables which i set while configuring java.

javac is running...i am able to run the programs within the same package.But when i access a class of a different package.I am getting the following error:-

(Here AccessClass and OtherClass are in different package and i have kept the access modifier issues in mind)

Please guide me regarding the significance of above system and user variables(why they are used etc) and are the values in those correct and why this error is coming?

Thanks..

Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

This should be useful: HowToSetTheClasspath

System Variables- Available For all the users.
User Variables- Available For the specific user for whom the variables have been defined. In my opinion its enough to use either of them. Dont try to mix both of them as it might lead to some problems. (There was a post few days back where the user was mixing the System and user variables and thereby facing some issues).


Mohamed Sanaulla | My Blog
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38039
    
  22
I think you ought to delete that classpath altogether, and your path appears correct. I read somewhere it is a security hazard to have . in your PATH.

You need to find which folder that OtherClass file is in. How did you import it?
Nikhil Nagrani
Greenhorn

Joined: Dec 23, 2010
Posts: 24
@Mohamed Sanaulla & Campbell Ritchie

Thanks for the reply guys. I saw the hyperlink(Mohamed Sanaulla ).But it hasn't solve the problem.

I have tried deleting the classpath variable and again creating the new variable.But it didn't work.I am using command prompt and not an IDE.(Campbell).

Now it's showing ClassDefNotFound Error.

Hey guys please let me know what all variables i need to make in the User Variable Section and what in System variable section.I am a bit confused regarding the same. I have deleted the previous ones in both the types.

Thanks.


Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Nikhil Nagrani wrote:I have tried deleting the classpath variable and again creating the new variable.But it didn't work.I am using command prompt and not an IDE.(Campbell).

Now it's showing ClassDefNotFound Error.

Delete the CLASSPATH variable completely. Do not create it again after deleting it.

Note that Java doesn't need the JAVA_HOME variable. Some other programs do, and they expect it to be set to the JDK or JRE installation directory, not to the bin directory of the JDK. If you want to set JAVA_HOME, set it to C:\Program Files\Java\jdk1.6.0_22 and not to C:\Program Files\Java\jdk1.6.0_22\bin


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38039
    
  22
Yes, Jesper is correct. Delete the classpath altogether. Also: which folder or directory is the OtherClass.class file in?
The error you are suffering suggests it is not a PATH problem, but do you really have = in your PATH? Remove that =.
Nikhil Nagrani
Greenhorn

Joined: Dec 23, 2010
Posts: 24
@Campbell

Thanks for the reply.I don't have any = in my Path variable.

C:\java_prac\certification\OtherClass.java
C:\java_prac\somethingElse\AccessClass.java

Now i am trying to compile the main class which is AccessClass.And it's showing ClassDefNotFound Error.

@All

Considering that i haven't made any user or system variables before and configuring it first time only.

Then what all variables i need to make for the two categories(both user and system)?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38039
    
  22
If you are getting that error, you do not have a problem with your user or system environment variables.

What is the package declaration in those two classes? Have you compiled OtherClass.java first? If you compile AccessClass before OtherClass, it won't compile OtherClass, but will give a ClassNotFoundException.

And about the =: read this, so you don't suffer similar errors in future.
 
 
subject: Setting up Java Problem
 
Similar Threads
Java environment variable and path setting
JAVA_HOME should point to a JDK not a JRE
Error while trying to run Tomcat for servlets
Use different JDK versions
Exception in thread "main" java.lang.NoClassDefFoundError: MyFirstApp. Please help basic issue