2

When I deploy my app.war file with Elastic Beanstalk, it is deployed on the ROOT context so I'm able to reach it at http://any-domain/ when I need it to be available at http://any-domain/app/.

I'm using tomcat 8 on the EC2 intances. I know this question might be related with ebextensions and/or context.xml config.

kache
  • 83
  • 1
  • 6

2 Answers2

4

Finally, I was able to solve it.

I added a file called server-update.config to the .ebextensions directory placed at the root of your .war file. The contents of the file looks like this:

container_commands:
  replace-config: 
    command: cp .ebextensions/server.xml /etc/tomcat8/server.xml 

Further information about ebextensions: https://aws.amazon.com/blogs/aws/customize-elastic-beanstalk-using-configuration-files/

Regarding the server.xml, I take the server.xml placed at /etc/tomcat8 and I added the following section inside the <Host> section.

<Context path="app" docBase="ROOT"/>

Thanks to this answer: https://stackoverflow.com/a/18226607/3576460

Community
  • 1
  • 1
kache
  • 83
  • 1
  • 6
  • Hi! Can you share the entire `server.xml` ? – Roc Boronat Apr 06 '17 at 10:13
  • Hi @RocBoronat, sorry but I'm not working in that project anymore. As I said, I took the `/etc/tomcat8/server.xml` from the EC2 instance, then I updated the `` section. – kache Apr 07 '17 at 12:18
  • Yes... the thing is that I'm not proficient with the EC2 instances. So, getting that server.xml is not straightforward as I expected :·) That's why I asked you to just copypaste that server.xml. By the way, I went forward forgetting the idea of setting the app's context, so no problem. By the way, it could help other stackoverflow users :·) Thanks for the answer, tho! :·D – Roc Boronat Apr 10 '17 at 09:19
3

This behaviour is by design: "In a single WAR source bundle, the application always runs at the root path." http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-tomcat-platform.html

If you want to override this behaviour, the simplest way is to create a multi-war bundle with only two war files (basically just a zip file wrapping the wars). The name of the war within the zip will determine the path (pretty sure this only works for one level deep), in this case you would call it "app.war", and you must also include a ROOT.war that can be empty.

Oren
  • 1,796
  • 1
  • 15
  • 17
  • I think that this is better answer than mine. Thanks! – kache Aug 30 '16 at 14:21
  • This solution does not work for me. I wrapped both the war files (empty ROOT.war and app.war) into "main.zip". I deployed this zip file on elastic beanstalk. The wars ended up here: `/var/lib/tomcat7/webapps/ROOT/main/ROOT.war` and `/var/lib/tomcat7/webapps/ROOT/main/app.war` – Hari Samala Jan 26 '18 at 01:30