Related
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 :)
I added my local tomcat 8.0.14 with eclipse successfully. My local tomcat is located at /Users/masum/tool/tomcat-8.0.14. I can see it form eclipse runtime Environment as well. Whenever I deploy any webapp to eclipse's tomcat. It doesn't appear in local tomcat-8.0.14/webapps directory. I expected it should go there. But it doesn't.
Also is I do any changes in tomcat/conf/server.xml. These changes doesn't effect in eclipse integrated tomcat. Also if local tomcat is running, port number conflicts with eclipse's tomcat. I have to stop local tomcat to work with eclipse tomcat. Looks like two different instance of tomcat.
My question is where does eclipse tomcat physically located? If I deploy any web app in eclipse tomcat where it actually goes? How can I configure Tomcat so that I can control it both from eclipse and also manually?
Thanks in advance.
Double click your tomcat server in the servers tab. In the servers tab you will see "Server path" under server locations. This is the location of eclipse's tomcat working directory. If you stop tomcat and undeploy all web apps, start and stop again, you will be able to select other options. Click "Use custom location" to set the location to a place of your choosing. In project Explorer you should see a tomcat folder. Under that folder you will find server.xml and the other config files, which you can modify as needed.
I build a Struts 2 + Hibernate web project using MyEclipse IDE.
When I run it in MyEclipse Tomcat environment it works fine ,but i want to run it on Tomcat server separately (means apart from MyEclipse ), so I export a .war file of project and deploy it on Tomcat manger - it is not working.
second issue is that when I copied my project from "My Eclipse\.metadata\.me_tcat\webapps\.." path and put it in tomcat webapps , but it is not working also - "HTTP Status 404 - /.." error occurred.
Is there any .jar file issue or something else?
If you are using MyEclipse you can deploy your application to the local server (not embedded). For this to work you should add a server on the Servers view and configure deploy configuration by right-clicking add deployment. There you can edit a context path that your application will run after deployment. You can use excellent Deploy button from the toolbar or the servers view. Note that MyEclipse copies files to the server, and you better not use "/" context path because in this case your webapps/ROOT folder will be overridden. If the application is deployed fine you can see in the logs the context path at which it has been started. Then you can access the application using this context path in the browser.
http://localhost:8080/yourappname/index.action
This url supposed to invoke the index action name, that should be configured in struts.xml. This is an example of index action
<action name="index">
<result>/index.jsp</result>
</action>
The second issue you should not copy/modify files in the metadata folder. This folder is used internally by MyEclipse unless you know what are you doing.
I have copied the sample.war file into the webapps directory of Tomcat, and I can access localhost:8080.
Now how will Tomcat deploy it, I mean do I need to open it in browser? How can I access the application?
You can access your application from: http://localhost:8080/sample
Deploying or redeploying of war files is automatic by default - after copying/overwriting the file sample.war, check your webapps folder for an extracted folder sample.
If it doesn't open properly, check the log files (e.g. tomcat/logs/catalina.out) for problems with deployment.
step-1. here I'm deploying pos.war First go to tomcat webapps folder and paste it
step-2. go to tomcat->bin folder start tomcat by clicking startup.bat
step-3. go to browser write localhost:port/project name eg. localhost:8080/pos (here my tomcat run on port 8080)
Done....
You just need to put your war file in webapps and then start your server.
it will get deployed.
otherwise you can also use tomcat manager a webfront to upload & deploy your war remotely.
Manual steps - Windows
Copy the .war file (E.g.: prj.war) to %CATALINA_HOME%\webapps ( E.g.: C:\tomcat\webapps )
Run %CATALINA_HOME%\bin\startup.bat
Your .war file will be extracted automatically to a folder that has the same name (without extension) (E.g.: prj)
Go to %CATALINA_HOME%\conf\server.xml and take the port for the HTTP protocol. <Connector port="8080" ... />. The default value is 8080.
Access the following URL:
[<protocol>://]localhost:<port>/folder/resourceName
(E.g.: localhost:8080/folder/resourceName)
Don't try to access the URL without the resourceName because it won't work if there is no file like index.html, or if there is no url pattern like "/" or "/*" in web.xml.
The available main paths are here: [<protocol>://]localhost:<port>/manager/html (E.g.: http://localhost:8080/manager/html) and they have true on the "Running" column.
Using the UI manager:
Go to [<protocol>://]localhost:<port>/manager/html/ (usually localhost:8080/manager/html/)
This is also achievable from [<protocol>://]localhost:<port> > Manager App)
If you get:
403 Access Denied
go to %CATALINA_HOME%\conf\tomcat-users.xml and check that you have enabled a line like this:
<user username="tomcat" password="tomcat" roles="tomcat,role1,manager-gui"/>
In the Deploy section, WAR file to deploy subsection, click on Browse....
Select the .war file (E.g.: prj.war) > click on Deploy.
In the Applications section, you can see the name of your project (E.g.: prj).
In addition to the ways already mentioned (dropping the war-file directly into the webapps-directory), if you have the Tomcat Manager -application installed, you can deploy war-files via browser too. To get to the manager, browse to the root of the server (in your case, localhost:8080), select "Tomcat Manager" (at this point, you need to know username and password for a Tomcat-user with "manager"-role, the users are defined in tomcat-users.xml in the conf-directory of the tomcat-installation). From the opening page, scroll downwards until you see the "Deploy"-part of the page, where you can click "browse" to select a WAR file to deploy from your local machine. After you've selected the file, click deploy. After a while the manager should inform you that the application has been deployed (and if everything went well, started).
Here's a longer how-to and other instructions from the Tomcat 7 documentation pages.
There are two ways:
Either you can do hot deployment (Hot deployment means deploying when server is running/up).
Or you can do cold deployment (Cold deployment means deploying when server is stopped).
Just use tomcat manager console for console deployment or simply copy and paste your application in webapp folder of your server's tomcat_home directory.
Note: Make sure if your war file size is more than 52 MB (the default configuration value),
you need to make two little changes in web.xml file of Manager application of your webapp folder(Manager application is provided by Apache tomcat by default upon installing the server).
Go to the web.xml of the manager application (for instance it could
be under /tomcat7/webapps/manager/WEB-INF/web.xml.
Increase the max-file-size and max-request-size values in web.xml file:
<multipart-config>
<!– 50MB max –>
<max-file-size>52428800</max-file-size>
<max-request-size>52428800</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
Increase the size by putting the values for <max-file-size> and <max-request-size> according to your requirement.
This has been working for me:
Create your war file (mysite.war) locally.
Rename it locally to something besides .war, like mysite.www
With tomcat still running, upload mysite.www to webapps directory.
After it finishes uploading, delete the previous version mysite.war
List the directory, watching for the directory /mysite to disappear.
Rename mysite.www to be mysite.war
List the directory, watching for the new /mysite to be created.
If you try uploading the new file as a war file, with tomcat still running, it will attempt to expand it before it is all there. It will fail. Having failed, it will not try again. Thus, uploading a www file, then renaming it, allows the whole war file to be present before tomcat notices it.
Hint, don't forget to check that the war file's owner is tomcat (Use chown)
If you installed tomcat7 using apt-get in linux then, deploy your app to /var/lib/tomcat7/webapps/
eg.
sudo service tomcat7 stop
mvn clean package
sudo cp target/DestroyTheWorldWithPeace.war /var/lib/tomcat7/webapps/
#you might also want to make sure war file has permission (`777` not just `+x`)
sudo service tomcat7 start
Also, keep tailing the tomcat log so that you can verify that your app is actually making peace with tomcat.
tail -f /var/lib/tomcat7/logs/catalina.out
The deployed application should appear in http://172.16.35.155:8080/manager/html
For deploying the war file over tomcat,
Follow the below steps :
Stop the tomcat. powershell->services.msc->OK->Apache Tomcat 8.5->stop(on left hand side).
Put the .war file inside E:\Tomcat_Installation\webapps i.e. webapps folder i.e. put.war (put.war is just an example)
After starting the tomcat(to start tomcat powershell->services.msc->OK->Apache Tomcat
8.5->start )
you will get one folder inside E:\Tomcat_Installation\webapps**put**
In this way you can deploy your war file in Apache Tomcat.
1.Generate a war file from your application
2. open tomcat manager, go down the page
3. Click on browse to deploy the war.
4. choose your war file.
There you go!
The application name goes into the context of your tomcat deployed URL,
eg. http://localhost:Port/applicationName.
If your application name is simple then, it should be http://localhost:8080/sample.
By default, Port is 8080, but if you wish to change it, or want to know the port where tomcat is running, simply go to server.xml file in <tomcat-apache-dir>/conf/server.xml, there you can find port & change,
eg. <Connector port="8080" redirectPort="8443" connectionTimeout="20000" protocol="HTTP/1.1"/>
If anything goes wrong, check the log files (e.g. <tomcat-apache-dir>/logs/catalina.out)
Perform the following steps:
Stop the Tomcat
Right Click on Project and click on "Clean and Build"
Go to your project Directory and inside Dist Folder you will get war file that you copy on your tomcat
webApp Folder
Start the tomcat
automatic war file extract and run your project
I followed the instruction in the following link, it works for me.
http://www.coderanch.com/t/487178/Tomcat/war-file-show-load
Stop Tomcat
Delete all the logs in tomcat/logs and all files in tomcat/conf/Catalina/localhost
Remove the war file and the directory it created (if it did) from tomact/webapps
Start Tomcat
While watching the logs, copy the war file to the webapps directory again
After this, keep an eye on the catalina.xxxx-xx-xx.log to find out the issue.
I have copied the sample.war file into the webapps directory of Tomcat, and I can access localhost:8080.
Now how will Tomcat deploy it, I mean do I need to open it in browser? How can I access the application?
You can access your application from: http://localhost:8080/sample
Deploying or redeploying of war files is automatic by default - after copying/overwriting the file sample.war, check your webapps folder for an extracted folder sample.
If it doesn't open properly, check the log files (e.g. tomcat/logs/catalina.out) for problems with deployment.
step-1. here I'm deploying pos.war First go to tomcat webapps folder and paste it
step-2. go to tomcat->bin folder start tomcat by clicking startup.bat
step-3. go to browser write localhost:port/project name eg. localhost:8080/pos (here my tomcat run on port 8080)
Done....
You just need to put your war file in webapps and then start your server.
it will get deployed.
otherwise you can also use tomcat manager a webfront to upload & deploy your war remotely.
Manual steps - Windows
Copy the .war file (E.g.: prj.war) to %CATALINA_HOME%\webapps ( E.g.: C:\tomcat\webapps )
Run %CATALINA_HOME%\bin\startup.bat
Your .war file will be extracted automatically to a folder that has the same name (without extension) (E.g.: prj)
Go to %CATALINA_HOME%\conf\server.xml and take the port for the HTTP protocol. <Connector port="8080" ... />. The default value is 8080.
Access the following URL:
[<protocol>://]localhost:<port>/folder/resourceName
(E.g.: localhost:8080/folder/resourceName)
Don't try to access the URL without the resourceName because it won't work if there is no file like index.html, or if there is no url pattern like "/" or "/*" in web.xml.
The available main paths are here: [<protocol>://]localhost:<port>/manager/html (E.g.: http://localhost:8080/manager/html) and they have true on the "Running" column.
Using the UI manager:
Go to [<protocol>://]localhost:<port>/manager/html/ (usually localhost:8080/manager/html/)
This is also achievable from [<protocol>://]localhost:<port> > Manager App)
If you get:
403 Access Denied
go to %CATALINA_HOME%\conf\tomcat-users.xml and check that you have enabled a line like this:
<user username="tomcat" password="tomcat" roles="tomcat,role1,manager-gui"/>
In the Deploy section, WAR file to deploy subsection, click on Browse....
Select the .war file (E.g.: prj.war) > click on Deploy.
In the Applications section, you can see the name of your project (E.g.: prj).
In addition to the ways already mentioned (dropping the war-file directly into the webapps-directory), if you have the Tomcat Manager -application installed, you can deploy war-files via browser too. To get to the manager, browse to the root of the server (in your case, localhost:8080), select "Tomcat Manager" (at this point, you need to know username and password for a Tomcat-user with "manager"-role, the users are defined in tomcat-users.xml in the conf-directory of the tomcat-installation). From the opening page, scroll downwards until you see the "Deploy"-part of the page, where you can click "browse" to select a WAR file to deploy from your local machine. After you've selected the file, click deploy. After a while the manager should inform you that the application has been deployed (and if everything went well, started).
Here's a longer how-to and other instructions from the Tomcat 7 documentation pages.
There are two ways:
Either you can do hot deployment (Hot deployment means deploying when server is running/up).
Or you can do cold deployment (Cold deployment means deploying when server is stopped).
Just use tomcat manager console for console deployment or simply copy and paste your application in webapp folder of your server's tomcat_home directory.
Note: Make sure if your war file size is more than 52 MB (the default configuration value),
you need to make two little changes in web.xml file of Manager application of your webapp folder(Manager application is provided by Apache tomcat by default upon installing the server).
Go to the web.xml of the manager application (for instance it could
be under /tomcat7/webapps/manager/WEB-INF/web.xml.
Increase the max-file-size and max-request-size values in web.xml file:
<multipart-config>
<!– 50MB max –>
<max-file-size>52428800</max-file-size>
<max-request-size>52428800</max-request-size>
<file-size-threshold>0</file-size-threshold>
</multipart-config>
Increase the size by putting the values for <max-file-size> and <max-request-size> according to your requirement.
This has been working for me:
Create your war file (mysite.war) locally.
Rename it locally to something besides .war, like mysite.www
With tomcat still running, upload mysite.www to webapps directory.
After it finishes uploading, delete the previous version mysite.war
List the directory, watching for the directory /mysite to disappear.
Rename mysite.www to be mysite.war
List the directory, watching for the new /mysite to be created.
If you try uploading the new file as a war file, with tomcat still running, it will attempt to expand it before it is all there. It will fail. Having failed, it will not try again. Thus, uploading a www file, then renaming it, allows the whole war file to be present before tomcat notices it.
Hint, don't forget to check that the war file's owner is tomcat (Use chown)
If you installed tomcat7 using apt-get in linux then, deploy your app to /var/lib/tomcat7/webapps/
eg.
sudo service tomcat7 stop
mvn clean package
sudo cp target/DestroyTheWorldWithPeace.war /var/lib/tomcat7/webapps/
#you might also want to make sure war file has permission (`777` not just `+x`)
sudo service tomcat7 start
Also, keep tailing the tomcat log so that you can verify that your app is actually making peace with tomcat.
tail -f /var/lib/tomcat7/logs/catalina.out
The deployed application should appear in http://172.16.35.155:8080/manager/html
For deploying the war file over tomcat,
Follow the below steps :
Stop the tomcat. powershell->services.msc->OK->Apache Tomcat 8.5->stop(on left hand side).
Put the .war file inside E:\Tomcat_Installation\webapps i.e. webapps folder i.e. put.war (put.war is just an example)
After starting the tomcat(to start tomcat powershell->services.msc->OK->Apache Tomcat
8.5->start )
you will get one folder inside E:\Tomcat_Installation\webapps**put**
In this way you can deploy your war file in Apache Tomcat.
1.Generate a war file from your application
2. open tomcat manager, go down the page
3. Click on browse to deploy the war.
4. choose your war file.
There you go!
The application name goes into the context of your tomcat deployed URL,
eg. http://localhost:Port/applicationName.
If your application name is simple then, it should be http://localhost:8080/sample.
By default, Port is 8080, but if you wish to change it, or want to know the port where tomcat is running, simply go to server.xml file in <tomcat-apache-dir>/conf/server.xml, there you can find port & change,
eg. <Connector port="8080" redirectPort="8443" connectionTimeout="20000" protocol="HTTP/1.1"/>
If anything goes wrong, check the log files (e.g. <tomcat-apache-dir>/logs/catalina.out)
Perform the following steps:
Stop the Tomcat
Right Click on Project and click on "Clean and Build"
Go to your project Directory and inside Dist Folder you will get war file that you copy on your tomcat
webApp Folder
Start the tomcat
automatic war file extract and run your project
I followed the instruction in the following link, it works for me.
http://www.coderanch.com/t/487178/Tomcat/war-file-show-load
Stop Tomcat
Delete all the logs in tomcat/logs and all files in tomcat/conf/Catalina/localhost
Remove the war file and the directory it created (if it did) from tomact/webapps
Start Tomcat
While watching the logs, copy the war file to the webapps directory again
After this, keep an eye on the catalina.xxxx-xx-xx.log to find out the issue.