What is the difference between Java projects having pom.xml and web.xml? Can projects have both these configurations at the same time?
They're completely compatible. As a matter of fact, they perform completely unrelated tasks.
pom.xml is the configuration file for Maven projects. One of its goals is to provide assistance in the compilation and building of a project when using Maven. You can think of it as an ant build.xml file or a makefile Make file if you're not familiar to Maven (actually, it can provide a lot more functionality)
web.xml is the Java EE web application deployment descriptor, where you specify for instance servlets, servlet mappings and other aspects of a webapp.
What is Maven from the Apache Maven site.
What is web.xml file and what all things can I do with it? question on SO.
The two files have nothing to do with each other.
pom.xml - Maven configuration file. Controls the build process for
the project
web.xml - Web application configuration file. Controls the deployment
and configuration of the web application
The POM file really shouldn't be deployed with the application, its just for the build process.
web.xml is an indicator that the project is running in some kind of servlet container (possibly even a full-fledged Java EE container).
pom.xml is an indicator that the project is built using the Maven build system.
Those two things are entirely orthogonal, so any given project can have none, one or both of them.
The Pom defines any dependancy libraries, it is part of Maven. This tells maven what jar files to download and store in the lib folder of your site.
Web xml is how your web project is configured.
They can both coexist as they do different things.
POM stands for "Project Object Model". It is an XML representation of a Maven project held in a file named pom.xml. http://maven.apache.org/pom.html
yes you can have both configurations at the same time.
The pom.xml is for configure your project with Maven.
The web.xml is use in all Java EE project under Tomcat for example.
You can use both, Maven is for compile and deploy your project, Tomcat is your server.
Related
My project generates a Jar as the output package and uses an external War file, available on our Artifactory, as the Web Application to be deployed on Tomcat (currently using version 7). This War file contains all libs and modules required for the application to run.
I have already packaged and ran those projects outside eclipse on a "vanilla" Tomcat installation. In this scenario, the Jar my project generates is loaded on the context.xml file this way:
<Loader className="org.apache.catalina.loader.VirtualWebappLoader" virtualClasspath="/home/igor/workspace/myapp/myapp-2.4.3.jar"/>
Is there a way I can deploy this project on Tomcat using Eclipse and still be able to debug it? Can I use the Jar generated for this purpose or do I have to deploy the workspace project?
As for the War file, do (or can) I have to add it as an dependency?
Thanks in advance!
EDIT
We actually provide an Web Framework, which is packaged as a war. Other applications that use that framework are exported as jars and loaded into the framework through the context file as cited above.
Your question is confusing probably because of your custom plugin/classloader and deployment which is sort of orthogonal to debugging.
What I recommend is you keep whatever system you have to build/package/deploy and use JVM remote debugging. That is do not use the Eclipse WTP since you seem to have custom steps for deployment but rather build your code deploy & run a separate Tomcat instance and then run the remote debugger in Eclipse.
You will get some hotcode swapping with this method but not as much as something like JRebel.. (which you could use also) it will certainly be better than constantly redeploying.
I have a Ear Project which includes two Appengine Dynamic Web Project and one shared java project (which has common classes).
I have added shared java project to EarContent Folder through Deployment assembly settings in EAR Project and i can see the java project jar file in published folder under EarContent folder.
Now i wanted to use the Ear library in Dynamic Web Project, so i have added this library in MANIFEST.MF setting for both the project and at compile time i can access the class from shared project too.
The problem is when i publish it, i couldn't able to find the java project jar in Both Web Project, i have tried almost every settings but nothing was helpful.
Am using Eclipse Mars, AppEngine SDK version 1.9.10,
Does any one tried this, is there any possible solution for my problem. any thoughts or suggestion is highly appreciated.
Thanks!
It looks like the Google Plugin for Eclipse doesn't recognize anything in EarContent/lib (or whatever your EAR library path is) regardless of settings when packaging the WAR files for each Dynamic Web Project. The JARs need to be physically present in WEB-INF/lib for each Dynamic Web Project in order for the modules to deploy properly.
I would recommend opening a feature request in the official issue tracker here:
https://code.google.com/p/googleappengine/wiki/FilingIssues
I have a spring project and using ANT to compile/deploy my war to Tomcat. So basically it just creates a war file and moves it to tomcat folder.
folder structure is this:
Spring
-src
ALL MY SRC (JAVA) files
-war
-WEB-INF
-jsp
-lib
ALL MY LIBRARIES
-properties
web.xml
spring-servlet.xml
-META-INF
build.xml
pom.xml // putting my pom.xml here
With ant I download all my libraries manually. Now as it seems, maven downloads all libraries automatically, thanks to pom.xml. Questions/problems:
Must I change my folder structure with maven?
Will maven include all downloaded libs to WAR? Is that default?
When maven downloads its WARS, can it put all libraries to WEB-INF/lib? How?
Does it make sense what I am doing, if no, then why?
Have few questions, because I have never ever used maven.
Yes better change the structure, see the maven site. It saves a bit of hassle, should you start using maven-plugins with complex things like using XSLT to generate java sources. Also IDE support might be better. Like:
src/main/java, src/test/java, src/main/resources.
Yes.
Yes. Automagically.
Yes otherwise you should use Ivy with ant.
Standard Maven Web Project Structure
As millimoose commented its better to go for standard project structure.
I have a J2EE application which has two web.xml files. One is called web.live.xml another is web.dev.xml. I am building this application with maven using profiles. So maven knows which file to choose when packaging.
I was wondering is it possible to make Eclipse use web.dev.xml when packaging my project and deploying it to Tomcat. This would be very useful because web.dev.xml sets some options which decrease start up time of the application.
You can designate the dev xml to be default (and name it web.xml). You can also have maven move (from a different folder) rather than rename.
You can use the Maven resources plugin (http://maven.apache.org/plugins/maven-resources-plugin/copy-resources-mojo.html) and configure it with a property in the profile and use that property in the configuration of the filename.
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.