Hi all,

I have a couple of problems and need your help and some recommendations on
embedding jetty in a web app.
I don't want to use maven to run it (no jetty:run) and I also don't want to
use the start jar provided. As I want the war to be self sufficient.
To do so I have, implemented 2 classes for embedding jetty:
                    - one is the "production" server main class, that will
be moved to the root of the war,
                    - the other is an implementation with hot deploy
enabled to run during development (from eclipse for example).
And configured a pom for maven to produce the executable war (I use shade
plugin to build it and choose only the needed artifacts to be copied at the
root and deleted them from the WEB-INF/lib).

Most of the things work fine except :
                    - If I use jetty 8 the jsp-config in web.xml doesn't
seem to be recognised, if I go back to jetty 7 and servlet 2.5 it's ok.
However I would like to use jetty 8... am I missing something? I am using
glassfishs implementations.

                    - Second problem. When I am using my development
implementation of the server I have nullpointerexception in
JstlBaseTLV.validate after a hot deploy of a jsp. If I look at the code, I
can see that the initParameters map is null. Do you have any clue on how I
could solve this problem? This one is pretty annoying...

                    - Last problem, when I am running the server on debian
linux the app takes twice as much memory as in windows xp... does someone
already had this kind of problem?

I am joining to the mail an extract of the pom and the two simplified
server classes.
Thank you for your help.

Kind regards,
Eugen

Attachment: EclipseDeveloppementServer.java
Description: Binary data

Attachment: EmbeddedJettyServer.java
Description: Binary data

<project xmlns="http://maven.apache.org/POM/4.0.0"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd";>

	<modelVersion>4.0.0</modelVersion>
	<groupId>mycomp</groupId>
	<artifactId>mycomp</artifactId>
	<version>0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<name>its name</name>

	<properties>
		<jetty.version>[7.2.0,7.9.9)</jetty.version>
		<org.springframework.version>3.0.5.RELEASE</org.springframework.version>
		<jackson.version>[1.6.4,2.0.0]</jackson.version>
		<slf4j.version>[1.6.1,]</slf4j.version>
		<web.working.directory>${basedir}/src/main/webapp</web.working.directory>
	</properties>

	<dependencies>

		<!-- ***************** -->
		<!-- Serveur Jetty -->
		<!-- ***************** -->
		<dependency>
			<groupId>org.eclipse.jetty</groupId>
			<artifactId>jetty-server</artifactId>
			<version>${jetty.version}</version>
		</dependency>
		<dependency>
			<groupId>org.eclipse.jetty</groupId>
			<artifactId>jetty-webapp</artifactId>
			<version>${jetty.version}</version>
		</dependency>
		<dependency>
			<groupId>org.eclipse.jetty</groupId>
			<artifactId>jetty-deploy</artifactId>
			<version>${jetty.version}</version>
		</dependency>

		<!-- ***************** -->
		<!-- Deps environnement web (jsp, jstl, etc) -->
		<!-- ***************** -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>

		<dependency>
			<groupId>org.glassfish.web</groupId>
			<artifactId>jstl-impl</artifactId>
			<version>1.2</version>
		</dependency>

		<dependency>
			<groupId>org.glassfish.web</groupId>
			<artifactId>jsp-impl</artifactId>
			<version>2.1</version>
		</dependency>

		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>jsp-api</artifactId>
			<version>2.1</version>
		</dependency>

		<dependency>
			<groupId>javax.el</groupId>
			<artifactId>el-api</artifactId>
			<version>2.2</version>
		</dependency>

		<dependency>
			<groupId>org.glassfish.web</groupId>
			<artifactId>el-impl</artifactId>
			<version>2.2</version>
		</dependency>
		
	</dependencies>

	<build>
		<outputDirectory>src/main/webapp/WEB-INF/classes</outputDirectory>

		<plugins>
			

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>2.1.1</version>
				<configuration>
					<packagingExcludes>WEB-INF/lib/*jetty*.jar,WEB-INF/lib/*slf4j*.jar,WEB-INF/lib/*log4j*.jar,WEB-INF/lib/*servlet-api*.jar</packagingExcludes>
				</configuration>
			</plugin>

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-shade-plugin</artifactId>
				<version>1.4</version>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>shade</goal>
						</goals>
						<configuration>
							<createDependencyReducedPom>true</createDependencyReducedPom>
							<artifactSet>
								<includes>
									<include>*jetty:*</include>
									<include>org.slf4j:*</include>
									<include>log4j:*</include>
									<include>javax.servlet:servlet-api:*</include>
								</includes>
							</artifactSet>
							<transformers>
								<transformer
									implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
									<mainClass>mycomp.web.server.EmbeddedJettyServer</mainClass>
									<manifestEntries>
										<Class-Path>./etc/</Class-Path>
									</manifestEntries>
								</transformer>
							</transformers>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<!-- The main class needs to be in the root of the war in order to be 
				runnable -->
			<plugin>
				<artifactId>maven-antrun-plugin</artifactId>
				<executions>
					<execution>
						<id>move-main-class</id>
						<phase>compile</phase>
						<configuration>
							<tasks>
								<echo>Copie de la classe main pour lancer le serveur en faisant
									java -jar ${project.artifactId}-${project.version}</echo>
								<copy
									todir="${project.build.directory}/${project.artifactId}-${project.version}">
									<fileset dir="src/main/webapp/WEB-INF/classes/">
										<include name="mycomp/web/server/*.class" />
									</fileset>
								</copy>
							</tasks>
						</configuration>
						<goals>
							<goal>run</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

		</plugins>
	</build>

</project>
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" 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";>
	<display-name>name</display-name>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/conf/applicationContext.xml</param-value>
	</context-param>

	// deleted some stuff for simplicity

	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<servlet>
		<servlet-name>appServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/conf/servlet-context.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>

	<servlet-mapping>
		<servlet-name>appServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
	
	<!--	Config des jsp	-->
	<jsp-config>
		<jsp-property-group>
			<description>Toutes les views</description>
			<url-pattern>*.jsp</url-pattern>
			<page-encoding>UTF-8</page-encoding>
			<include-prelude>/WEB-INF/views/prelude.jspf</include-prelude>
			<include-coda>/WEB-INF/views/coda.jspf</include-coda>
		</jsp-property-group>
	</jsp-config>
	
	
</web-app>
_______________________________________________
jetty-users mailing list
jetty-users@eclipse.org
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to