my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Classpath different behaviour in java and javac Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Classpath different behaviour in java and javac" Watch "Classpath different behaviour in java and javac" New topic
Author

Classpath different behaviour in java and javac

timo corn
Ranch Hand

Joined: Oct 26, 2013
Posts: 68



Current Dir. is "test". I read in the kb book (page 829 ) that the java -classpath does not include the test dir. but the javac -classpath does. Does it make sense?? Can you explain if there is a diff. in cp between java and javac invocation? I thought there is no difference in using -cp in java or javac?


hth
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18848
    
  40

timo corn wrote:

Current Dir. is "test". I read in the kb book (page 829 ) that the java -classpath does not include the test dir. but the javac -classpath does. Does it make sense?? Can you explain if there is a diff. in cp between java and javac invocation? I thought there is no difference in using -cp in java or javac?



What do you mean by no difference? These are two different commands, and hence, have needs to get classes for different reasons. The compiler just needs it to obtain the class definitions for the classes that the file that it is compiling is using. If it can't find some classes, it may trigger addition compilations. The JVM actually runs the code. It needs everything that will be executed. Not just the classes that the GetJar class uses, but what those classes needs as well -- everything that is used.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
timo corn
Ranch Hand

Joined: Oct 26, 2013
Posts: 68

ok, so I tried it with the test Nr. 11, kb book, chapter 10:
c:/users/tk -|
|- getJar.java

|- myApp-|
|-Foo.java

the current directory is "tk", and myApp/Foo.class is placed in a JAR file called myJar.jar
located in <tk>

And given the contents of GetJar.java and Foo.java:


c:\Users\tk>javac -cp myJar.jar getJar.java


The result:
myJar.jar(myApp/Foo.java):1: error: illegal character: \187
´╗┐package myApp;
^
myJar.jar(myApp/Foo.java):1: error: illegal character: \191
´╗┐package myApp;
^
getJar.java:4: error: cannot access Foo
System.out.println(myApp.Foo.d);
^
bad source file: myJar.jar(myApp/Foo.java)
file does not contain class myApp.Foo
Please remove or make sure it appears in the correct subdirectory of the sourcepa
th.
3 errors

Any help?

EDIT: I did not compile Foo.java, my fault, because in order to get a jar file I need class files. When I do compile it, I get the special rotten chars ´╗┐
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18848
    
  40

timo corn wrote:
EDIT: I did not compile Foo.java, my fault, because in order to get a jar file I need class files. When I do compile it, I get the special rotten chars ´╗┐



What editor are you using? The compiler is complaining that it encountered non-ASCII characters -- which generally occurs when you save the file in a format that is something other than a text file format.

Henry
 
jQuery in Action, 2nd edition
 
subject: Classpath different behaviour in java and javac