【发布时间】:2021-04-22 05:23:37
【问题描述】:
因为我想使用原型创建一个多合一的项目,并通过 requiredProperty 删除一些文件和包, 我可以使用 Velocity 通过#if 显示一些代码,如下所示:
#if(${mysql})
interface ${table.mapperName} : ${superMapperClass}<${entity}>
#else
但文件或目录无法删除
我使用代码调用 JDK 方法来获取当前日期:
#set( $ldt = $package.getClass().forName("java.time.LocalDateTime").getMethod("now").invoke(null) )
#set( $dtf = $package.getClass().forName("java.time.format.DateTimeFormatter").getMethod("ofPattern", $package.getClass()).invoke(null, "yyyy/MM/dd HH:mm:ss") )
#set( $date = $ldt.format($dtf))
所以我认为可能可以调用文件 API 来获取当前目录并将其删除:
#set( $CurPath = $package.getClass().forName("java.nio.file.Paths").getMethod("get").invoke(".") )
#set( $CurPathStr = $CurPath.toAbsolutePath().normalize().toString() )
#set( $CurPathStrSys = $package.getClass().forName("java.lang.System").getMethod("getProperty").invoke("user.dir") )
但得到错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.2.0:generate (default-cli) on project standalone-pom: Error merging velocity templates: Invocation of method 'getMethod' in class java.lang.Class threw exception java.lang.NoSuchMethodException: java.nio.file.Paths.get() at archetype-resources/__rootArtifactId__-service/src/main/java/MainApplication.java[line 5, column 69] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
【问题讨论】:
-
原型旨在为项目类型创建特定模板...听起来您正在尝试与原型作斗争...
-
同意@khmarbaise,您最好为每种支持的技术创建一个单独的模板。原型在某种程度上是可定制的,但并不打算无限地如此。
-
那么会有很多类型原型,但是我想用它来自定义一些依赖和演示代码
标签: maven velocity archetypes