Maven: create directory structure from pom.xml

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.


Analog to Matt's answer these lines will create the default maven folder structure on Microsoft Windows OS. Run them from the directory where your pom.xml exists:

mkdir -p src/main/java
mkdir -p src/main/resources
mkdir -p src/test/java
mkdir -p src/test/resources

I wonder why there is no maven command for this. You can either run the mkdir commands above, or use an archetype instead i.e. quickstart. There is the folder structure already in the box.


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.


It seems to me like you are making a big problem out of a little one.

I'd try using mvn archetype:create-from-project ... and then just replace the generated POM file with the original one.

And as Peter Lawrey suggests, a lot of modern IDEs are capable of creating a Maven project structure.