How do I deploy an unpacked maven project to Tomcat? - java

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 "/")

Related

Serve files using maven outside of project directory

I am working on an old project based on maven and node. I want to configure maven to use an external directory to serve files. I have done with apache tomcat to use that directory after deploying the war file generated by maven. but during development maven also need to configure to serve files from the directory, without including it during the war generation process.

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.

Modifying Java Paths when deploying WAR

I have a webserver that I developed in Eclipse with a local TomCat server. When developing, I often had to run scripts from the command line from my Java code. I just looked at the working directory that Java inside eclipse was working from (was in the Eclipse subdirectory somewhere) and put a ton of files and scripts in here.
Now when creating a WAR those paths are wrong. I'm just not sure how to integrate this all into my project correctly. Should I copy everything into the Eclipse project directory and make the Java 'home' path here - how can I set this up so that the WAR would work when deployed on a webserver?
Should I copy everything into the Eclipse project directory and make the Java 'home' path here - how can I set this up so that the WAR would work when deployed on a webserver?
That is a bad idea:
Since you can't change the "current directory" in a Java program, the only way to do that would be to "cd" to the Eclipse project directory and start Tomcat from there. Yuck!!
And that's conceptually wrong:
Suppose you had two WAR files created in two distinct Eclipse projects. An application cannot have two different "current" directories. It makes no sense.
What if you want to deploy to a Tomcat on a system that doesn't have the Eclipse projector available to it ...
The correct way to solve this is to put all of the requisite files into the WAR file, and then access them from your webapp codebase using either webapp relative file paths ... or via the classpath.
Yes, it will entail changing the code of your webapp, but it is the right approach.

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.

Eclipse(STS)/Maven integration issues

I am working on a fairly big project that uses maven for dependency management. As part of this we are using Maven profiles to build and replace certain properties files that differ between test/dev/production environments.
To perform a build I would execute a Maven:build using the correct profile and mavens reactor would then build the projects in the correct order and store the jars in the .m2 folder, eg the domain jar first, then the service jar (with the domain jar included in its jar as a dependency) etc. This leads to a war file eventually with all the correct libs required by the war to run.
When eclipse performs its default build that it performs everytime you save a file the jars are not built with any profile, just a regular build.
When I then push the final war file to the server and it is exploded when the server starts up (started and deployed through eclipse) I get in the lib folder all the jars that maven had packaged into the war file but also all the jars that eclipse had built.
eg
lib/
domain.jar (built by eclipse)
domain.SNAPSHOT.1.0.jar (built by maven)
etc
Is there any way to prevent this from happening? This has the end consequence of there being two of every property file and only the order in which they are loaded determines which is used. A real hassle as different properties are used in different environments.
I found a slightly hacky solution to this problem.
In the web projects properties -> Deployment Assembly I modified the path for the offending jar files eg domain.jar from
WEB-INF/lib/domain.jar
to
WEB-INF/autogen/domain.jar
This leads to the eclipse generated jar files (with the wrong properties files) to be deployed to a folder that won't be loaded when tomcat starts. Not a perfect solution but it allows all the nice things of eclipse auto-building like code completion and error messages in the web project if the interface of the domain changes etc while also providing the correct profile when deployed.
Leaving this here for anyone else in this situation.

Categories

Resources