资 源 简 介
Introduction
Microsoft introduced a nice concept in VS2005. t4 a template engine allows you to generate some code, xml or any other text-based compilation unit from ASP or PHP-like language.
Java has plenty of template engines but some are over-complicated and some
just not powerful enough, or better say I was not able to find one that worked for me in my current project, so I decided to create one.
Details
The idea is simple you write your template file like that
```
public class MyGeneratedClass{
<%%
for(int i = 0; i < 10; i++){
%> private int mVar<%=i %>;
public getMvar<%=i %>(){
return mVar<%=i %>;
}
public setMvar<%=i %>(int value){
this.mVar<%=i %> = value;
}
<%%
}
%>
}
```
Save it as template.java
And after you run
%JAVA_HOME%/bin/java -jar template.jar template.java=MyGeneratedClass.java
Y