This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming 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
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

How to deploy the web-app without appbase attribute using embedded tomcat 8 ?

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I set the following attribute  for embedded tomcat 8

this.embedded = new TomcatImpl();
this.embedded.setPort(0);
this.embedded.setBaseDir(getPath());
((StandardHost) this.embedded.getHost()).setUnpackWARs(true);   If  I set the value to true
//this.embedded.getHost().setAppBase(getPath());              I did not set this value as I have to deploy using context docbase attribue
this.embedded.getHost().setAutoDeploy(true);
this.embedded.getHost().setDeployOnStartup(true);
this.embedded.getHost().setCreateDirs(true);

Context rootContext = this.embedded.addWebapp("", getPath() + dirchar + "ROOT");
rootContext.setReloadable(false);

Context appContext = this.embedded.addWebapp("M", getPath() + dirchar + "ROOT");
appContext.setPrivileged(true);

After setting the above attribute i  deploy the war as

               Context context = this.embedded.addWebapp(this.embedded.getHost(), contextPath, absolutePath);
context.getLoader().setDelegate(true);
context.reload();
context.setReloadable(false);

Everything works fine but i got the below error message

Exception fixing docBase for context [/service]
java.io.IOException: Unable to create the directory
[/var/opt/mediation/MMStorage/Online/etc/tomcat/webapps/webapps/service]
at org.apache.catalina.startup.ExpandWar.expand(ExpandWar.java:115)
at org.apache.catalina.startup.ContextConfig.fixDocBase(ContextConfig.java:619)
at org.apache.catalina.startup.ContextConfig.beforeStart(ContextConfig.java:752)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:308)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:394)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:144)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725)
at org.apache.catalina.core.ContainerBase. (ContainerBase.java:701)

to remove this error

I set the  below value

b]((StandardHost) this.embedded.getHost()).setUnpackWARs(false)[/b];   If I change the value false from true

I did not get any error


but migration guide of tomcat says that

https://tomcat.apache.org/migration-8.html

says that we should not set this value as  false due to security reason

Please suggest me best approach for tomcat 8 for context docbase deployment without this error

T
 
Saloon Keeper
Posts: 21127
131
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Security is not the main issue when determining whether to unpack WARs or not. If you properly secure your system, I doubt it will even make a difference. On the other hand, the latest javadocs indicate that allowing Tomcat to unpack a WAR can result in significant speedup in deployment. Whether you find that important depends on your work environments and viewpoint. I've never felt it to be a problem.

If you do decide to unpack WARs, however, you need to tell Tomcat where to unpack the WARs to. That is, you must have a destination directory similar to the TOMCAT_HOME/webapps directory that will serve as the parent directory for the unzipped WAR files.

Your problem is that you're telling Tomcat to unzip into a directory that does not exist - /var/opt/mediation/MMStorage/Online/etc/tomcat/webapps/webapps/service - and since you don't show how the variable absolutePath is being set, it's hard to tell exactly what you did wrong in creating that name.



So much for your actual problem. Here's some info that you might find useful.

First, on Unix/Linux depoyment, the directory path /var/opt/mediation is a bit wonky. Typically you'd either use /opt/mediation (or something like /opt/com/mousetech/mediation is what I use, since I'm mousetech.com). OR you'd use /var/lib/mediation. You have an odd combination of both. Not exactly wrong, just weird since it conforms to none of the accepted usages.

The other thing has to do with filesystem paths and context paths. Instead of:

Context rootContext = this.embedded.addWebapp("", getPath() + dirchar + "ROOT");

you might prefer this:



Why you're deploying 2 different instances of the same webapp I don't know, but that's your business. Do note that a webapp context path should be absolute, so simply deploying under "" and "M" shouldn't work. If it does, well OK. But it's not how the convention works elsewhere.
 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!