Maven: create directory structure from pom.xml

Viewed 37950

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...

9 Answers

Open command line, change directory to the folder with the pom.xml
and past this into the CMD:

echo This will create all required folders for maven project.
echo creating  Application\Library sources
MD "src\main\java"
echo creating  Application\Library resources
MD "src\main\resources"
echo creating  Resource filter files
MD "src\main\filters"
echo creating  Web application sources
MD "src\main\webapp"
echo creating  Test sources
MD "src\test\java"
echo creating  Test resources
MD "src\test\resources"
echo creating  Test resource filter files
MD "src\test\filters"
echo creating  Integration Tests (primarily for plugins)
MD "src\it"
echo creating  Assembly descriptors
MD "src\assembly"
echo creating  Site
MD "src\site"

I use this one-liner:

touch pom.xml && mkdir -p src/main/java && mkdir -p src/main/resources && mkdir -p src/test/java && mkdir -p src/test/resources

It creates also an empty pom.xml. For quick access I've put it in my notes. Beside that it is similar @Matt answer.

as suggested by many answers from above, I find this to be the quickest

mkdir -p src/{main,test}/{java,resources}

which will generate the following structure

.
├── pom.xml
└── src
    ├── main
    │   ├── java
    │   └── resources
    └── test
        ├── java
        └── resources

Note how by passing the sub-directory names in curly braces, you generate more than 1 sub-directory. E.g. mkdir -p src/{dir1,dir2,dir3} will give you this:

.
└── src
    ├── dir1
    ├── dir2
    └── dir3
Related