Filtering java source files
Hi All, is there a way to filter the java source files ? I have a java class that contains the version of my application and I would like to set that value automatically to the one contained in the pom. I tried putting in my java file: private static final String VERSION = ${project.version}; and modifying my pom in order to have the java files in the resources: ... resource directorysrc/main/java/directory filteringtrue/filtering targetPathjava/targetPath /resource ... In this way, under target/generated-sources/java I have my java class with the right version, but now I have to compile it. I tried setting the sourceDirectory in the build section: ... build sourceDirectorytarget/generated-sources/java/sourceDirectory resources ... but it doesn't work because the compilation is performed before my java classes are copied in target/generated-sources/java. Any hint ? Thanks in advance Ste - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Filtering java source files
Why don't you just put your version in a standard properties file using maven's resource filtering (like you are trying to do with the java file) and have your class read it from there? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Filtering java source files
Yes, this was my first implementation, but it is really easy to update a jar file (in a production environment for instance) without increasing the version in the properties file so I would like to put the version in the source code. Tomislav Stojcevich wrote: Why don't you just put your version in a standard properties file using maven's resource filtering (like you are trying to do with the java file) and have your class read it from there? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Filtering java source files
Ah, I see what you are trying to do now. Although according to the maven lifecycle the resources should get processed before the compile. http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html so it should be working. I think you can get your end result by manually binding the resource plugin to the generate sources phase but it seems like a lot of extra work just to get a version in the file. Does your SCM tool provide keyword substitution upon commit? You might be able to have it inject the file's scm version. It won't be the same as your maven project version but if you have everything tagged in your SCM tool you should be able to map it back to a specific tag. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Filtering java source files
You are right...I checked the maven lifecycle and re-doing my tests, my first idea works ! I don't know why it didn't work, probably I did a lot of confusion during my attempts. Thanks a lot ste Tomislav Stojcevich wrote: Ah, I see what you are trying to do now. Although according to the maven lifecycle the resources should get processed before the compile. http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html so it should be working. I think you can get your end result by manually binding the resource plugin to the generate sources phase but it seems like a lot of extra work just to get a version in the file. Does your SCM tool provide keyword substitution upon commit? You might be able to have it inject the file's scm version. It won't be the same as your maven project version but if you have everything tagged in your SCM tool you should be able to map it back to a specific tag. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- () Stefano Nichele [EMAIL PROTECTED] _.._ Funambol Servers Tech Lead || || funambol :: mobile open source :: http://www.funambol.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Filtering java source files
maven-jar-plugin puts the version into a file META-INF/maven/groupid/artifactid/pom.properties have a look... easy to read out... On Monday 01 October 2007 05:18, Stefano Nichele wrote: Hi All, is there a way to filter the java source files ? I have a java class that contains the version of my application and I would like to set that value automatically to the one contained in the pom. I tried putting in my java file: private static final String VERSION = ${project.version}; and modifying my pom in order to have the java files in the resources: ... resource directorysrc/main/java/directory filteringtrue/filtering targetPathjava/targetPath /resource ... In this way, under target/generated-sources/java I have my java class with the right version, but now I have to compile it. I tried setting the sourceDirectory in the build section: ... build sourceDirectorytarget/generated-sources/java/sourceDirectory resources ... but it doesn't work because the compilation is performed before my java classes are copied in target/generated-sources/java. Any hint ? Thanks in advance Ste - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- Michael McCallum Enterprise Engineer mailto:[EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Filtering java source files
Thanks a lot for you hint. I'll try it... Do you think this is pretty stable ? I mean, in the next plugin version, could this change ? Ste Michael McCallum wrote: maven-jar-plugin puts the version into a file META-INF/maven/groupid/artifactid/pom.properties have a look... easy to read out... On Monday 01 October 2007 05:18, Stefano Nichele wrote: Hi All, is there a way to filter the java source files ? I have a java class that contains the version of my application and I would like to set that value automatically to the one contained in the pom. I tried putting in my java file: private static final String VERSION = ${project.version}; and modifying my pom in order to have the java files in the resources: ... resource directorysrc/main/java/directory filteringtrue/filtering targetPathjava/targetPath /resource ... In this way, under target/generated-sources/java I have my java class with the right version, but now I have to compile it. I tried setting the sourceDirectory in the build section: ... build sourceDirectorytarget/generated-sources/java/sourceDirectory resources ... but it doesn't work because the compilation is performed before my java classes are copied in target/generated-sources/java. Any hint ? Thanks in advance Ste - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- () Stefano Nichele [EMAIL PROTECTED] _.._ Funambol Servers Tech Lead || || funambol :: mobile open source :: http://www.funambol.com - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]