How do I run a .war file with tomcat/maven? - java

I'm new to tomcat and maven configuration. I was given a single .war that has all the dependencies in it. I'm trying to figure out how to run the war file on a given port configured using a pom.xml file
I tried mvn tomcat:run-war where the .war file lives but it obviously needs a pom.xml How can I configure this to be able to run this?

If you have already compiled project with all the dependencies in it then it has nothing to do with maven (because it's a tool for building projects from source code).
In order to deploy a war file you should install standalone tomcat on your system and drop the war file into webapps directory in the tomcat installation home folder, then (re)start tomcat. Give it 20-30 seconds to launch and open http://localhost:8080/war-file-name-without-dot-war in your browser, if everything went right then you will see the deployed application.

Related

IntelliJ IDEA Ultimate 2020.1.2 - Tomcat 8.5.55 - war file not in webapps dir

Am using IntellIJ IDEA Ultimate Edition 2020.1.2 and Tomcat 8.5.55 on macOS Catalina 10.15.5
Have setup a run configuration inside IntelliJ for Tomcat.
Am able to run Tomcat via IntelliJ IDEA and everything works (am able to run tomcat and see my webapp inside Google Chrome & see catalina.out via IntelliJ) but when I go to the webapps dir, I don't see the unpacked war file anywhere?
cd $CATALINA_HOME/webapps
ls
Directory listing:
ROOT docs examples host-manager manager
Question(s):
How can I setup / edit my Tomcat local run configuration to move the war file (whether exploded or not) inside $CATALINA_HOME/webapps?
Where is this IntelliJ generated war file located?
Configure the artifact output path to be under webapps directory.
In the artifact output directory.
Normally there is no need to change it, IntelliJ IDEA instructs Tomcat to deploy from the configured artifact output location.

Deploy a Maven project with a generated webapp folder to Apache Tomcat

I am trying to build/deploy/run this maven/apache tomcat project LODE.
It's quite the first time I see this style of java web applications. I Followed the instructions provided on the website of this project. Started with maven clean install. Then an src folder was generated with a java folder (containing java classes) and a webapp folder (containing web resources) See the photo.
I am used to having a structure where a WebContent folder is there and a WAR file can generated.
.
How to deploy this project into apache tomcat and get it to run?
Here is what I tried:
I tried generating a war file by editing the build section in pom.xml file. However, it did not work.
I tried to add the project to Apache Tomcat 9 in my eclipse IDE. However, Tomcat does not believe that this is a web project, so I cannot add it (using right click on Tomcat -> Add/Remove).
I tried to take the generated webapp folder and deploy it to Tomcat (without eclipse IDE --> tomcat manager 'http://localhost:8081/manager/html' --> Deploy Directory) after creating WEB-INF/classes folder and moving the source qualified packages from the generated src folder to this folder. This did not work because the java classes were missing (cannot find the java class/package error).
LODE's README clearly says how to lunch the application. Well you don't see a war thus can't deploy on tomcat server.
I found two ways to make it work:
mvn clean jetty:run from the terminal. This will just work fine (runs on the jetty server).
For tomcat server, add <packaging>war</packaging> in the pom.xml to generate the war. Then either rename the generated war manually (for example, LODE-1.3-SNAPSHOT.war to lode.war) or use maven plugins to generate the war name. Now deploy this war to your tomcat server as usual.

Web Deployment Assembly not used by Tomcat7

My understanding is when running tomcat inside of eclipse, during publishing... eclipse will copy files based on the settings in Web Deployment Assembly to tomcat directory. I added my app to Tomcat 7 thru Server --> "Add or Remove...", when I start tomcat, I don't see any files been copied to /usr/share/tomcat7/wtpwebapps/myapp folder. BTW, I have all the folder structure (folders) under tomcat directory, but missing all the files (like .class, .properties, .xml and ...). This is the error I am getting when start tomcat. BTW, the directory show in the pic is the directory under tomcat. I thought the publishing process copies files from eclipse to tomcat dir? It looks like it's trying to copy files from tomcat dir to somewhere else. What am I missing? My Server path and Deploy path are all correct.
It's a permission thing. Also I recommend install tomcat manually instead of running apt-get.
Either https://askubuntu.com/questions/17223/permissions-problem-when-copying-files-to-usr-share-tomcat6 or http://www.frattv.com/tomcat-can-t-start-from-ide-eclipse-luna-wtp-intellij-idea-in-ubuntu/ will work.

Unable to export non-jar files when web project is exported as a war file from Eclipse

I have developed a dynamic web application in Eclipse. I am using Tomcat as a server. In my lib folder I have placed one non-jar files( addressing.mar ). This file is necessary other wise I get an error in my application.
Now I export my project as war file and then deploy the project on Tomcat server. When I run the project I get an exception because addressing.mar cannot be found in the lib folder of the project. I don't know why addressing.mar isn't exported. If I manually place file in it, it is working, but I need a better solution.
Right click the project, open properties.
Under the Deployment Assembly page, you can configure what resources to include during export and their path in the WAR file. Just include your jar there and it will show up next time you export.

Different versions of war files using eclipse and maven

I have a mavenized web project which generates the war file. When I deploy this war file to the tomcat, it works fine. However, when I use eclipse to run the project on tomcat, it packages a different set of jars in the war and the deployment is unsuccessful. Would you have any pointers on how to get the same war file generated using eclipse as the one that i get using maven?
Thanks for the help
Right click on project
click on run as
click on run on server
set tomcat as your new runtime
then run
I hope it will help you.

Categories

Resources