Maven 原型:js 文件中的问题:"Error merging velocity templates: Encountered ..."

Maven archetype : Issue in js files : "Error merging velocity templates: Encountered ..."

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

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

<!-- 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:
        "," ...
        ")" ...

有什么想法吗? 谢谢

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

#set( $dollar = '$' )

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

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