从 Maven 原型(prototype)创建项目时如何确定包名称?
我发现它是由创建项目时给定的groupId + src/main/java 之后的原型(prototype)中的路径组成的。 (如果我错了请纠正我)
示例:
具有 groupId it.foo.stub 的原型(prototype)文件夹树 src/main/java/service 创建包 it.foo.stub.service
对于一个包,我想将包名称的第一部分更改为类似 it.bar.mock.business 的名称,但直到现在我还没有找到答案如何。有可能吗?
最佳答案
您可以创建任何您想要的包。无论如何,包主要由目录定义。在您的 archetype-metadata.xml
文件中,您可以配置您的原型(prototype)以生成您想要的任何目录。这显示了如何在生成的项目中创建两个不同的包:
<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。
关于java - 从 Maven 原型(prototype)生成的项目中的包名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20403157/