File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Starting Web App on Embeded Tomcat via Java Web Start Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Starting Web App on Embeded Tomcat via Java Web Start" Watch "Starting Web App on Embeded Tomcat via Java Web Start" New topic
Author

Starting Web App on Embeded Tomcat via Java Web Start

Sebastian Valmont
Greenhorn

Joined: Jul 09, 2013
Posts: 4
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
Marshal

Joined: Mar 22, 2005
Posts: 42596
    
  65
It's missing the class "org.apache.catalina.deploy.ServletDef" - is that somewhere in the jar files you're including?


Ping & DNS - my free Android networking tools app
Sebastian Valmont
Greenhorn

Joined: Jul 09, 2013
Posts: 4
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

Joined: Jul 09, 2013
Posts: 4
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
Marshal

Joined: Mar 22, 2005
Posts: 42596
    
  65
What was the problem?
Sebastian Valmont
Greenhorn

Joined: Jul 09, 2013
Posts: 4
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Starting Web App on Embeded Tomcat via Java Web Start