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

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.

Related

J2EE project with using classes from J2SE project [duplicate]

I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.
I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.
I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.
Am I missing something?
In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in /WEB-INF/lib of the deployed WAR.
You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.
Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.

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

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.

How do I deploy an unpacked maven project to Tomcat?

Per the Tomcat 7 documentation...
A web application is defined as a hierarchy of directories and files
in a standard layout. Such a hierarchy can be accessed in its
"unpacked" form", where each directory and file exists in the
filesystem separately, or in a "packed" form known as a Web ARchive,
or WAR file. The former format is more useful during development,
while the latter is used when you distribute your application to be
installed. (http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html)
The project I'm working with is a maven project (and must stay that way). I would like to simply put the project in my Tomcat webapps folder and run it from source (without doing a maven deploy) while I'm debugging/developing it. For production, I will use maven to build a war file for deployment. Is it possible to run a maven project from source? (without compiling to a war file?)
As Muel commented, you have to compile the files first, once you have all your files compiled, you can put it in any folder inside web apps (even ROOT, but should be empty), the app will use the folder name as context path (Except for ROOT that deploys in "/")

Configure: JRebel + External JBoss + Eclipse + Ant based deployment

I am trying to configure JRebel
Dev environment description:
Eclipse Juno IDE
JBoss 6.0.1 - Running externally from eclipse (same machine, not remotely)
Debugging: Remote, all hotswapping functionalities off
Ant script that: compiles, deploys and lifts target WAR to the JBoss
I have not used JRebel before, the configuration guide seemed pretty easy, but i am having troubles with my particular case.
All source (incl. jsps and images) is being compiled in project's bin folder.
Ant script creates WAR which holds separately JSPs, style, property files and compiled application classes are put inside dedicated jar in /web-inf/lib/ together with libraries. The script lifts the generated WAR to the JBoss and runs the server.
Where should i put my rebel.xml (i suppose in my project's bin folder?!) and what should i write into it in order to get jrebel-hotswapped the code changes inside the jar inside the war that is deployed in JBoss server.
I provided JBoss run script with necessary jrebel VM arguments.
Many thanks in advance!
rebel.xml should end up in WEB-INF/classes of your application. If you have dependencies in WEB-INF/lib folder, then every archive should have its own dedicated rebel.xml configuration file.
See the doc
If you deploy using Eclipse WTP, then it is fine to put it into source folder. But if you are using Ant to build the WAR, then you have to make sure that your Ant script will detect rebel.xml and copy it to the correct location.
The paths in the rebel.xml should point to the folder where the compiled classes are, i.e. the location where your IDE compiles these classes to.

configure eclipse, tomcat and maven to improve productivity in webapp

(Am a maven noob)
Have a maven built webapp which uses spring, etc.
When I run "mvn clean install", it generates a .war file in the target directory.
I copy the .WAR file to tomcat for deploying the app.
Debug the app
Edit the code
This process takes a lot of time. When I earlier used ant, I would point tomcat's server.xml to my webapps directory. Also, Eclipse would put all of its classfiles in my webapp\WEB-INF\classes folder. If I had to modify any JSPs, I would just edit and there was no need of additional copying. If I modified a .java file, Eclipse would build it and put the .class file in the WEB-INF\classes folder so that Tomcat would pick it up.
Now, each time I make changes to a .jsp, I need to manually copy the .jsp to tomcat's webapps directory. Isn't there a way that a maven built app can optimize this process ?
So, where do you point your tomcat at that makes development productive?
project (where pom.xml resides)
src
main
java
resources
webapp
WEB-INF
target
webapp
webapp.war
Basically, I would like to know how to configure eclipse(3.7.1) and tomcat/maven so that the edit/deploy/debug cycle is really fast.
UPDATE1
1) I was able to get m2e(http://download.eclipse.org/technology/m2e/releases/) installed in indigo(v. 3.7.1 of eclipse). it had 2 components
a) maven integration for eclipse
b) slf4j logging
It installed successfully asking me to restart eclipse. I restarted.
2) Next, I installed m2e-wtp (at http://download.jboss.org/jbosstools/updates/m2eclipse-wtp/)
It had 3 components
a) maven integration for eclipse
b) maven integration for eclipse Extras
c) maven integration for WTP.
When I selected all 3, I got some error. So, I unselected the 1st two and only selected the 3rd one and then it installed successfully asking me to restart eclipse. I restarted.
#Raghuram
I ran the 4 steps that you suggested below. Only the 4th step resulted in an error and my webapp could not get deployed. It resulted in an error "File not found --- .svn/.wcprops/.
http://i.imgur.com/Pg1aq.png
What should I make of it ?
Thanks again,
I'd recommend you to use cargo to deploy automatically to a local container (that can be downloaded and started)
Maven+Cargo
Then having that started with jpa activated (so that you can remotly debug your code) you just have to attach a listener and debug from eclipse, intellij, whatever.
For JSP, talking Intellij, you must tell your IDE where to package files (right-click 'package file") which is done in the project setup (output classes dir in WEB-INF/classes)
Check Tomcat 7 - Maven Plugin? for an example cargo configuration for Tomcat 7. After the confiuration is valid you can deploy to your Container using mvn cargo:deploy and mvn cargo:redeploy
If you use Eclipse Indigo with m2e and m2e-wtp, you can pretty much develop and debug your web application without any manual step.
Add tomcat as a server in Eclipse
Import your maven project as a maven project in Eclipse.
Build the project (using Eclipse or using maven)
Choose "Run as server...".
Eclipse will pretty much take care of hot deploying jsps as well as classes on changes.

Categories

Resources