classpath problem with compiler...

I'm an experienced programmer but new to Java.

I thought I had the whole classpath thing figured out but I'm having trouble....

I'm working on a project that uses Axis and I was trying to compile somthing to simply return the Message context.

The problem I'm having is that no matter how I set up my class path, it can't find axis.jar (I think...).

Here's the code:

package PlexPackage;

import org.apache.axis;

publicclass PlexServ{

public String ReturnContext()

{

MessageContext mc = MessageContext.getCurrentContext();

return"";

}

}

Here's the bat file I'm using to compile it.

I put in the DIR to confirm that my class path was pointing to the jar.

(I've confirmed that the MessageContext class IS in that jar under org.apache.axis).

CompilePlex.bat file:

set CP="C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\lib\axis.jar"

dir %CP%

"C:\Program Files\Java\jdk1.5.0_06\bin\javac.exe" -cp %CP% PlexServ.java

and here's the results I get from running the BAT file:

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\classes\PlexPackage>CompilePlex.bat

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\classes\PlexPackage>set CP="C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\lib\axis.jar"

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\classes\PlexPackage>dir"C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\lib\axis.jar"

Volume in drive C has no label.

Volume Serial Number is 68F7-0E7D

Directory of C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\lib

04/22/2006 06:56 PM 1,599,570 axis.jar

1 File(s)1,599,570 bytes

0 Dir(s) 12,621,848,576 bytes free

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\classes\PlexPackage>"C:\Program Files\Java\jdk1.5.0_06\bin\javac.exe" -cp"C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\lib\axis.jar" PlexServ.java

PlexServ.java:2:package org.apache does not exist

import org.apache.axis;

^

PlexServ.java:6: cannot find symbol

symbol :class MessageContext

location:class PlexPackage.PlexServ

MessageContext mc = MessageContext.getCurrentContext();

^

PlexServ.java:6: cannot find symbol

symbol : variable MessageContext

location:class PlexPackage.PlexServ

MessageContext mc = MessageContext.getCurrentContext();

^

3 errors

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\axis\WEB-INF\classes\PlexPackage>

So questions to the group:

Do you see anything obvious I'm doing wrong?

I've tried MANY variations on setting the classpath (absolute, relative, etc) and all with the same results.

Do I only have to reference the jar I'm using in the classpath (axis.jar),

or do I have to list every jar that's referenced downstream?

(i.e. every jar that axis.jar references, and all the jars they reference, etc.)

Many thanks for any assistance!

S

[3982 byte] By [eggoeatera] at [2007-10-2 22:09:25]
# 1

You should use -classpath option (instead of -cp.)

[url=http://java.sun.com/j2se/1.5.0/docs/tooldocs/windows/classpath.html]To quote the doc[/url]:

The JDK tools java, jdb, javac, and javah have a -classpath option which replaces the path or paths specified by the CLASSPATH environment variable while the tool runs. [...]

The runtime tool java has a -cp option, as well. This option is an abbreviation for -classpath.

PS :

By the way, I'm not sure your import statement is correct (unless 'axis' is a class), shouldn't it be:import org.apache.axis.*;

TimTheEnchantora at 2007-7-14 1:26:12 > top of Java-index,Java Essentials,New To Java...
# 2

The -classpath option gave me the same results (I think they changed that in ver5) but the .* worked!

I didn't think you had to have the asterick.

All the example code that came with Axis doesn't have astericks on the import statements. Oh well.... I'll have to read up on that.

Thanks for the reply!!

S

eggoeatera at 2007-7-14 1:26:12 > top of Java-index,Java Essentials,New To Java...
# 3
[url= http://java.sun.com/docs/books/tutorial/java/interpack/usepkgs.html]Using Package Members[/url]Regards,Tim - the week-end just knocked at my door...
TimTheEnchantora at 2007-7-14 1:26:12 > top of Java-index,Java Essentials,New To Java...
# 4
> Tim - the week-end just knocked at my door...World cup HOOO
thorne_iv2a at 2007-7-14 1:26:12 > top of Java-index,Java Essentials,New To Java...
# 5

Thanks for the link. I read it and that makes more sense now.

(I'm coming from .NET which doesn't require the .* after

an import namespace statement, so I'm sure that's where I was getting confused.)

BTW, I tried it again with -cp instead of -classpath and it worked.

Like I said, I think that's new with Java 5.

Thanks again.

S

eggoeatera at 2007-7-14 1:26:12 > top of Java-index,Java Essentials,New To Java...