This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Starting Web App on Embeded Tomcat via Java Web Start

 
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?

 
Rancher
Posts: 43016
76
  • 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: 43016
76
  • 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.
 
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic