wood burning stoves*
The moose likes Beginning Java and the fly likes Problem with setting classpath 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 "Problem with setting classpath" Watch "Problem with setting classpath" New topic

Problem with setting classpath

Jayanth Mathavan

Joined: Nov 10, 2005
Posts: 16
Hi all,
I have a very basic doubt with regards to setting the class path for a java program.The Java program and class file is located in below mentioned directory.

The above java program has the package declaration,
package com.aol.ch;

From another directory(D:\test\) I set path as mentioned below,
>>set PATH=C:\Sun\SDK\jdk\bin;.;%PATH%
>>set CLASSPATH=%CLASSPATH%;D:\Workspace\FileHandling\com\aol\ch

and i run the java class file from the directory(D:\test\),I run using the below mentioned command.

>>java FilesEdit

and I get the below errors,

Exception in thread "main" java.lang.NoClassDefFoundError: FeedsEdit (wrong name
: com/aol/ch/FeedsEdit)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:12
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
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)

I don't know what mistake am making but everything looks fine. Can someone please help me out?

Jayanth Mathavan
Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 418
Please set classpath by doing :

set CLASSPATH=D:\Workspace\FileHandling;%CLASSPATH%

and run your file by doing :

java com.aol.ch.FilesEdit
marc weber

Joined: Aug 31, 2004
Posts: 11343

The reason is that after compiling with this package declaration, your class file's qualified name will be com.aol.ch.FilesEdit (not just "FilesEdit"), and this is found under the FileHandling directory (not the "ch" directory).

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
It is sorta covered in the JavaRanch Style Guide.
subject: Problem with setting classpath
Similar Threads
running java program out of workspace
Difficulty in executing
classpath trouble
Basic CLASSPATH problem on Mac OS X