• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please Help. cannot compile Assertions

 
Ayanik Sil
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanks Smith,the problem is sorted out.
 
Ayanik Sil
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanks Smith,the problem is sorted out.
Meanwhile,i use XP,not Unix
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ayanik Sil:
hey thanks Smith,the problem is sorted out.


Glad to hear it Sil.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic