This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Please Help. cannot compile Assertions 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 "Please Help. cannot compile Assertions" Watch "Please Help. cannot compile Assertions" New topic
Author

Please Help. cannot compile Assertions

Ayanik Sil
Greenhorn

Joined: Sep 23, 2007
Posts: 27
Hi friends,
I have tomcat installed.when i gave the command echo %classpath%
the following was the output:


";C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\commons-el.j
ar;C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\jasper-runt
ime.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\naming
-factory-dbcp.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\
lib\jasper-compiler.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.5\c
ommon\lib\jsp-api.jar;C:\Program Files\Apache Software Foundation\Tomcat 5.5\com
mon\lib\naming-resources.jar;C:\Program Files\Apache Software Foundation\Tomcat
5.5\common\lib\jasper-compiler-jdt.jar;C:\Program Files\Apache Software Foundati
on\Tomcat 5.5\common\lib\naming-factory.jar;C:\Program Files\Apache Software Fou
ndation\Tomcat 5.5\common\lib\servlet-api.jar;"

now,when i am running assertions for simple java practice,

the compilier cannot find the class if i am in a directory other than the
where the class file resides.
It gives
Exception in thread "main" java.lang.NoClassDefFoundError: Assertions
where Assertions.class in the name of my class file

now, i cannot delete the class path as Tomcat needs practice.
I am using J2SE 5.0 and windows xp.
what can be done?

My program is as follows:
package MyProjects.javaPrograms;
public class Assertions {

public static void main(String args[]) {
Assertions a=new Assertions();
a.calcSpeed(12,3);
a.calcSpeed(12,-4);
a.calcSpeed(-60,3);

}
public void calcSpeed(int dis,int t) {
assert dis>=0;
assert t>=0:"Time cannot be negative"+t;
int speed=dis/t;
assert speed>=0;
System.out.println("Speed is "+speed);
}
}
I am trying to run the program from
MyProjects directory

where the directory hiearchy is
C:/MyProjects/javaPrograms
and Assertions.java is in javaPrograms directory
[ September 23, 2007: Message edited by: Ayanik Sil ]
Red Smith
Ranch Hand

Joined: Aug 05, 2007
Posts: 136
    
    1
I tried this on Unix and in order for it to run I had to add the package name to the class name on the command line (also the path to the directory containing MyProjects - C:\ in your case - should be in the CLASSPATH):

java MyProjects/javaPrograms/Assertions

or without setting CLASSPATH this should work

java -classpath C:\ MyProjects/javaPrograms/Assertions
[ September 23, 2007: Message edited by: Red Smith ]
Ayanik Sil
Greenhorn

Joined: Sep 23, 2007
Posts: 27
hey thanks Smith,the problem is sorted out.
Ayanik Sil
Greenhorn

Joined: Sep 23, 2007
Posts: 27
hey thanks Smith,the problem is sorted out.
Meanwhile,i use XP,not Unix
Red Smith
Ranch Hand

Joined: Aug 05, 2007
Posts: 136
    
    1
Originally posted by Ayanik Sil:
hey thanks Smith,the problem is sorted out.


Glad to hear it Sil.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please Help. cannot compile Assertions
 
Similar Threads
What is the classpath for Tomcat 5.5?
What is the classpath for Tomcat 5.5?
please help! classpath not working
Need help in compiling programs
Compilation problem in servlets