Re: How to include *.class file with package in CLASSPATH?



Lion-O wrote:
On 2008-04-26, Ulf Meinhardt <ulf2m@xxxxxxxxx> wrote:

D:\java\output\aaa\bbb\ccc\myclass.class

myclass.java contains the following package information:

package aaa.bbb.ccc;

The current path in the command prompt is

D:\java>

---<CUT

But when I enter a statement like:

javac -cp D:\java\output\aaa\bbb\ccc;%CLASSPATH% test.java

then the compiler complains that he cannot find myclass:

Try just compiling without setting any classpath, or, if your classpath
contains specific settings try: javac -cp .;%CLASSPATH test.java

Arne gave the correct answer, which this wasn't. He also suggested to follow the coding conventions, which have us use upper-case letters to begin class names (and lower-case ones to begin variable and method names), and camel case thereafter.

Additionally, having the word "class" in a class name is silly.

CLASSPATH is a blunt tool. Normally one shouldn't use it, at least not much. Use the -cp option completely.

To run Test (correcting the class name), and assuming a dependency on MyExample in package aaa.bbb.ccc (directory d:\java\output\aaa\bbb\ccc\) and Test in package xxx.yyy.zzz, and the current working directory d:\work\,

java -cp D:\java\output xxx.yyy.zzz.Test

Of course, Test.java will start off with these directives:

package xxx.yyy.zzz;
import aaa.bbb.ccc.MyExample;

--
Lew
.



Relevant Pages

  • Re: Dealing with packages UNIX
    ... Everything has the same package name in teh same directory. ... ALso when my web app runs it is using an older version of the class file taht wont compile even afer I did a rm *.class and replaced them with the javac *.java. ... javac needs a defined sourcepath to work. ...
    (comp.lang.java.programmer)
  • Re: How to include *.class file with package in CLASSPATH?
    ... myclass.java contains the following package information: ... then the compiler complains that he cannot find myclass: ... Try just compiling without setting any classpath, or, if your classpath ... contains specific settings try: javac -cp .;%CLASSPATH test.java ...
    (comp.lang.java.help)
  • Re: java packages
    ... Using the following to compile manually. ... javac -classpath %PROD_CLASSPATH% CSDSMsg.java javac -classpath %PROD_CLASSPATH% DBS.java javac -classpath %PROD_CLASSPATH% RunDBS.java javac -classpath %PROD_CLASSPATH% XSS.java ... Common Java package name nomenclature is to use all ... The source and class files are to all be in same directory DBS_Intercept ...
    (comp.lang.java.programmer)
  • Re: package junit.framework does not exist
    ... not find the junit package. ... From Eclipse, the project compile fine, but from the command line, I ... I have included junit.jar in the classpath, ...
    (comp.lang.java.programmer)
  • Re: If . is in classpath doesnt that pull in classes in the current folder?
    ... I have seen the package stuff in action in a different example from "Thining in Java" so I understand it a little better now. ... >> compiled MIMEType.java that a folder standalone was not made. ... the -d option to javac will tell the compiler where to put the ...
    (comp.lang.java.help)