Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a context.xml from Tomcat to Jetty

Tags:

tomcat

jetty

i have the following context.xml in webapp/META-INF/. This one is used by tomcat to define value that will be understand by Spring with a Property

<?xml version="1.0" encoding="UTF-8"?>
<Context>     
<Parameter name="si.host" value="super.com"  override="false"/>   
</Context>

Right now im trying to deploy the webapp with the maven jetty plugin :

    <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>6.1.26</version>
    <configuration>
      <connectors>
        <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
          <port>8080</port>
          <maxIdleTime>60000</maxIdleTime>
        </connector>
      </connectors>
      <jettyEnvXml>${basedir}\src\test\resources\server\jetty\jetty-env.xml</jettyEnvXml>
      <jettyConfig>${basedir}\src\test\resources\server\jetty\jetty.xml</jettyConfig > 
       <contextPath>/myapp</contextPath>
      <webApp>target/myapp.war</webApp>
      <stopKey>foo</stopKey>
      <stopPort>9999</stopPort>
    </configuration>
    <executions>
      <execution>
        <id>start-jetty</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <scanIntervalSeconds>0</scanIntervalSeconds>
          <daemon>true</daemon>
        </configuration>
      </execution>
      <execution>
        <id>stop-jetty</id>
        <phase>post-integration-test</phase>
        <goals>
          <goal>stop</goal>
        </goals>
      </execution>
    </executions>        
  </plugin>

How can i add this parameter in a jetty.xml file ?
I have already dig into their documentation and here and on google but found nothing clear.
Thanks in advance for your help.

like image 367
Omar Elfada Avatar asked Jan 21 '23 13:01

Omar Elfada


2 Answers

This needs to go in your WEB-INF/web.xml which is web-server independent i.e. it will work in both tomcat and jetty:

<context-param>
  <param-name>si.host</param-name>
  <param-value>super.com</param-value>
</context-param>

or you can set it in your jetty xml like this:

<Configure class="org.mortbay.jetty.webapp.WebAppContext">
  ...
  <Set name="initParams">
    <Map>
      <Entry>
        <Item>si.host</Item>
        <Item>super.com</Item>
      </Entry>
    </Map>
  </Set>
</Configure>
like image 92
dogbane Avatar answered Jan 27 '23 21:01

dogbane


First thank you DogBane !!

I have found an other solution without need to modify web.xml Use the Default web.xml file.

This file is applied to a Web application before it's own WEB_INF/web.xml file

I prefer this than using jetty.xml because it is less verbose.

Just add in the maven plugin configuration section the webDefaultXml with the path to the file below :

<web-app
   xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns   /javaee/web-app_2_5.xsd"
   metadata-complete="true"
   version="2.5">

  <description>
    Default web.xml file.
    This file is applied to a Web application before it's own WEB_INF/web.xml file
  </description>

   <context-param>
    <param-name>si.host</param-name>
      <param-value>super.com</param-value>
   </context-param>
</web-app>
like image 34
Omar Elfada Avatar answered Jan 27 '23 20:01

Omar Elfada