質問

I have a Maven archtype that use a requiredProperty that contains a number, but the velocity variable are string. So, in my template I can't test if this property is greater than a number:

#if( $myVar gt 5 ) 

I have tested the following solution without success.

I've also tried this:

#set( $intVar = Integer.parseInt($myVar) )

That's also fail at the archetype generation.

Any advice?

役に立ちましたか?

解決

You can't reference classes from Velociy, so Integer.parseInt won't work. However, since in Java any static method can be called as an instance method, and Velocity is just Java in disguise, you can call parseInt on any integer. So you can try this trick:

#if ($myVar.length().parseInt($myVar) gt 5)

You're getting hold of an integer starting from the one variable that you're assuming you have, $myVar.

他のヒント

I have implemented user input validation based on a regular expression provided in the archetype descriptor :

https://issues.apache.org/jira/browse/ARCHETYPE-487

hopefully it will solve this issue for future versions of the maven archetype plugin.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top