Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace Maven Archetype property in JavaScript file

I'm trying to create a Maven Archetype for a Java web app and I have some JavaScript files I want it to generate. Is it possible to use Maven Archetype properties in the JavaScript file such that it will get replaced by the defined value at generation?

example.js

#set( $symbol_escape = '$' )
var name = "${artifactId}"

The above doesn't appear to work. I've tried other properties as well. It would seem it just isn't supported. Maybe due to collision possibilities with '$'?

The end resulting example.js file that is created just has the text "${artifactId}" instead of replacing it with the value of the property artifactId.

I'm using Maven Archetype plugin/extension version 2.2.

archetype-metadata.xml

...
<fileSet filtered="true" encoding="UTF-8">
  <directory>src/main/javascript</directory>
  <includes>
    <include>**/*.js</include>
  </includes>
</fileSet>

JS Path: src/main/javascript/my/package/name/example.js

like image 857
Nikordaris Avatar asked Sep 01 '25 17:09

Nikordaris


1 Answers

You should add a

<build>
 ...
    <resources>
        <resource>
            <directory>src/main</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.js</include>
            </includes>
        </resource>
    </resources>
 ...   

in your pom.xml

like image 113
Gambotic Avatar answered Sep 04 '25 07:09

Gambotic