I developed a java program which runs on Apache Tomcat server.
At the moment i am running the program on eclipse.
My question is how can i run the program on the server as a Service, and without needing to enter Eclipse for it?
I am new ti this, so i am looking for directions.
And one more thing, i also have a program which include JSP pages, what is the process in this case?
Thanks.
What do you mean when you say enter eclipse for it. You can install tomcat on server where you want to run the program and deploy your application there. Once deployed you can start the tomcat and that should work. Tomcat should also serve as the JSP engine for your deployed application.
You need to Export the project as a WAR file. Right click on the project -> Export -> WAR File. You can then drop the war file in the webapps directory of Tomcat.
Related
I'm new to deployment, I've jar file as a package how should I go ahead for deployment in my prod server?
My prod server is basically an EC2 machine running on AWS
Shall I just run java - jar "jar file"? is this the practiced way for prod servers?
Shall I package .jar file to ear/war and deploy in tomcat/jboss server?
Help appreciated!
Both of the approaches you described are valid.
For small web APIs that include their own application server (e.g. Spark, Javalin, Spring Boot) on Linux servers, I start a screen session and run java -jar. This allows me to exit the SSH session (disconnect from the server) without terminating the program.
For other Spring applications that don't include an application server, I package the code into a WAR and copy it to an application server's deployment directory. For Tomcat, that's webapps. The application server can then read the WAR and spin up a running instance (assuming hot-deploy is enabled).
Tomcat in particular also has a web page where you can upload your WAR file to deploy it.
If you would that the program is still held run after disconnecting from SSH or closing the terminal in Linux. You can use this command:
nohup java -jar file.jar &
This is basically up to your preference and usual standard at your place. We have services in Docker that basically have exec java -jar param param... at the end of entry-point.sh script. You can run whole Tomcat, etc.
If you're using Spring Boot (which is a good idea), then java -jar is perfectly fine - you can use embedded Tomcat and skip installing dedicated application server (or, to be precise, servlet container).
Second approach is preferred over first in Jboss servers as things can be easily done through console.
You can control the deployment of the application on the servers.
If say you don't want to deploy the jar on all the servers part of cluster ,that can be taken care.
I am new to java web programming and eclipse-apache Tomcat. I have small login web-application which includes (one jsp page , one servlet class).
I want to configure/deploy this application on apache web application manager. I mean I don't want to run this application in eclipse. I hope you understand my point.
Whenever I run my server in eclipse it run successfully. But when I want to open apache default page by typing http://localhost:8080 or http://localhost:8080 to configure my app It wouldn't open.
Please advice me.
To deploy a web application on Tomcat, you need to first compile your web application into a WAR file. Then, take that WAR file (let's assume it's called "MyApp.WAR") and put that into the tomcat/webapps directory. Restart the tomcat service. Tomcat will extract that WAR to a folder in the webapps directory. After that, any request to localhost:8080/MyApp will go to your webapp.
Make sure you have java installed, and add JAVA_HOME to your environment variable. (it is the path to java installation directory for e.g. C:\Program Files\java\jdk-1.6)
i.e
JAVA_HOME=C:\Program Files\java\jdk-1.6
install TOMCAT from here "http://tomcat.apache.org/download-70.cgi"
make sure you do not install it in you "c:\program files" due to some permission issues.
Lets say you installed tomcat at "c:\webserver\apache-tomcat\" this is your CATALINA_HOME, add it to your environment variable
i.e CATALINA_HOME=c:\webserver\apache-tomcat\
to acess tomcat webapp manager you need to configure user in %CATALINA_HOME%\conf\tomcat-users.xml
Add a role and a user :
Have your WAR file ready with you (this is how you create WAR "How to make war file in Eclipse")
move your WAR file to "%CATALINA_HOME%\webapp" directory. lets say "TestWeb.WAR" is your application with index.jsp page in it.
Now go to your %CALALINA_HOME%\bin and launch the startup.bat file (you would be using startup.bat to start and shutdown.bat to stop tomcat)
once tomcat is up and running check http://localhost:8080 is working fine.
P.S. If port 80 is already in use then try configuring your tomcat to some other unused PORT here "http://www.mkyong.com/tomcat/how-to-change-tomcat-default-port/"
go to your browser type http://localhost:8080/TestWeb/index.jsp
now you can to lot of configuration to your web app like having a default page and all
Hope this help you !
Normally eclipse uses Tomcat as an eclipse project, hence it uses metadata.
Server > Double click on the tomcat server instance > Server Location > Select "Use Tomcat installation"
Update: Tested just now. Set Deploy path to webapps folder. Works fine :)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am using windows 7.
I have written a simple Spring3 Hello World using Eclipse and successfully run it using tomcat on my computer.
Now I have a Server which runs Linux.
I would like to run the project that I just wrote on my server. It has no GUI or anything of the kind so I can't simply start up eclipse and write the same project on the server.
How do I go about doing that? I am completely new to the whole java and Spring thing, and have absolutely no clue as to how to run my project on the server and be able to view it.
I have searched everywhere online trying to figure out how to put my project on the Server, but it seems like Spring isn't the most noob friendly, especially with its documentation. There doesn't seem to be any explanation on how to take your code from one computer and put it into another and make it work.
There doesn't seem to be any explanation on how to take your code from one computer and put it into another and make it work.
That's right, as it is not often considered "not a programmers job". Its not very related to the framework you're using (Java EE or Spring or whatsoever), instead it's more of an infrastructure thing (related to the operating system and application server that are being used). Nevertheless, it can be very useful to know how the process works.
Generally speaking there are two steps:
Packaging - If you use Maven, you simply run the mvn package command. Or using Eclipse, you can export your project as an WAR-file (Right-click your project, click Export, search for "WAR"). I would advice to use Maven, but that's a bit outside the scope of your question probably. Either way, this step will result in a WAR file.
Deployment - This is a bit harder. The WAR file from step 1 needs to be copied to the Linux server where the application must be ran, and then copied into a special directory where the application server looks for apps. If you're using Tomcat on the Linux machine as well, look for the Tomcat installation directory and find the 'webapps' subdirectory. Other application servers have other procedures / locations, though.
This is under the assumption that Tomcat was already set up for you on the Linux server, and that is running.
This has nothing to do with Spring and everything to do with packaging your application and deploying it in a Servlet container/HTTP server.
Setup Apache and Tomcat (or some other servlet container) on your linux server.
Package your Spring application as a war file (either with maven, ant, Eclipse, or some other build tool).
Drop the war file in the /webapps directory of your Tomcat installation.
Start Tomcat.
Well first you need to get tomcat 'http://tomcat.apache.org/download-70.cgi', and set it up on the linux server you are trying to deploy to.
Then you would export your project as a .war archive in eclipse (File -> Export -> war)
Copy the war file to your server, and copy it into TOMCAT_HOME/webapps
Start up tomcat and you should be able to access the application under localhost:8080/{APPNAME}, so if your war name is myapp.war the url will be localhost:8080/myapp
good luck!
Spring is just a 3rd party open source API. You can do without Spring and still be able to "run" your application on a server.
By "run", this means that your project must be placed in a directory in the server's filesystem, most of the time in the form of a WAR file.
I said most of the time, because if done correctly, you can actually put your project directory inside the server, and it will run without transferring it as a WAR file.
A WAR file is just an archive that has a standard directory structure so that it is readable and executable by the server.
Read the following link on how to package your project as a WAR:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.wst.webtools.doc.user%2Ftopics%2Fcwwarovr.html
And then just copy the WAR file to the TOMCAT_HOME/webapps folder.
Packaging
cd c:/my_project_directory/Web/
jar cvf web-archive-test.war .
Deployment
cd c:/my_project_directory/Web/
scp *.war
your_username#remote_linux_host:/some/remote_directory_where_tomcat_is_installed/webapps/
I have implemented a jetty-based servlet under eclipse.It runs fine under eclipse. Right now, I need to deploy it as a Web application. I would like to know the procedures of transplanting these java programs from Eclipse to a real Jetty-based web application. The system is a Linux box. Thanks.
Export your Web Application as a WAR file in Eclipse and copy the WAR to:
/usr/share/jetty/webapps
(or appropiate path on your Linux box)
Restart the Jetty server and voila.
Are there any free tools using which I can package my war (java web app) and tomcat as exe
We distribute our web application Kunagi as a .war, a debian package and also as a windows .exe. The windows versiont works as follows:
The .exe is created by a tool which exists on all windows machines, called iexpress. It is just an archive which is executable. On execution it extracts itself into a temporary directory and then executes a predefined command in this direcotry.
So wie pack a minimal embedded Tomcat (just 5 jars) into it, together with Katokorbo.
Katokorbo is a simple Swing application which downloads a war from the web and starts it with the embedded Tomcat. It also checks for new versions of the webapp on startup, asks the user if he wants to upgrade, starts a browser with the webapp and provides a gui to the user to view log output and for stopping the whole thing.
Maven can do that (http://maven.apache.org/) and I think Ant can too.