File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Classpath different behaviour in java and javac

 
timo corn
Ranch Hand
Posts: 68
MyEclipse IDE PHP Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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?
 
Henry Wong
author
Marshal
Pie
Posts: 20829
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
timo corn
Ranch Hand
Posts: 68
MyEclipse IDE PHP Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20829
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic