如何在maven站点apt文件中使用点符号属性?

时间:2016-06-29 22:02:53

标签: maven velocity maven-site-plugin

maven网站插件http://maven.apache.org/plugins/maven-site-plugin/examples/creating-content.html#Filtering的文档建议使用$context访问带点符号的属性。 我的pom文件中有一个属性nexus.url。在.apt文件中使用$context.get("nexus.url")$context.get("parent.version")会产生解析错误:

[ERROR] Error parsing src/site/apt/readme.apt.vm as a velocity template, using as text.

使用-X标志运行mvn会发出此跟踪:

java.lang.RuntimeException: Exception when invoking public void org.apache.velocity.tools.generic.SafeConfig.configure(java.util.Map) on org.apache.velocity.tools.view.ViewContextTool@6a950a3b
at org.apache.velocity.tools.ToolInfo.invoke(ToolInfo.java:375)
at org.apache.velocity.tools.ToolInfo.configure(ToolInfo.java:294)
at org.apache.velocity.tools.ToolInfo.create(ToolInfo.java:255)
at org.apache.velocity.tools.Toolbox.getFromInfo(Toolbox.java:152)
at org.apache.velocity.tools.Toolbox.get(Toolbox.java:112)
at org.apache.velocity.tools.ToolContext.findTool(ToolContext.java:221)
at org.apache.velocity.tools.ToolContext.get(ToolContext.java:206)
at org.apache.velocity.context.InternalContextAdapterImpl.get(InternalContextAdapterImpl.java:219)
at org.apache.velocity.runtime.parser.node.ASTReference.getVariableValue(ASTReference.java:740)
at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175)
at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:294)
at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:318)
at org.apache.velocity.Template.merge(Template.java:254)
at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:508)
at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.renderDocument(DefaultSiteRenderer.java:354)
at org.apache.maven.doxia.siterenderer.DoxiaDocumentRenderer.renderDocument(DoxiaDocumentRenderer.java:51)
at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.renderModule(DefaultSiteRenderer.java:311)
at org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.render(DefaultSiteRenderer.java:129)
at org.apache.maven.plugins.site.render.SiteMojo.renderDoxiaDocuments(SiteMojo.java:261)
at org.apache.maven.plugins.site.render.SiteMojo.renderLocale(SiteMojo.java:172)
at org.apache.maven.plugins.site.render.SiteMojo.execute(SiteMojo.java:141)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)

Caused by: java.lang.NullPointerException
at org.apache.velocity.tools.view.ViewContextTool.configure(ViewContextTool.java:69)
at org.apache.velocity.tools.generic.SafeConfig.configure(SafeConfig.java:113)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.velocity.tools.ToolInfo.invoke(ToolInfo.java:363)

1 个答案:

答案 0 :(得分:0)

想出来。它适用于maven-site-plugin 3.5.1版。