Running spring + hibernate application without actual servlet container - java

I have a Spring+Hibernate application, which I compile to *.war file and deploy it to Tomcat. This works for me as developer, but:
Is there a way to run that application in some user's computer, that has Java installed, but not tomcat installed?
I would even accept the solution, which uses somekinda package that actually runs the servlet container and deploys the application to user's computer, but I don't want that user must install container and configure it etc etc.
Any suggestions?
EDIT:
Basically I want user to run my web application from an executable, without having to install tomcat or other tools.

You have a few options:
if you are distributing the source code to the user, and they have maven installed, you can just run mvn jetty:run or mvn tomcat:run to build the application locally and run it within a servlet container started by the Maven plugin.
You can embed Tomcat or embed Jetty in your application, so that running a main() method in your app launches a servlet container listening on a certain port and runs your application. This makes it possible to package your entire application as a single .jar file and have it be run with java -jar your.jar.

The Winstone servlet container allows for embedding the war-file inside the winstone jar, resulting in a single jar deployment which can be run either with "java -jar foo.jar" or as a clickable jar.
Jenkins/Hudson uses this. We've used it with some classpath trickery to use an exploded war.
See http://winstone.sourceforge.net/#embedding for details.
This is most likely the most elegant way to do this at the moment.

You can certainly run a spring +hibernate application from command line, using the ClassPathXmlApplicationContext to load the spring configuration file in your main method to initialize the spring container and rest of the wiring.
However, to run a web application written using servlets or similar paradigms that use Java Servlet Specification, then you need a servlet container like Tomcat, AFAIK.

Not a direct example, but potentially useful example of something similar: http://www.zimbra.com/products/desktop.html and http://www.zimbra.com/products/zimbra-open-source.html

Related

What is the difference of Jetty Server and Embedding Jetty in my Application

I am building right now a Web Application, and generating a .war file.
How can I embed Jetty into it, so that this war can be a stand-alone application?
And that brings me to the key question, how is this different from deploying this war file into a Jetty Server?
Am I confusing something? Should I actually build a regular Java - jar -application, and start the server from a Main method, adding the Servlet and Handlers there?
My goal is to have a stand-alone java application, using a WebSocket Servlet, and I am using Jetty 8
Sounds like you want a self-executing WAR that has embedded-jetty in it.
The jetty project maintains such a project at
https://github.com/jetty-project/embedded-jetty-live-war

Spring boot application in windows server

I am planning to deploy a web application built on spring boot in windows server.
I want to use tomcat container.
Can I deploy the spring boot fat jar directly or is it recommended to deploy the war file.
please suggest how to deploy and the preferred method?
As Josh Long likes to say "Make Jar not War!" It really allows an application to have flexibility on where it can be run and allows for everything to be packaged as one artifact. Windows has no issue running the embedded Tomcat that is part of Spring Boot and that is exactly what it is doing when running it in your IDE. The one edge case to this is keeping the process running on the server. Normally in Windows you would do that by setting up a service and having that service run java -jar myapp.jar. I haven't personally seen it done so might take some playing around but it is possible.
A simple way to run a spring application in Windows Server is to run it as a service. You can do it using the winsw, that you download its .bin file here
winws download
Then, rename it to something like my-app.exe and create a XML file like this:
<service>
<id>my-app-service</id>
<name>my-app-service</name>
<description>Back end service for app</description>
<env name="HOME" value="YOUR_JAR_FILE_PATH"/>
<executable>java</executable>
<arguments>-Xrs -Xmx256m -jar "YOUR_JAR_FILE_PATH\YOUR_JAR_FILE.jar"</arguments>
<logmode>rotate</logmode>
</service>
Then, using the terminal, run:
my-app.exe install service
Your application is now a windows service and you can start\stop it in the tasks manager on the services tab.
Starting from the latest Windows versions, you could also deploy your Spring Boot app inside a Docker Windows Container. I wrote a complete guide: https://blog.codecentric.de/en/2017/04/ansible-docker-windows-containers-spring-boot/ (as already mentioned, Tomcat is already embedded in Spring Boot).
Spring boot internally has a tomcat server.
If you want to deploy it on tomcat then while building with maven build it as war.
If you want to deploy it has inependent application then build has jar and then place it in some folder and run it using below commands java -jar yourjarname.
Apache tomcat is a web container you cannot deploy a jar in tomcat server. If you created a web application then export your application as war file and put it in tomcat webapp directory, start the server and your war will be deployed.
How to deploy created .jar file in Apache Tomcat server in Eclipse IDE?

Jetty does not launch deployed war

I have a Scala application which I usually run like "sbt run". Now I packaged whole project to a .WAR file (via sbt package). Then I put the file into webapps/ directory and restarted Jetty. Logs say that the application has been deployed. And I can see it if I go to /tmp/jetty..../. But, it seems that Jetty does not run the "main" method of my application. This method runs the Twitter Storm topology, but I feel like nothing really happens once the war is deployed. This is my first time dealing with Jetty. I appreciate any help.
There is no such thing as a main method for webapps and wars.
If you want something to startup when the deployment is complete, you'll want to create, setup, and configure a custom javax.servlet.ServletContextListener where your implementation of contextInitialized(ServletContextEvente sce) performs your twitter storm topology.
or
You can skip the entire deploy of a war on a standalone jetty process. To do that you would setup an embedded jetty instance where you can do whatever you want in your own custom main, from starting up jetty itself, to adding your webapp, to executing your own custom code.
See the OneWebApp embedded example.
In your use case, you would initialize your 'Twitter Storm topology' after the server.start(); and before the server.join();

Where does WebSphere put the EAR file when RAD does a "Run On Server"? And how to run createEJBStubs on it?

I have a JavaEE-based web app with IBM RAD 7.5 (Eclipse) and WebSphere 7. The app has EJBs with remote interfaces. It runs fine.
I created a new project for JUnit tests, and I'm trying to do a JNDI lookup of the EJB to test it, but I get the following error:
"ClassCastException: org.omg.stub.java.rmi._Remote_Stub incompatible with com.myapp.UserServiceRemote"
To solve this problem, my understanding is I have to run the WebSphere createEJBStubs command to generate remote stubs, so the JUnit app (which is running as a separate application) can look up the EJB.
My question is:
When I run my app from within WebSphere by rightclicking the myappEAR project and selecting "Run As > Run On Server", where does WebSphere put the EAR file that's being run? That is, what folder is it in?
I ask because my understanding is I'm supposed to run the createEJBStubs command on it, which will generated the stubs and put those stubs in the EAR.
Any advice is greatly appreciated, thanks!
Rob
FYI, I followed the instructions here to create an ANT script to build the EJB jar with the stubs included:
http://www-01.ibm.com/support/docview.wss?uid=swg21393419
To speed up processing, an EAR is not actually built. Instead, the application is configured so that each module or JAR file is loaded from the RAD workspace. I would recommend exporting the EAR (from either RAD or the WAS admin console), and then using createEJBStubs on the result.

GWT app - deploying on Tomcat or any other servlet container

Is there a plugin for Eclipse GWT or any other method to automatically deploy and run GWT app on Tomcat (or any other Serlvet container)? For the moment the only method I know is copying the compiled classes into WEB-INF directory but this is an arduous work. Additionally you have to configure Apache Tomcat manually. I'd like to have something like in Eclipse Dynamic Web Project where you can run your servlets directly by spawning tomcat process.
Thanks
You could write an Ant task to deploy and run your GWT app. It could copy the files and then tell your servlet container to reload the latest files.
Is this what you are looking for: "How do I use my own server in hosted mode instead of GWT's built-in Jetty instance?"?
PS: You only need to copy the contents of the war folder once.
PPS: I'm assuming here you want to be able to easily deploy your app to Tomcat during development, since you are bringing up spawning Tomcat from Eclipse - meaning it's not a production server.

Categories

Resources