• Post Reply Bookmark Topic Watch Topic
  • New Topic

Class Path Woes  RSS feed

 
P Moran
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdie folks,

Sure this is easy and am being thick but bare with me, I am just having a play with Googles protocol buffers examples

So I have created a Java project which lives in ~<USER>/workspace/protocol

In it is AddPerson.java, the file reference a library

com/example/tutorial/AddressBookProtos.java which is in this folder

and also uses the jar which is in
~<USER>/javalib (its called /protobuf-java-2.0.2.jar )

My CLASSPATH=..:.:/~<USER>/javalib/

However when I cd to the ~<USER>/workspace/protocol directory and I run
./javac AddPerson.java it gives me the errors

javac AddPerson.java
AddPerson.java:15: cannot access com.google.protobuf.GeneratedMessage
file com/google/protobuf/GeneratedMessage.class not found
Person.Builder person = Person.newBuilder();
^
AddPerson.java:18: cannot access com.google.protobuf.GeneratedMessage$Builder
file com/google/protobuf/GeneratedMessage$Builder.class not found
person.setId(Integer.valueOf(stdin.readLine()));



Could you put me out my misery ? am I missing the point about the CLASSPATH ? should the fact it references ., .. and the library folder containing my jars not be enough?
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you need the / before the ~<USER> in your classpath ? Doesn't ~<USER> include the leading / when it is interpreted ?
[ November 18, 2008: Message edited by: Joanne Neal ]
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think an additional / doesn't harm you..

To use classes in a jar you need to have an entry in the classpath pointing to the .jar file itself not just the directory containing it.

But since JSE 6 you can use wildcards.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gamini Sirisena:
I think an additional / doesn't harm you..

Yes, it does. If I try:

cd /~jesper

on my Ubuntu computer, it says it can't find the directory. So, remove the / before the ~ in your CLASSPATH.
 
Gamini Sirisena
Ranch Hand
Posts: 378
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper,
You are right, that tilde didn't register..
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!