从Maven原型生成的项目中的程序包名称 [英] Package names in project generated from Maven archetype
问题描述
从Maven原型创建项目时如何确定包名称?
How are the package names determined while creating a project from a Maven archetype?
我发现它是由创建项目时给定的groupId加上原型中src/main/java之后的路径组成的. (如果我错了,请纠正我)
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)
示例:
具有groupId it.foo.stub 的原型文件夹树src/main/java/service创建包 it.foo.stub.service
Archetype folder tree src/main/java/service with groupId it.foo.stub creates the package it.foo.stub.service
对于一个软件包,我想将软件包名称的第一部分更改为类似 it.bar.mock.business 的名称,但直到现在我仍无法找到如何.甚至有可能吗?
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?
推荐答案
您可以创建所需的任何程序包.无论如何,该软件包主要由目录定义.在您的archetype-metadata.xml
文件中,您可以配置原型以生成所需的任何目录.这显示了如何在生成的项目中创建两个不同的程序包:
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>
这假设您使用的是Maven Archetype 2.x.
This assumes you are using Maven Archetype 2.x.
这篇关于从Maven原型生成的项目中的程序包名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!