4

I am getting an issue while trying to generate a project from my maven archetype. Everything was alright when javascript files weren't parsed (i.e. exclude in the archetype-metadata.xml file). But I need to insert ${MyProject} variable in some js files and so not to exclude my project js files.

Here is my archetype configuration : (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>

Here are the different errors I get with 3 test cases (I tried to exclude in archetype-metadata.xmlsome files where I get the errros) :

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

Any idea ? Thanks

Truche
  • 523
  • 1
  • 5
  • 19
  • 1
    This question may help you: http://stackoverflow.com/questions/6828342/velocity-how-to-avoid-parseerrorexception-when-using-jquery Otherwise, post some more details of the portion where the merge fails. – Michael May 13 '15 at 14:10
  • Thanks Mikaveli, this helped me a bit to find the solution (describe below) – Truche May 18 '15 at 17:44

1 Answers1

7

I found the problem, I had conflict with $ characters from the js files : the parser uses $ for variables (like ${rootArtifactId} for example). The solution is to define your own variable ${dollar} :

#set( $dollar = '$' )

For example : $scope.$watch(...) must be replaced with ${dollar}scope.${dollar}watch(...)

The same tips must be applied with the # character.

Truche
  • 523
  • 1
  • 5
  • 19