• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Classpath Related Problem

 
Greenhorn
Posts: 2
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tes/xcom folder is having 3 things :

A.java ; A.class ; B.java

------A.java

package xcom;
public class A{}

-------B.java
paclage xcom;
public class B extends A{}


now this thing works if you are in test folder
javac -classpath . xcom/B.java

i modified a bit
javac -classpath xcom/A.class xcom/B.java
this doesn't work
why???
 
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Each classpath should end with a filename or directory depending on what you are setting the class path to:
For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.
For .class files in an unnamed package, the class path ends with the directory that contains the .class files.
For .class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name).




http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html
 
Ranch Hand
Posts: 125
Scala Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jigar Rathod wrote:tes/xcom folder is having 3 things :

A.java ; A.class ; B.java

------A.java

package xcom;
public class A{}

-------B.java
paclage xcom;
public class B extends A{}


now this thing works if you are in test folder
javac -classpath . xcom/B.java

i modified a bit
javac -classpath xcom/A.class xcom/B.java
this doesn't work
why???



Because the classpath should point to the place where A.class is located. In the above example javac -cp . xcom/B.java should be invoked from tes directory and .(dot) here specifies to look up for any needed classes in the current directory. A.class is not located at xcom/A.class but is located in tes/xcom.

You have to specify the classpath for the class and not the class itself.
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic