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.
Related
I have a question about using Apache Maven: I built a very simple Maven-based project. This works fine so far.
Now I want to make an executable JAR file from my target file. The problem here seems to be that the dependencies (external libraries) are not packaged together with my app.
I've already googled and found the maven-assembly-plugin. That actually does exactly what I want, but seems to be somewhat inflexible, since the dependencies are not automatically resolved and I can not specify file filters, etc. (or only with much effort over assembly.xml).
What I really like is the solution of spring-boot-maven-plugin, so automatically determine all linked JAR files and put in a lib folder. Now my little project is not a Spring application, so Spring Boot might not be suitable for me, right?
So what would interest me: Is there a way to get a similarly structured and executable JAR archive as spring-boot-maven-plugin builds?
Just use Maven Shade Plugin. It packages your dependencies inside your jar and you can specify the Java packages to exclude
I have compiled sources of java web application. I know that project uses maven, because there is pom.xml files inside .war file.
I want to know is it possible to re create maven project using .war file. I use Java Decompiler to get sources, but i do not know how to combine all folders and .java files as it was in original project.
Is there any tool or howto to do it automaticaly?
Here is sources directory tree structure
For information: I do not want to stole some project or code, it's just my work. There is some web app in our production that was done by other developers in 2007. Now we are supporting this projects, and i don't know why customers do not have sources.
Create a new project from scratch as explained in Maven - Guide to Webapps. Then find the src/main/java directory and create a directory structure that reflects packages of classes in the war. Move the resources to resources folder. Use the command mvn package to recreate the war.
You can follow following steps. If your pom.xml is proper
Create a folder say, project
Copy your source code files with package structure intact to project folder( Note: if subfolder should src /project/src .
Copy pom.xml
In eclipse File->Import->select Maven-> Existing maven projects-> select the folder(project)-> Follow the instruction
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.
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.
Does anyone have a skeleton build file that I can modify to war up an eclipse dynamic web project.
I need to war it up and make sure that all the libraries/servlets are in the right place.
Creating a deployable WAR file from Eclipse Project
[I'm going to be voted down because it doesn't directly answer your question, but alas...]
I am also using Eclipse WTP for my web projects but I want to keep my own structure (IMO code should be independent from the tools). Fortunately, you can define where the various assets are located by modifying the project's .settings/org.eclipse.wst.common.component file.