Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Package names in project generated from Maven archetype

Tags:

java

maven

How are the package names determined while creating a project from a Maven archetype?

I figured out that it's composed by the groupId given while creating the project + the path in the archetype after src/main/java. (Correct me if I'm wrong)

Example:

Archetype folder tree src/main/java/service with groupId it.foo.stub creates the package it.foo.stub.service

For just a package I'd like to change the first part of the package name to something like it.bar.mock.business, but until now I haven't been able to find out how to. Is it even possible?

like image 443
Eugenio Laghi Avatar asked Dec 05 '13 14:12

Eugenio Laghi


1 Answers

You can create any package that you want. The package is mostly defined by the directory anyway. In your archetype-metadata.xml file you can configure your archetype to generate any directories you want. This shows how to create two different packages in generated projects:

<fileSets>
    <!-- Create a package using the groupId -->
    <fileSet filtered="true" encoding="UTF-8">
        <directory>src/main/java/__packageInPathFormat__</directory>
    </fileSet>
    <!-- Create a fixed package: it.bar.mock.business -->
    <fileSet filtered="true" encoding="UTF-8">
        <directory>src/main/java/it/bar/mock/business</directory>
    </fileSet>
</fileSets>

This assumes you are using Maven Archetype 2.x.

like image 111
David V Avatar answered Sep 23 '22 23:09

David V