Blog : Including jars in classpath on commandline (javac or apt)

Including jars in classpath on commandline (javac or apt)


Hey all, trying to run this program. I think that to setup all of the web service stuff I need to run apt. (Although using javac I am having the same issue). I think what I am getting is compile errors. (Shown at bottom).

I think what I need to do is include this jar in my class path: jsr181-api.jar (source). Is there a simple temporary way to do this (on solaris)? I don't want to add it to my bash_rc file (it is there forever). I also know that there is some way to do it using a manifest text file but that seemed complicated so I didn't look into it yet. Can I just do something like:

<code>javac HelloImp<listOfJars></code>

or

<code>apt HelloImp<listOfJars></code>

Code:

<code>package server;import javax.jws.WebService;@WebServicepublicclassHelloImpl{/*** @param name
  * @return Say hello to the person.
  */
  public String sayHello(String name) {
  return "Hello, " + name + "!";
  }
}
</code>

Compile errors:

<code>HelloImpl.java:3:package javax.jws does not exist
import javax.jws.WebService;^HelloImpl.java:5: cannot find symbol
symbol:classWebService@WebService^2 errors</code>

Update: Cool that is wrapped up but it is still not quite working. I have created a new question to keep things nice and organized:

In windows:

<code>java -cp C:/.../jardir1/*;C:/.../jardir2/* class_with_main_method</code>

make sure that the class with the main function is in one of the included jars

Use the -cp or -classpath switch.

<code>$ java -help  
Usage: java [-options]class[args...](to execute a class)  
  or  java [-options]-jar jarfile [args...](to execute a jar file)  

where options include:...-cp <class search path of directories and zip/jar files>-classpath <class search path of directories and zip/jar files>  
  A ; separated list of directories, JAR archives,  
  and ZIP archives to search forclass files.</code>

(Note that the separator used to separate entries on the classpath differs between OSes, on my Windows machine it is ;, in *nix it is usually :.)

Using:

<code>apt HelloImpl.java -classpath /sac/tools/thirdparty/jaxws-ri/jaxws-ri-2.1.4/lib/jsr181</code>