0

I am trying to default some property values in a templated class and it looks like the velocity engine the maven archtype plugin is using is choking on the ':' with errors like:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:generate (default-cli) on project standalone-pom: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Encountered ":" at line 18, column 40 of archetype-resources/__modelName__/src/main/java/client/CandyClientConfig.java
[ERROR] Was expecting one of:
[ERROR] "}" ...
[ERROR] <DOT> ...
[ERROR] "(" ...
[ERROR] -> [Help 1]
[ERROR] 

I have tried several escape sequences and it complains about them all:

@Value("${candy.http.maxConnections\:100}")
@Value("${candy.http.maxConnections\\:100}")
@Value("${candy.http.maxConnections&#58;100}")

in the top of my archetype pom

#set($colon = ':')

then

@Value("${candy.http.maxConnections$colon100}")

This should be easily to beat. So, what am I missing?

Christian Bongiorno
  • 5,150
  • 3
  • 38
  • 76

2 Answers2

1

I faced the same issue in the past, the problem lies in the common syntax ${...} used by velocity and the java code.

Though I don't consider it a particularly elegant solution, I solved the problem as follows:

#set( $candy_http_max_connections_decl = '${candy.http.maxConnections:100}')
@Value("${candy_http_max_connections_decl}")

PS. To keep the code readable in case of many of such declarations in my source file, I kept the #set declarations close to their use (in the example, the line immediately above the @Value(...) annotation), instead of putting them at the beginning of the file as I would have normally done

chrx
  • 2,169
  • 5
  • 24
  • 45
0

If you address the '$' character instead of ':', like in :

#set( $dollar = '$' )

then

@Value("${dollar}{candy.http.maxConnections:100}")

it seems to work

chrx
  • 2,169
  • 5
  • 24
  • 45
  • actually, this solution had already been found in a similar thread see http://stackoverflow.com/questions/31201338/maven-archetype-velocity-error-because-of-a-colon?rq=1 (I noticed it after posting by following a link on "Related" section) – chrx Apr 21 '16 at 09:40