I am having trouble connecting to the endpoints of my java application deployed to AWS Elastic Beanstalk. The application handles a number of POST requests and is intended to serve a mobile application, so the server itself does not have any static files. I used the Spark Java framework, which finds the endpoints correctly when I test on Localhost, but not on AWS Elastic Beanstalk.
I can deploy the Exploded war onto EB (running Tomcat Web server), yet all requests that I send return a 404 Error: Resource not Found. Spark java runs on the embedded Jetty server, so to run on Tomcat, I did as suggested in their documentation (http://sparkjava.com/documentation#other-web-server): I have implemented the SparkApplication interface, moving all endpoints from main() to init() and I added the suggested code to the web.xml file.
The .war uploaded contains META-INF with web.xml, lib (with the gradle libraries), and classes (with my compiled output). Again, no static files.
More details:
I use the Elastic Beanstalk IntelliJ (Ultimate) plugin to deploy and at this point I tested that this is no different from deploying a .war directly on the EB dashboard. I have opened to all ports and connections in security settings to discard any connectivity issue. I believe this is just a matter of the servlet not mapping the urls. Any suggestions?
Run it as a war on local box to make sure you have the wiring right. I have done this recently - Spark Java on Beanstalk, but I think I deployed it as a jar. Beanstalk supports just straight java jar (fronts it with nginx). I think when I deployed as a jar, I did have to do something to specify the listening port of 4567 that Spark Java uses by default.
I have run Spark Java as a war in Tomcat as well, but I don't think on AWS - I believe in that case I deployed as a jar.
Solved! I had code inside the main class that was changing the port. While this was necessary to run on the local environment, it conflicted with AWS, which assigns the port automatically.
Related
do you know where do I need to put the heroku http port in my web app?
The only documentation I can find is: https://devcenter.heroku.com/articles/setting-the-http-port-for-java-applications but I do not use eighter of those options which are in the documentation. I can't find no java maven web application example. The only examples I can find are for node.js.
I deploy my app just by using:
heroku war:deploy warfile.war --app myproject
I am aware of two solutions:
1) At the webpage of Heroku Dev Centre describing the Configuring WAR Deployment with the Heroku CLI, you find the Configuring Tomcat Options which describes commands configuring the way a war file will be executed on the server by setting the WEBAPP_RUNNER_OPTS configuration variable on your application with a wide range of options described at Webapp Runner: Options. You might find the --port interesting that is set to 8080 by default and can be configured like:
heroku config:set WEBAPP_RUNNER_OPTS="--port=9090"
2) Another solution is at Heroku Dev Centre Create a Java Web Application Using Embedded Tomcat.
Basically, it means that the application will be launched on the embedded Tomcat using dependencies. This provides an ability to configure the Tomcat directly at the code-base of your project.
Tomcat tomcat = new Tomcat();
tomcat.setPort(Integer.valueOf("9090"))
// defining context and localizing resources
tomcat.start();
tomcat.getServer().await();
I am trying to deploy a war file in tomcat7. I am using MySQL JDBC driver to connect to database server. The jar file of MySQL JDBC driver is copied to $CATALINA_HOME/lib/ directory and the web application works correctly.
Now, I want to deploy the .war file in Amazon Elastic BeanStalk service. By default, Amazon doesn't place the MySQL JDBC driver in $CATALINA_HOME/lib directory by default and I can't run a script which will ssh into each instance and download the jar in the directory.
Is there any way, in which I can bundle the jar file for JDBC driver , so that I don't have to download and place the jar file in $CATALINA_HOME/lib directory ?
You can place the jar file in an S3 bucket, and then use a EB container command to copy the file to the lib directory, like:
"copy-lib-file":
mode: "000644"
owner: root
group: root
source: https://s3.amazonaws.com/<MY_BUCKET>/<my-JDBC-driver>.jar
No you can't bundle JDBC JARS for Tomcat7:
I've had this issue and it was a nightmare to debug. In my trials and in the documentation you can't bundle JDBC drivers inside your WAR file. Or at least you can but the classloader will ignore JDBC classes that are not in the Tomcat Lib folder. Its in the first paragraph of the Mysql section of the documentation here -> Tomcat7-JDBC I don't know of Tomcat8 or Tomcat9 beta...
Short Term Solution
What I do is exactly what you said you don't want to do and similar to Mark B's solution. I use a script that copies it from s3 but this is really easy and is only 1 line of bash if you use the aws s3 cp command. The aws s3 tool comes installed on the EC2 instance your application will be running on.
aws s3 cp s3://mybucket/mysql.jar /usr/share/tomcat7/lib/mysql.jar
*You will need to restart tomcat another reason you should see the longterm solution
Long Term Real Solution = Automate Your Build Steps
In the end you'll eventually have to run provisioning scripts if your application becomes complex, which is why I stopped using elastic beanstalk and started using AWS cloudformation which gives you a "STEP" where you can throw in all your setup scripts similar to docker build steps. It will also run those configuration steps for every new instance that gets created so there is no needed for you to ssh onto every box.
Cloudformation is all about turning your infrastructure setup into code which you could actually check into github and build without any manual intervention. You go through the headache of configuring your build scripts once then save your environment as a json or yaml file. You can include the MySQL server, tomcat version, firewalls, load balancers etc etc and build that all from a file.
Tomcat, like many application servers, installs a variety of class loaders (implementation of java.lang.ClassLoader) that will give your application access to the JDBC jar resource.
The order is:
Bootstrap
System
Common - $CATALINA_BASE/lib
Webapp - /WEB-INF/lib
Put the jar into the WEB-INF/lib directory inside the application. Note, this JAR will be only visible to this specific application and no others.
In order to do so you need to use .ebextensions.
With .ebextensions you can copy files from your application package to the beanstalk file system.
However keep in mind that no other application deployed in a beanstalk environment will use your driver. Your beanstalk instance is dedicated to one application. Every time you upload the application you have to upload the mysql driver in order to be deployed to the tomcat installation.
Therefore you do not gain anything in terms of upload size or memory footprint in a tomcat (shared jdbc connetion pool through jndi).
It seems that uploading your application with the jdbc driver included (non provided in your maven config) is a more beanstalk oriented solution.
However there are cases you don't want to make any changes in the way your war gets packaged, for example your application gets deployed to an on premises tomcat server containing the jdbc driver and you want to upload it to an elastic beanstalk environment.
In such cases you can consider docker with elastic beanstalk as an option too.
I built my java RESTful application in Eclipse with Jersey and a couple other libraries. My question is, how do I deploy this to a Tomcat server? Do I export it as a WAR file? Do I need to deploy the libraries I used as well or are they packaged in the WAR file?
The server is running on an ubuntu machine which I can access over ssh. I got the server running with "apt-get install tomcat7". Which folder should I put it in? Is any configuration needed? What should I do with the web.xml file?
Thanks in advance.
You usually wouldn't use Apache to directly serve a Jersey web application as Apache is not a Java application server. It would be served from a Java server such as Tomcat instead. If you wish to serve your Jersey application as if it was located on your Apache server, you would still have a Tomcat server running and set up a reverse proxy to your Tomcat server. I personally use a server such as Wildfly or TomEE which implements the full JavaEE profile and means you are less likely to run into errors. Nearly all Java application servers also have the capability of serving static content so unless you specifically need Apache features, you do not need to go to the trouble of also running Apache.
With each one of these servers you would need the .WAR file and deploy it, either through the appropriate maven plugin, the web manager or placing the .WAR into the appropriate directory.
Dependencies for a .WAR specified in the 'compile' scope will be included as part of the .WAR file and those in the 'provided' scope will not be included (for when your web server has these included)
I have an enterprise application running on a WebLogic server.
When I modify any Java class, I have to build the .ear file and deploy to the server every time. Even for a small modification, I need to build the whole application and deploy to the server. The server is taking around 10 minutes to do this.
Is there any other way to do this?
When I was working with Tomcat, we used to update the .class files directly in the webapps project folder so that we didn't need to re-build the entire application.
Yes - there is a feature called FastSwap.
Using FastSwap to speed up dev
Using FastSwap Deployment to Minimize Redeployment
When you create a weblogic domain, you define it will be started in Development or Production mode.
To modify that, update the value of production-mode-enabled to true or false in config/config.xml
For more details check the following link or Weblogic documentation.
Difference between DEV and PROD mode in Weblogic 10.3
About your question on Weblogic Plugin, I suppose your're talking about OEPE (Oracle Enterprise Pack for Eclipse), which will deploy your application to a running domain that will be in dev or prod mode according to the mentioned in the config.xml
I wrote a small servlet and jsp project on eclipse and tomcat 5.5, but I don't know with works I do for make that a real site on a real host. Should I war them or I should upload project on host? My host should have which properties? I really don't now how to start?
I would recommend packaging them in a war and deploying it out to the remote tomcat server. Its not a good idea to deploy an unpackaged project directly to the server unless your debugging or testing. Once you have a finished project ready to deploy package it to a war. I typically deploy to server using the tomcat manager page. Just browse for the war, click the upload button and it should start right up. On my local machine this is the url that I use to upload to the server http://localhost:8080/manager. The server itself should have the same properties and settings that you are using in your eclipse workspace, and I would highly recommend that it be the same version as well. The war can also be dropped into a directory on the remote host and Tomcat will load this on startup, this location will vary depending on the host.