Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] jetty-env.xml and extraClasspath issues in ContextDeployer vs WebAppDeployer [plus mode]

Hello,
I am trying to achieve the following two items in jetty but they are not working out together only one of them at a time. Please help.

R1. set up jndi resources using jetty-env.xml - jetty-env.xml included in WEB-INF, as well as
R2. add additional classpath for the webapp using extraClasspath of WebAppContext (why? pls see below *Explaination1)

I have tried following two ways to achieve it:

Try1: WebAppDeployer[plus]
I deployed an extracted webapp in webapps-plus/ directory, thus relying on WebAppDeployer (in jetty-plus.xml) for starting the webapp.
The webapp has jetty-env.xml in WEB-INF/ which is picked up by the WebAppDeployer, I have setup debug statements in jetty-env.xml to verify this.
Please see attached jetty-env.xml for details. Please note the extraClasspath setting in the jetty-env.xml.
And because I see FileNotFoundException in the logs for some of the I have in extraClasspath, I think extraClasspath setting in jetty-env.xml is ignored by WebAppDeployer. I am not sure why it would do that.

I can only guess that, by the time jetty-env.xml is read, webapp is already under deployment and so extraClasspath setting is rendered meaningless. Am I correct??

So I tried gave it another shot with the following try.
The only way I can ensure that extraClasspath is set before actual webapp is deplyed is to employ hot deployment using ContextDeployer. Here is what I found...

Try2: ContextDeployer
Again I have the same extracted webapp in webapps-plus/ directory with jetty-env.xml in WEB-INF/ . In addition to this I have (see attached) DWMessagingWeb.xml in context/ folder. Thus relying on ContextDeployer for deployment.
I have debug statements in both DWMessagingWeb.xml  and jetty-env.xml files. In addition to this I have (same) extraClasspath setting in both the files.
This time from logs I can see that DWMessagingWeb.xml is picked up and extraClasspath setting has come into effect, as webapp is able to locate additional resources in present extraClasspath. However, none of the log statements from jetty-env.xml appear in the log files and the webapp fails to locate jndi resources in jetty-env.xml. I see NameNotFoundException in logs.
I wonder if ContextDeployer looks for jetty-env.xml and loads it?? I think it does not.


So FINALLY questions really are

Q1. Is it possible to have extraClasspath in WebAppContext of jetty-env.xml recognized/picked-up/used by the container? How?
or extraClasspath in WebAppContext of jetty-env.xml is just ignored?

Q2. Is it possible to load jetty-env.xml if deploying using ContextDeployer? How?

Thanks,
Kashyap Amin.

*Explaination1:
for #R2 above I am trying to add webapps resourceBase directory in classpath so that WEB-INF is in classpath
This is required to achieve loading resources in Spring using classpath:WEB-INF/resources/foo.xml, for example

Configuration details:
Jetty - 7.1.6.v20100715
with annotation and plus options and using etc/jetty-plus.xml in start.ini file
thus command line is simply java -jar start.jar
created webapps-plus in jetty.home
no other changes to default jetty config
sun java jre : 1.6.0_18
OS - Windows XP
Spring 3.x
Hibernate 3.x
<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd";>

<!-- ==================================================================
Configure and deploy the test web application in $(jetty.home)/webapps/test

Note. If this file did not exist or used a context path other that /test
then the default configuration of jetty.xml would discover the test
webapplication with a WebAppDeployer.  By specifying a context in this
directory, additional configuration may be specified and hot deployments 
detected.
===================================================================== -->

<Configure class="org.eclipse.jetty.webapp.WebAppContext">

	<Get id="myLogger" class="org.eclipse.jetty.util.log.Log" name="log" />
	<Ref id="myLogger">
		<Set name="debugEnabled">true</Set>
	</Ref>
	<New id="myException" class="java.lang.RuntimeException">
		<Arg>My context/ Exception String</Arg>
	</New>

  <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  <!-- Required minimal context configuration :                        -->
  <!--  + contextPath                                                  -->
  <!--  + war OR resourceBase                                          -->
  <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
  <Set name="contextPath">/</Set>
  <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/webapps-plus/DWMessagingWeb</Set>
  <Set name="extraClasspath"><Get name="resourceBase"/>/</Set>
  <!-- just making sure that extraClasspath is set -->
	<Get id="myclasspath" name="extraClasspath" />
	<Ref id="myLogger">
		<Call name="debug">
			<Arg>
				<Ref id="myclasspath" />
			</Arg>
			<Arg>
				<Ref id="myException" />
			</Arg>
		</Call>
	</Ref>  
</Configure>
<?xml version="1.0"?>
 <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd";>

<Configure class="org.eclipse.jetty.webapp.WebAppContext">

	<Get id="myLogger" class="org.eclipse.jetty.util.log.Log" name="log" />
	<Ref id="myLogger">
		<Set name="debugEnabled">true</Set>
	</Ref>
	<New id="myException" class="java.lang.RuntimeException">
		<Arg>My jetty-env Exception String</Arg>
	</New>

	<!-- Set extra class path to include context in classpath -->
	<!--
		this enables access to resources using classpath:WEB-INF/dir/filename
		etc.
	-->
	<Set name="extraClasspath">
		<Get name="resourceBase" />
	</Set>
	<Get id="myclasspath" name="extraClasspath" />
	<Ref id="myLogger">
		<Call name="debug">
			<Arg>
				<Ref id="myclasspath" />
			</Arg>
			<Arg>
				<Ref id="myException" />
			</Arg>
		</Call>
	</Ref>

	<New id="jdbc_localdb_hsql" class="org.eclipse.jetty.plus.jndi.Resource">
		<Arg></Arg>
		<Arg>jdbc/localdb_hsql</Arg>
		<Arg>
			<New class="org.hsqldb.jdbc.JDBCDataSource">
				<Set name="database">jdbc:hsqldb:hsql://localhost:9001/xdb</Set>
				<Set name="user">SA</Set>
				<!-- <Set name="password"></Set>  -->
			</New>
		</Arg>
	</New>

</Configure>

Back to the top