Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Bug:GhostsFoundInClasspath

 
jyothi abraham
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please somebody explain to me on classpath on following:
1)I have following files;
i)C:\folder1\com\Class1.java
ii)C:\folder2\com\Class2.java
(Class2 extends from Class1)
iii)C:\folder3\org\Class3.java
2)Class3 file contains following lines;
package org;
import com.Class2;
class Class3{
public static void main(String args]{
}}
When I am compiling from C:\folder3\org>:
----------------------------------------
javac -classpath %path;C:\folder2 Class3.java,it
compiles fine.
a)when I am running from same directory
java Class3
it produces an error:NoClassDefintionFound
but when I comment out package line it works
fine.How?
b)javac -classpath %path;C:\folder1;C:\folder2;
C:\folder3 Class2.java produces an error,can't
read Class2.java.Why it happens while
import com.Class2; statement of Class3 in the same directory compiles without a problem?
In all, what modifications I have to make to compile and run in same directory.It now appears
to me like a ghost story
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this to Java in General (Beginner).
Corey
 
timothy zimmerman
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure I am correct but I think you may have better luck if you redirect the output of the compile to a common directory using the javac -d option.
example:
javac -d c:\build\classes c:\folder1\com\*.java c:\folder2\com\*.java c:\folder3\org\*.java
Then to execute:
java -classpath c:\build\classes;%CLASSPATH% org.Class3
The advantage of having a common build area (ie build/classes) is that you can put that directory in your classpath and the package structure will be built up from that (ie build/classes/com build/classes/org).
to address what I can in your post
a)java Class3 does not provide a CLASPSATH so you must have the directory containing your compiled package for Class2 in your environment
b) not sure I entirely understand but if you provide more detail I will try again.
Hope this was helpful
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DO
java org.Class3 in u C:\folder3\org\ directory.
[ removed quote -ds ]
[ June 13, 2002: Message edited by: Dirk Schreckmann ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic