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.
Related
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.
I am using Jetty eclipse plugin and generally other server will pick classes from /src/main/java folder,but in Jetty case its totally different its picking classes from the /target/classes folder .Is this right if yes then
How it will pick the properties file needed in web project?
Should i have to manually copy the dependent project jar file into the Jetty server lib directly ?
Jetty plugin i am using
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 "/")
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.
Where should I have my Java source folder in the Maven web application architecture which results in a WAR?
Suggestions needed.
Maven web applications typically do not include java source code. The maven approach is to create a maven project for the "logic" of your web application (this will build into a jar) and create a second maven project for the webapp portion of your web application (this will build into a war). Then in the webapp portion, you introduce a dependency on the "logic" portion.
The end result is that when you build / test your logic jar (which contains servlets, etc), you will deploy that to your local repository and then build your war (which contains jsp pages, web.xml configs, etc).
The basic structure that is standard for Maven project is the following.
src/main/java Application/Library sources
src/main/resources Application/Library resource
src/main/filters Resource filter files
src/main/assembly Assembly descriptors
src/main/config Configuration files
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/site Site
Following the Maven recommendations and normal behavior makes it easier for other people familiar with Maven to easy recognize and understand the structure.
Source/Read more
Unless you explicitly specify it differently in your pom.xml (productive) Java source files in a Maven project go to src/main/java.
Java files always go in src/main/java and its advised to keep it that way.