The Maven Archetype - Colon Speed ​​Mistake

I find it difficult to create a Maven archetype because of the presence of a colon (':') in one of the resources. I have Spring XML that includes this character:

<property name="maxSize" value="${ws.client.pool.maxSize:5}"/>

When starting the archetype, I get this error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate 
(default-cli) on project standalone-pom: 
org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: 
Encountered ":5}\"/>\n\t</bean>\n\t\n\t<bean id=\"fooServiceClient\" class=\"org.springframework.aop.framework.ProxyFactoryBean\">\n\t    <property name=\"targetSource\" ref=\"fooServiceClientPoolTargetSource\"/>\n\t</bean>\n\n</beans>\n" 
at line 15, column 69 of archetype-resources/src/main/resources/spring/library.ws-client.xml
[ERROR] Was expecting one of:
[ERROR] "}" ...
[ERROR] <DOT> ...
[ERROR] "(" ...
[ERROR] -> [Help 1]
[ERROR] 

I tried setting up the escape character in archtype pom:

    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-archetype-plugin</artifactId>
                <version>2.0</version>
            </plugin>
            <!-- Resources configuration -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <escapeString>\</escapeString>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

However, it still does not work. In this case:

<property name="maxSize" value="${ws.client.pool.maxSize\:5}"/>

the error is this:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate 
(default-cli) on project standalone-pom: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: 
Error merging velocity templates: 
Encountered "\\" at line 15, column 69 of archetype-resources/src/main/resources/spring/library.ws-client.xml
[ERROR] Was expecting one of:
[ERROR] "}" ...
[ERROR] <DOT> ...
[ERROR] "(" ...
[ERROR] -> [Help 1]
[ERROR] 

Any idea on how to avoid this colon?

+4
source share
2 answers

I developed a solution based on the Velocity variable ($ maxSize):

#set( $maxSize = '${ws.client.pool.maxSize:5}' )

<bean id="fooServiceClientPoolTargetSource" class="org.springframework.aop.target.CommonsPoolTargetSource">
    <property name="targetBeanName" value="fooServiceClientTarget"/>
    <property name="maxSize" value="$maxSize"/>
+2
source

Had the same error with the following Spring code for an additional property:

@Value("${hostname:}")
private String hostName;

Decision:

#set( $dollar = '$' )
@Value("${dollar}{hostname:}")
private String hostName;

The most important step is to transfer the reference to your constant $ {curly brackets}

+4

All Articles