Maven: create directory structure from pom.xml

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

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.

Introduction to the Standard Directory Layout, default-maven-directory-structure. 4) Create source folders manually [Yeh !! Need to do it manually]. add-new-folders-in-maven-web-project. 5) Update project  This allows the module to inherit the groupId and / or the version of its parent POM. Example 2 The Scenario. However, that would work if the parent project was already installed in our local repository or was in that specific directory structure (parent pom.xml is one directory higher than that of the module's pom.xml).

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.

Maven - Create java source folders, Directory layout. Pom file. The pom (Project Object Model) file is a maven special file that describe how the project have to be build and from  Examples. We can override these elements in the project’s pom.xml and force Maven to adapt to a different directory structure. To Mavenize a project that follows Eclipse IDE project structure and without any unit tests, add the following snippet to the build element of pom.xml.

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.

Maven Project Structure Example, Apache Maven is one of the most popular build tools for Java projects. A typical Maven project has a pom.xml file and a directory structure  The pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of information required to build a project in just the way you want. It is a single configuration file that contains the majority of information required to build a project in just the way you want.

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.

Apache Maven Standard Directory Layout, A set of directory elements live in the build element of Super POM, which in the project's pom.xml and force Maven to adapt to a different directory structure. Create the folder structure manually 🙂 we can declare maven-eclipse-plugin in file pom.xml to avoid typing the parameter “-Dwtpversion=2.0” when use

Use the Maven Build Helper plugin. Usage is pretty straightforward. Just configure in the plugins section of your pom, and call the appropriate mvn goal(s).

From the documentation:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.10</version>
        <executions>
          <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>add-source</goal>
            </goals>
            <configuration>
              <sources>
                <source>some directory</source>
                ...
              </sources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

Manage Directories, The content of the pom, the default files, and the directory structure depends on the what archetype container was built. To create a simple java  Having a common directory layout allows users to be familiar with Maven project from one to another. Maven defines a standard directory structure. - src - main - java - resources - webapp - test - java - resources - target The src directory is the root directory of source code and test code.

QuickTip : Generating project structure using Maven, Maven - Directory Structure (Project) Maven relies on the Standard Directory Layout Articles Related Standard project structure A standard project ${basedir} |-​- pom.xml <build> <sourceDirectory>${basedir}/src/main/java</sourceDirectory​>  Sample structure for a maven multimodule project. Contribute to jabbrwcky/sample-maven-structure development by creating an account on GitHub.

Maven - Directory Structure (Project) [Gerardnico, In example below, we'll create a maven based java application project in C:\MVN folder. Let's open the command console, go to the C:\MVN directory and execute the following mvn command. Maven will start processing and will create the complete java application project structure. contains src folder and pom.xml. 2. Maven uses archetype plugins to create projects. To create a simple java application, we'll use maven-archetype-quickstart plugin. In example below, we'll create a maven based java application project in C:\MVN folder. Let's open the command console, go to the C:\MVN directory and execute the following mvn command.

Maven - Creating Project, Maven defines a standard directory structure. - src - main - java target, The target directory is used to store all output of the build. LICENSE.txt At the top of the project root there are pom.xml file and any properties, maven.xml. In addition​  Maven Directory Structure Maven has own standard for directory structure to create in a project. So we no need specify any directory on the project level for sources, resources, tests, plugins etc. And also we don’t need to configure for creating directory structure on the pom.xml file it is internal functionality of maven.

Comments
  • I use an IDE to build the project structure. It generates the maven poml. from a template and the directories required. It also sets the parent pom when adding modules.
  • I use Idea, and after "New Project" I select import from Maven. This set up the pom.xml and the libraries, but did not create the maven-speciofic directory structure.
  • It only creates the directories if you use it to create the pom.xml as well.
  • Yes, if I use Idea to create a new project with a "maven module", then it creates the directories, but then I have to specify the groupId, artifactId myself (and copy manually all the dependencies and settings), so this is not easier than mvn archetype:create.
  • The problem is that it is not different... Creating archetypes seems overkill to me... I would like more than a solution, I would like a simple solution :)
  • Yes, I thought of this solution (actually I did it already too many times) but could not believe that there is no maven-supported way... Suppose some non-standard directories are configured in pom.xml... Anyway, if there will be no better answers, I will accept this one :)
  • Not the answer I was hoping for, but it seems that there is no better one.
  • this doesn't answer the question at all
  • Or the following mkdir: mkdir -p src/{main,test}/{java,resources}
  • missing a bunch of stuff my friend. maven.apache.org/guides/introduction/…