We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 year开发者_高级运维s ago.
Improve this questionI'm looking for a guide on how to create new maven archetypes that involve using parameters to create directories and file names where the parameters are used as prefixes in the file names and part of the package structure/directories that are created by the archetype.
All I can find is very simple instructions on how to make very simple projects.
why not use the maven website itself?
http://maven.apache.org/guides/mini/guide-creating-archetypes.html
I think I found the a site that helps me a little more once I figured out that Velocity templates are used as part of the archetype processes.
HowToCreateMavenArchetypeFromProject
I think we met the same problem, finally i resolved it with enlightening from this article
assuming you want to generate package com.company.base.dal.dao, we call com.company.base is root package, dal.dao is core package, then just put your template java file under src/main/java/dal/dao, and tweak the packaged="true"
in META-INF/maven/archetype-metadata.xml as below
<fileSet filtered="true" packaged="true" encoding="GBK"><!--packaged="true" tells maven to copy the core package in to root package while creating a project.-->
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
say, if you set -Dpackage=com.alibaba.china
after execute mvn archetype:generate, it will create java source package as com/alibaba/china/dal/dao/sample.java
as how to give the prefix package information in sample.java, just use ${package} as below
package ${package}.dal.dao;
the archetype plugin will replace ${package} with -Dpackage as velocity template
Even I am looking for the same thing. Even I find Maven home page very basic and does not fulfill our requirement.
I even tried HowToCreateMavenArchetypeFromProject But I still have one question. How to invoke a specific file of the archetype when the project of that type of archetype is generated. To be specific, if I have a java class App.java how to invoke that while creating project?
What happens with create-archetype-from-project is it creates a project of the same files and directory structure and we need to run that again to get that in action.
Also, ${groupId} and such stuff work only in maven files. What if I have a property file and wanna use the artifactId the user has entered?
Do let me know if you come across any good stuff. Meanwhile, I will also let you know when I find any solution.
Thanks
from the maven documentacion: http://maven.apache.org/archetype/archetype-models/archetype-descriptor/archetype-descriptor.html
A fileset defines the way the project's files located in the jar file are used by the Archetype Plugin to generate a project. If file or directory name contains property pattern, it is replaced with corresponding property value.
if you can name the file as
__artifactId___local.properties
... when you generate the proyect with artifactId=foo it will contains this file:
foo_local.properties
here is a short description but very helpful http://javajeedevelopment.blogspot.fr/2012/05/how-to-create-maven-archetype.html
精彩评论