Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting classpath in web.xml

Status
Not open for further replies.

DoraC

Programmer
May 7, 2002
98
US
Hi,

I'm following a fairly standard path of using ant to build my jsp/servlet web app. However, I've run into an issue I can't seem to resolve (and can't locate suitable documentation on, either).

I would like to include a java package in the compile classpath, but I'm not sure where or how to list this in the build.xml file. There seem to be provisions for .jar files, but not .class files contained in packages. I've tried the (stunningly naive, I'm sure) approach of:

Code:
    <property name=&quot;my.source&quot; value=&quot;C:\myPackage&quot;/>

...

    <pathelement location=&quot;$my.source&quot;/>
    <fileset dir=&quot;$my.source&quot;>
      <include name=&quot;*.class&quot;/>
    </fileset>

but, (not surprisingly), after rebuilding when I go to load my page it errors out with a &quot;package does not exist&quot; error,
so evidently it's not finding it...
my build.xml file works fine otherwise, for &quot;vanilla&quot; builds.

Any help very appreciated,
Thanks -
Dora




 
Hi Dora,
Are you talking about making classes available inside a deployed web application, or making them available when you compile classes using the build file before deploying the web app?

Is your web application deployed as a WAR file?

If you want to add java classes to a classpath in Ant you have to specify the location of the root of the package hierarchy, not the directory that contains the class file (unless the class file is not in a package, in which case the root of the package hierarchy is the directory that contains the class file).

So if you have a class com.myCompany.MyClass stored in the build/classes directory (relative to the basedir of the build.xml file), you add them to a classpath like this:

<property name=&quot;build.dir&quot; value=&quot;build&quot;/>

<path id=&quot;project.classpath&quot;>
<pathelement location=&quot;${build.dir}/classes&quot;/>
</path>

You can then refer to the project.classpath by its id.

<javac srcdir=&quot;${src.dir}&quot; destdir=&quot;${build.dir}/classes&quot;>
<classpath refid=&quot;project.classpath&quot;/>
</javac>


 
Thank you for your response....

1) I'm not deploying my application as a WAR file
2) I guess the answer would be that I'm trying to make my
classes available inside a deployed web application.

THe reason I say this is because they are referred to in a .jsp file, and that's where the error occurs (not the ant compile step). WHen I try to load the .jsp file, I get a
package doesn't exist error - resulting from the
<%@ page import=&quot;mypackage1.*, mypackage2.*&quot;%>
step.

I think my attempts before were a little misguided, in that they were probably influencing the actual compile time classpath. So please forgive my very basic question, but how can I then influence the runtime classpath? Is there a setting in ant for this?

THanks a lot for the help, it's really apprecaited!
Dora


 
You probably have to check the documentation for the application server you're using to find out how to set the classpath. For instance, Weblogic has a WLCLASSPATH variable that can be set as part of the server start up process.

I reckon you should have a look at deploying as a WAR file. It makes it a lot easier to deploy an application and it gives you more control over things like security, initial context parameters and what goes in the classpath. Everything you put in the WEB-INF/classes directory of the WAR file is automatically added to the classpath. Ant has a task which makes it easy to package up a WAR file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top