Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Starting Web App on Embeded Tomcat via Java Web Start

 
Sebastian Valmont
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I have some trouble in starting my Primefaces WebApp from a embeded Tomcat v7 via Web Start.

Of course I signed all the jars and that stuff. The actual error in the java web console is:
Jul 09, 2013 9:52:06 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8081"]
Jul 09, 2013 9:52:06 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Tomcat
Jul 09, 2013 9:52:06 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.42
Jul 09, 2013 9:52:06 AM org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
INFO: No global web.xml found
Jul 09, 2013 9:52:06 AM org.apache.tomcat.util.digester.Digester endElement
SEVERE: End event threw exception
java.lang.ClassNotFoundException: org.apache.catalina.deploy.ServletDef
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)

My simple tomcat startup code looks like this:

public static void main(String[] args) throws Exception {

System.setSecurityManager(null); // i know, just for testing issues!!! didn't help anyway

URL e = WebApp.class.getClassLoader().getResource("WebApp.war");

File f = new File(new File(System.getProperty("java.io.tmpdir")), "TmpWebApp.war");

IOUtils.copy(e.openStream(), new FileOutputStream(f));

String webappDirLocation = f.getAbsolutePath();
Tomcat tomcat = new Tomcat();

String webPort = System.getenv("PORT");
if(webPort == null || webPort.isEmpty()) {
webPort = "8081";
}

tomcat.setPort(Integer.valueOf(webPort));

tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());

tomcat.start();
tomcat.getServer().await();


}

I found out the copy into the java temp folder seems to be required.

The JNLP-File looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase=
"http://localhost:8080"
href="webStart.jnlp">
<information>
<title>Simple Test</title>
<vendor>TestVendor</vendor>
</information>
<security>
<all-permissions/>
</security>
<resources>
<!-- Application Resources -->
<j2se version="1.7+"
href="http://java.sun.com/products/autodl/j2se"/>
<jar href="MyEmbdededTomcatApp.jar"
main="true" />
<jar href="tomcat-embed-core.jar"/>
<jar href="ecj-4.2.2.jar"/>
<jar href="tomcat-dbcp.jar"/>
<jar href="tomcat-embed-jasper.jar"/>
<jar href="tomcat-embed-logging-juli.jar"/>
<jar href="tomcat-embed-logging-log4j.jar"/>
<jar href="commons-io-2.4.jar"/>
</resources>
<application-desc
name="Html WebApp Demo"
main-class=
"WebApp"
width="300"
height="300">
</application-desc>
<update check="background"/>
</jnlp>


What am I doing wrong?

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's missing the class "org.apache.catalina.deploy.ServletDef" - is that somewhere in the jar files you're including?
 
Sebastian Valmont
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The missing class file is contained in tomcat-embed-core.jar, which is contained in the resource section of the .jnlp file.
So it should work
 
Sebastian Valmont
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it to work.

Now I'm able to have a java web start app, which runs an embeded tomcat with my web application contained in a war!
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What was the problem?
 
Sebastian Valmont
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was missing this line of code in my application:

Context context = tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());

WebappLoader solrLoader = new
WebappLoader(
WebApp.class.getClassLoader());
context.setLoader(solrLoader);

Otherwise the System Class Loader in the Web Start Context was used, which just had deploy.jar on its classpath.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic