So I'm really new to the Java webstack world, and had a question on the most efficient solution to my problem. Some background information first; I'm running Tomcat on a Lubuntu 14.04 server listening on Port 80, developing on a separate Windows computer in Spring Tool Suite (developing Spring applications obviously). Currently, whenever I want to test something, I...
1) Export the project as a WAR file from Spring Tool Suite
2) Undeploy the old WAR file from the server from the Tomcat manager webapp
3) Deploy the new WAR file that I just got from Spring Tool Suite (which takes ~15 seconds)
Is there any faster way to do this? Normally, I wouldn't be opposed to just developing on localhost. However, I'm going to be doing a group project, so we would all need access to the same SQL server, which would be the one hosted on the Lubuntu 14.04 server.
How can I solve this issue?
Most IDEs have the ability to deploy to server for both development and production purposes.
Those that don't have this ability inbuilt, ususally have a add-on that enables this.
You can also use build tools such as maven or gradle to undertake these actions.
Since you raised a good point of working with others it is important that all are across the deployment process and that the process is standardised to ensure no weird issues/bugs pop up.
Related
I'm complete able to configure spring boot in both cases, the question here is which of them are more robust and is the more recommended, because I didn't find in the spring boot documentation the recommended way to deploy it in a production environment, my concerns about use the embedded container are:
If I want to set it as a Windows or Linux service, is the jar file the best option?
If I use the jar file I'm not going to have access to restart the server.
Maybe in the future I need more applications in the same container.
If I restart the machine I have to execute again the java -jar.
The question in general is which is better use the jar file and execute it as java -jar jarname.jar in production or change the packaging to war set the tomcat as provided and set the generated war in an empty tomcat.
I hope you can help me.
---EDIT---
Many times the answer is depends, this is for a normal web application or REST web service.
jar packaging is perfectly suitable for production and you should rather fallback to war only if you really have to - which is often the case when you cannot control your deployment environment (which is often the case in large enterprises).
There is a chapter in Spring Boot Reference about setting up Spring Boot based application as a Unix/Linux/Windows service: Installing Spring Boot applications.
Regarding your concern:
Maybe in the future I need more applications in the same container.
With embedded containers if you need more applications running on the same machine, you should start two applications separately, each running on different port and effectively you will end up with two containers running - which is good, applications are better isolated from each other.
About a month ago I had the question like yours.
Let me share my conclusion:
1) JAR:
You can run independently every appliction with different ports (in linux, java -jar ... > app_logs.log &) and you can route it (e.g. nginx). Note that, restarting is not problem. You can write custom bash script (like this: ps aux | grep appname and kill by PID)
But there are some problems with configuring production app. Property files will archived into jar.
2) WAR
You can deploy into container and just run it. Easy managing at the server. If you want to re-configure app, open properties file from unarchived folder inside container, change it as need and restart container. So, managing and configuring will be easy.
But, if you want to run another app in this server with another port, then you must install another copy of container and config it.
So, in my practice, using war app easier than jar to manage and re-configure.
I don't know that much about Windows services but on Linux you can add the execution of a jar to a RC-Scripts (and thus make the application start at a certain run-level). For a spring boot app you just have to symlink to the jar and you can start/stop/etc like any other service, see: Spring Boot application as a Service
restart the machine or the JVM? A shutdown mechanism is built into spring boot, you just have to activate it (and you should enable security machanism so that not anybody can do that), see: How to shutdown a Spring Boot Application in a correct way?
Spring-Boot enables microservices - so the idea is to have one embedded webapp-container for each webapp/microservice. This reduces the risk of losing all services when only one is going down.
Yes. and you have to execute catalina.sh|bat start after every restart. Or you add an appropriate startup script (see 1.)
I sense that you'd rather do it the old-fashioned way. Despite the 'matter of taste' answer, there is one argument pro-jar: the only dependency is the JVM! The rest (the web-app-container, db-drivers, other libraries) is all part of the package you deliver. And if you decide to change the container for the next release, so will it be.
One more reason to use "war" file in production.
Springboot masked an error Jetty threw whereas WAR deployed in Jetty correctly caught it ( though issue below is still under review )
https://github.com/spring-projects/spring-boot/issues/8917#issuecomment-294673487
I don't know much about server kind of things, But my recommendation is
If you are using Monolithic application, better to use war with
external tomcat.
If you are using for Micro Service applications, use embedded
tomcat with different port. And each micro service applications are
independent from each other.
I am about to start working on a JSF application and I am trying to decide on how to set up my production environment.
I enjoy working off my VPS for production instead of my local host. Is there a way to launch a JSF app to my server and then build on it from there? Or is that not going to work because I have to have a compiler to compile the java each time I update?
If that is the case would it make sense to just install a compiler to the server?
This is my first JSF and real java application so if there is some good info on this please lead me there.
I have someone working with me and I was assuming if we both work of the server it would be easiest.
How would this work in a professional environment, or in other words how would a team working for a company set their environment up?
How it generally works is that each team member has a local installation, and deployments up the chain to servers are handled by the systems admin guys on requests, them being provided with an installation package containing the compiled application (a WAR or EAR file), any other files needed, and quite likely a script with database changes, an installation manual, and things like that.
You should never develop directly on a production server. Only deploy stuff there once it's complete, tested, and verified to be in working order, and secured against attacks.
I have two questions, for those which I did not get any solution sounds good for my expectations.
1. Why both XAMPP/WAMP and Apache Tomcat?
Assume if I am now running a Windows system, with Eclipse LUNA.
Now, if I have to run a query for my localhost server, how does Eclipse help?
I won't be satisfied if you say there should be an XAMPP server running live for your query to execute in Eclipse(Like they say here Database Development Using the Eclipse IDE, MySQL with Eclipse Data Tools Platform in Java).
Then why Tomcat is there?
Sorry if there is some loop hole, or may be this is a Banana-Monkey` type question. All because I don't get it clear.
And now, my second question.
2. How can I(Is it possible to) run a Java project in Eclipse with Apache Tomcat while WAMP/XAMPP is running in background in my system?
Suppose I am on the same system working with different user privileges. Say user1 runs both the XAMPP and Eclipse As Administrator. Now (or anyhow) is it possible to run a project in Apache Tomcat while WAMP/XAMPP is running in background simultaneously in the system?
I am totally confused. Helps with your comments and answers are appreciated.
Thank you.
Yes it is possible to run two servers on same system simultaneously.
Yes you can execute a MySQL query when XAMP/WAMP is not running.
It seems you don't understand your setup and the elements involved.
XAMP/WAMP contains Apache server, so a http server that can handle static html or run php scripts. It also comes with a MySQL database.
So the only important part from the Java WebAPP is the MySQL. You can start MySQL without starting apache, you can finally install MySQL yourself (it has simple windows installer). But if your application is using MySQL it has to be running for it to work (be it a XAMP version or standalone version).
Your Java Web Application requires application container to run, and it is the Tomcat. It is Apache Tomcat as it is developed under apache groupe, but it is not the same as Apache web server.
So you need tomcat to run your web app. Again you can install one yourself or use the one that comes toghether with Eclipse.
You can have many tomcats at the same time, all running (for example different version of Tomcats or Java) as long as they listen on different ports. The ports on which tomcat is runing is configured in its server.xml file under conf directory.
We have two separate web projects for our application
One for Spring REST services
Other for AngularJS, the front end of the application.
We have been using eclipse for development of both and also for running those locally on tomcat server.
It is a great deal of pain to view updates to JavaScript and CSS part of the second project from eclipse, because it requires restart or publish of the tomcat server every time which takes a long time.
So I wanted to use eclipse for development of REST and front-end development editor like Brackets for development of AngularJS/JavaScript and CSS. But then they run on different ports causing Cross Site requests errors, and I don't want to write any CORS filter like this for this purpose.
Is there any better way to get these tools work together ?
Spring Tool Suite (STS) uses the pivotal tc server will automatically deploy resources without redeploying the application. Download it and give it a go, STS is just eclipse anyway with different branding. Maybe you can just download it, copy the pivotal server folder to your eclipse folder and add it to your servers view in your eclipse version. One thing I have noticed is that the application must be running under a context for this to work, deploying to root does not automatically deploy resources for some reason (at least this was the case when I was using the previous vfabric server about a year ago).
I have a Spring MVC project running locally on tomcat right now. What I need to do to be able to run it on my linux server? How can I deploy it? Before I used firezilla(running usual jars) to connect to server using ssh. Please help me by writing easy steps on how to run web application on server, thank you.
There are a lot of answers to this just have to google (i found about 10 in first couple pages that were good).
It all varies based on your environment, build setup etc.
Here is example of deploying with maven to tomcat
http://www.mkyong.com/maven/how-to-deploy-maven-based-war-file-to-tomcat/
and another
http://bitbybitblog.com/deploy-to-tomcat/
Some IDEs also have inbuilt functions that take care of this for you as well.