WAR file can't be deployed on Tomcat 7 without wtpwebapps folder - java

I am facing a problem by deploying a War file on a Tomcat Server.
My Tomcat Server configuration as follows:
My steps to deploy:
I created a WAR file in Eclipse Kepler (Windows 7 64 bit, no Maven used).
Uploaded it with a Tomcat Web Application Manager.
Clicked deploy.
Tomcat unpacks WAR file in tomcat/webapps and throws me NullPointerException. It is missing some files that should be imported to project to work it right.
When I was working in Eclipse, as a source for these files I gave a workspace path, given in the Server settings and adding the wtpwebapps folder, which was offered by Eclipse by default. So my complete path looks like this:
C:\Users\myUserName\kepler\workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\myProjectName\WEB-INF\classes\project\fdsProject\FDS.prj
Now, when I deploy the project, it locates in a webapps folder, not in wtpwebapps and if I try to start in a browser, it shows me NullPointerException. But as soon as I copy the wtpwebapps folder from my workspace to the tomcat installation folder, near webapps, my project is starting successfully.
It means that I cannot start my project on another server, just deploying a standalone WAR file. I must add manually the wtpwebapps with my project in into the tomcat server installation folder. How can I optimize it and start project just with a WAR file deployed?
Thank you!
EDIT
My project structure is looking like this:

Stop the Tomcat Server
In the settings view Tomcat Server settings in Eclipse -> Server
Locations, check Use Tomcat Installation(...)
Now, you can change the Deploy Path, if you want webapps, then input it.
EDIT
The values below control how tomcat deal with war file
autoDeploy="true"
unpackWARs="true"
Just search these values in your server.xml file and edit values as you need.

If you want to be able to deploy your app as a WAR file, you need to refer to everything within it relative to the app itself, not with absolute file paths, not even as file paths if you can. If you have code that requires a java.io.File, rewrite it. The point is that you don't care where things are, you just care about how to get to their contents. For a Servlet, you can read anything on the web app's classpath by calling getResourceAsStream() on the correct class or classloader.
See getResourceAsStream() vs FileInputStream .

Related

tomcat is not autodeploying my .war file

i hope this is no duplicate. I allready searched for an answer, but did not find anything that fits.
I have a .war file called "app.war" and put it into the webapps folder of my tomcat. When i start tomcat, the .war file should actually be deployed, but it does not.
In my server.xml unpackWARs and autoDeploy is set to true. The tomcat service in the system is installed.
Does the content of the war file needs to have a special structure? I have the following structure:
I create the .war file with gradle by using "gradle build". My project structure is a typical maven java webapp structure.
Is there maybe anything missing in the war file? I have no more idea why the war file is not being deployed. What is also strange to me, is that when i unzip the war file in the webapps folder and restart my tomcat, the app won't be found by the tomcat.
Did you checked the permission of the war file and the webapps folder? Commonly tomcat is started by a user different to root , so , If you copied the file as root, the tomcat process never can access it .

How To Add An External Folder With Configurations To A Web Application In Eclipse

I created a normal Dynamic Web Project in Eclipse. I added a folder to the project, which shows up after refreshing the project. The folder is containing an XML-file with configurations for the applications.
When I deploy the application on the tomcat in eclipse, the relative pathes do not match anymore. I need to copy the folder in the catalina home directory and then it works.
Question
How can I add the folder to my project, that when I start tomcat (V7) in eclipse the folder is deployed as well and the relative pathes work too?
When the development comes to an end, I will export a WAR-File and deploy it on my server. It would be great, if then the configurations will be included as well.
If you have any questions or you need some further information, do not hesitate to ask nor to comment!
In the project's properties I have found where I can add the folder when I export the WAR-file. But it doesn't deploy in eclipse's tomcat yet. This part is still remaining.
I copied the configs-folder into the WebContent-folder and accorded the paths.
Now i have two configurations, one for my local execution and one for the execution on Tomcat after the deployment.
Important Advise
I needed to accord the filepaths starting from CATALINA's home directory.

How to deploy Java/Spring application on my own system in Apache tomcat server.?

Hello all master minds,
I have created a java spring application in eclipse with mysql db.
Now I can run this application using >Run on server in eclipse,but I want to know how to deploy this application on my own laptop(windows 7).
I have already configured server,by localhost://8080 I can see Apache tomcat is configured.
Give me simple steps so that i can just run that software using browser via its link like
http://localhost:8080/PMS
PMS is my project name.
Thanks in advance.
You can install tomcat-manager in order to deploy your war using a web interface: Tomcat 7 manager
Another option is to copy your war file into tomcat webapps folder. Your container will auto deploy your war: http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html#Deployment_With_Tomcat.
The easiest way, since you are using eclipse is to just export your project as war and then put that war (naming it PMS) in webapps directory in your tomcat.
Once started, Tomcat will deploy that war on http://localhost:8080/PMS
You have to do the following steps:
Right click on project>> Export (Export as WAR file).
or if you are using a maven project then you can give a maven build.
Copy that WAR file, (you will get that war file inside the project folder in your workspace) to the tomcat_Installed_Folder/ webapps
Inorder to deploy the app from outside eclipse,
goto tomcat_Installed_Folder/bin
and double click on startup.bat
then you could see a console.
For detailed logs of deployment, goto tomcat_Installed_Folder/logs
ALL THE BEST :)

Deploying a Dynamic Web Project with Tomcat

I currently have a working servlet created in Eclipse. When running it from the Tomcat plugin, everything works, and my app shows up at localhost:8080/project_name/. However, when I package the project into a .war file and place it in the /webapps directory of Tomcat and start the server, the servlet cannot be accessed. In Terminal, I can see Tomcat loading my project, and a temporary folder of the unarchived project is also created in /webapps. However, I simply cannot access my servlet.
Note:
I'm using Tomcat 7 and I don't have a web.xml file in my project.
How are you creating the war file? Check if your war files contain jar files under WEB-INF/lib folder and if the class files are not missing. You can easily verify it under tomcat/webapps/[project name] folder.

difference between wtpwebapps and webapps folder in tomcat

when I run my dynamic web project from eclipse it gets deployed to wtpwebapps. However I want to deploy a war file to tomcat so when I checked here in SO this came up
How to deploy a war file in Tomcat 7
It says I have to deploy to webapps folder in tomcat.
Can anybody please explain me the details between wtpwebapps folder and webapps folder in tomcat and also if I can deploy war files to wtwebpapps folder instead of webapps folder.
wtpwebapps is an eclipse-specific folder created when you run a dynamic web project on Tomcat within eclipse.
Webapps directory is within the Tomcat home and it's where you copy over your WAR files manually.
Recently, i've struggled with webapp strange behavior while debugging in Eclipse. I've noticed that it was double deployed.
My setup was:
web module with context path that differs from document base;
enabled autoDeploy in server.xml;
and deploy was set into webapps directory.
When checking tomcat-manager i've noticed that this webapp was deployed once with its context path name and once with document base name.
Here is what the documentation states (All credits goes to octopus, Tomcat docs):
If you want to deploy a WAR file or a directory using a context path that is not related to the base file name then one of the following options must be used to prevent double-deployment:
Disable autoDeploy and deployOnStartup and define all Contexts in server.xml
Locate the WAR and/or directory outside of the Host's appBase and use a context.xml file with a docBase attribute to define it.
And, i believe it's the main reason to use wtpwebapps instead of webapps for Tomcat with Eclipse.

Categories