Maven原型:js文件中的问题:“错误合并速度模板:遇到......”

时间:2015-05-13 13:57:29

标签: javascript maven maven-archetype

我在尝试从我的maven原型生成项目时遇到问题。当javascript文件未被解析时(即在archetype-metadata.xml文件中排除),一切都很好。但我需要在一些js文件中插入${MyProject}变量,因此不要排除我的项目js文件。

这是我的原型配置:(archetype-metadata.xml file)

<!-- Project Web Content -->
<fileSet filtered="true" packaged="false" encoding="UTF-8">
    <directory>src/main/webapp</directory>
    <excludes>
        <exclude>js/libs/**/*</exclude>
        <exclude>js/angular-mock/**/*</exclude>
        <exclude>template/**/*</exclude>
        <exclude>views/**/*</exclude>
        <exclude>img/**/*</exclude>
        <exclude>font/**/*</exclude>
        <exclude>icones/**/*</exclude>
        <exclude>css/**/*</exclude>     
    </excludes>
</fileSet>

以下是我在3个测试用例中遇到的不同错误(我试图在archetype-metadata.xml中排除一些我得到错误的文件):

Unable to create project from archetype [com.mypackage.archetypes:ngwis-project:2.0-SNAPSHOT]
    org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Encountered "}" at line 14, column 25 of archetype-resources/__rootArtifactId__Web/src/main/webapp/js/__rootArtifactId__/application.js
    Was expecting one of:
        "[" ...
        "{" ...
        <STRING_LITERAL> ...
        "true" ...
        "false" ...
        <INTEGER_LITERAL> ...
        <FLOATING_POINT_LITERAL> ...
        <IDENTIFIER> ...
        "{" ...

Unable to create project from archetype [com.mypackage.archetypes:ngwis-project:2.0-SNAPSHOT]
        org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Encountered "() { return item; },\r\n\t\t\t\t\t          columns : function() {  return scope.columns; },\r\n\t\t\t\t\t          service: function() { return scope.service; },\r\n\t\t\t\t\t          newItem: function() { return isNewItem; }\r\n\t\t\t\t\t        }\r\n\t\t\t\t\t      });\r\n\r\n\t\t\t\t\t\tmodalInstance.result.then(\r\n\t\t\t\t\t\t\tfunction (selectedItem) {\r\n\t\t\t\t\t\t\t\tscope.onclosemodal(selectedItem);\r\n\t\t\t\t\t\t\t\tscope.tableParams.reload();\r\n\t\t\t\t\t\t\t}, function () {\r\n\t\t\t\t\t\t\t\tconsole.log(\'Modal dismissed at: \' + new Date());\r\n\t\t\t\t\t\t\t});\r\n\t\t\t\t\t};\r\n\t\t\t\t\t\r\n\t\t\t\t\tscope.isSelectable = function() {\r\n\t\t\t\t\t\treturn scope.select && scope.select !== angular.noop;\r\n\t\t\t\t\t};\r\n\t\t\t\t\tscope.totalElements = 0;\r\n\t\t\t\t\tscope.hasElements = function () {\r\n\t\t\t\t\t\treturn (scope.totalElements > 0);\r\n\t\t\t\t\t}\r\n\t\t\t\t    scope.tableParams = new ngTableParams({\r\n\t\t\t\t        page: 1,            // show first page\r\n\t\t\t\t        count: scope.displayedLines, // count per page\r\n\t\t\t\t        filter : scope.filter || {},\t// filtering\r\n\t\t\t\t        sorting : scope.sort || {}\t\t//order by\r\n\t\t\t\t    }, {\r\n\t\t\t\t    \tcounts : [10, 25, 50, 100],\r\n\t\t\t\t        total: 0, // length of data\r\n\t\t\t\t        getData: function(" at line 143, column 66 of archetype-resources/__rootArtifactId__Web/src/main/webapp/js/__rootArtifactId__/directives/directives.js
        Was expecting one of:
            "," ...
            "}" ...


 Unable to create project from archetype [com.mypackage.archetypes:ngwis-project:2.0-SNAPSHOT]
    org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Encountered "(value) { \n\t\t" at line 16, column 41 of archetype-resources/__rootArtifactId__Web/src/main/webapp/js/__rootArtifactId__/controllers/controllers.js
    Was expecting one of:
        "," ...
        ")" ...

有什么想法吗? 感谢

1 个答案:

答案 0 :(得分:5)

我发现了问题,我与js文件中的$字符发生冲突:解析器使用$表示变量(例如$ {rootArtifactId})。解决方案是定义自己的变量${dollar}

#set( $dollar = '$' )

例如: $scope.$watch(...)必须替换为${dollar}scope.${dollar}watch(...)

必须使用#字符应用相同的提示。