I have Maven a pom.xml file (copied from another project, and adapted), and I would like to generate the directory structure for a new project. Which command can do this?
Note that I found countless examples on the web, that explained how to use mvn archetype:create to create a pom.xml file and the directory structure, but I already have a pom.xml, and I would like to create the directories based on that, without specifying groupId, artifactId etc on the command line.
mvn archetype:create-from-project also seems to create a pom.xml based on another pom.xml (?) but I just want the directories. Thank you in advance!
EDIT: I am aware that this is not a "big problem" because I can create the directories manually :) I did it already many times, and I always felt that there must be a smarter way to do it...
maven-project/src/main – contains source code and resources that become part of the artifact. maven-project/src/test – holds all the test code and resources. maven-project/src/it – usually reserved for integration tests used by the Maven Failsafe Plugin.
Webapp. Maven project structure defines a folder in order to store all resources and files needed by a web application. Inside this folder you can put all the required files for a web application like jsp files, js files, html files, css files, template files, reports files, WEB-INF files (like web.
I agree that there should be a way to specify that maven itself should look at my pom and generate a project/dir structure from that. I don't know of a way to do that, but here's what I do:
Step 1: move your already created pom.xml somewhere else (maven will complain if you already have it in the directory where you will run the next command)
Step 2: from the command line, in your new maven project directory execute:
mvn archetype:generate -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -DgroupId=my.package.path -DartifactId=myartifact
You do have to edit groupId and artifactId to match your pom (sigh), but this creates the basic directory structure for you and a default Java class and Unit test.
Step 3: move/copy your pom.xml into that project directory
Step 4: run some maven command like mvn clean package
or mvn dependency:tree
to start downloading dependencies
Note: I'm including this answer because some of the previous answers recommend using mvn archetype:create
, but according to the maven website that goal is deprecated in favor of using generate
. And I wanted to show how to do it independent of any IDE or IDE plugins.
Not to sound condescending, but:
mkdir -p src/main/java mkdir -p src/main/resources mkdir -p src/test/java mkdir -p src/test/resources
(or feel free to substitute different directories).
I don't know of any maven command that will create this structure for you without creating a new pom file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With