You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Andrew Williams <an...@handyande.co.uk> on 2007/08/13 16:26:02 UTC
Re: Generate Version class
You could configure the filtering to filter your java code as well as
standard resources, though I don't know if that is what you want.
Andy
On 22 Jul 2007, at 22:56, Francois Fernandes wrote:
> Hi list,
>
> for some time now I've been looking for a easy way to generate a
> simple class containing version information of our artifact. I know
> that it is possible to filter resources. But to avoid any resource
> loading issues I would like maven to generate such a class.
> Does anyone have a idea how to solve this? I'm sure that using
> resource filtering of a specific class template and then attaching
> the generated source(-folder) using the build-helper-maven-plugin,
> but is this a elegant way?
>
> thanks
>
> Francois
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Generate Version class
Posted by Michael McCallum <gh...@apache.org>.
You can load the pom properties off the class path so every maven built
artifact in your class path has version information.
Don't copy and paste this but it gives you the idea...
InputStream in
getClass().getResourceAsStream("META-INF/maven/path/to/pom.properties");
Properties p = new Properties();
p.load(in);
String version = p.getProperty("version");
Cheers
Michael
On Monday 20 August 2007 23:09, Tim Kettler wrote:
> Create a new directory (for example 'src/main/classtemplates') and put
> you class template under the correct package directory in there.
>
> Then declare a additional resource in your pom:
>
> [...]
> <resources>
> <resource>
> <directory>src/main/classtemplates</directory>
> <filtering>true</filtering>
> <targetPath>target/generated-sources</targetPath>
> </resource>
> </resources>
> [...]
>
> and use the buildhelper-maven-plugin from mojo.codehaus.org to declare
> the additional source directory, so the compile plugin picks it up:
>
> [...]
> <plugin>
> <groupId>org.codehaus.mojo</groupId>
> <artifactId>build-helper-maven-plugin</artifactId>
> <executions>
> <execution>
> <id>add-source</id>
> <phase>process-resources</phase>
> <goals>
> <goal>add-source</goal>
> </goals>
> <configuration>
> <sources>
> <source>target/generated-sources</source>
> </sources>
> </configuration>
> </execution>
> </executions>
> </plugin>
> [...]
>
> -Tim
>
> bakito schrieb:
> > How is this done? Can you please give an example. I can not get it
> > working using filtering java files like filtering resources.
> >
> > bakito
> >
> > Andrew Williams-5 wrote:
> >> You could configure the filtering to filter your java code as well as
> >> standard resources, though I don't know if that is what you want.
> >>
> >> Andy
> >>
> >> On 22 Jul 2007, at 22:56, Francois Fernandes wrote:
> >>> Hi list,
> >>>
> >>> for some time now I've been looking for a easy way to generate a
> >>> simple class containing version information of our artifact. I know
> >>> that it is possible to filter resources. But to avoid any resource
> >>> loading issues I would like maven to generate such a class.
> >>> Does anyone have a idea how to solve this? I'm sure that using
> >>> resource filtering of a specific class template and then attaching
> >>> the generated source(-folder) using the build-helper-maven-plugin,
> >>> but is this a elegant way?
> >>>
> >>> thanks
> >>>
> >>> Francois
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >>> For additional commands, e-mail: users-help@maven.apache.org
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: users-help@maven.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
--
Michael McCallum
Enterprise Engineer
mailto:gholam@apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Generate Version class
Posted by Andrew Williams <an...@handyande.co.uk>.
Though it is not exactly a best practice it is possible to filter the
source "in place" using just a <resources> configuration similar to
that posted (referencing src/main/java) - this would not require the
buildhelper plugin.
Andy
On 20 Aug 2007, at 12:09, Tim Kettler wrote:
> Create a new directory (for example 'src/main/classtemplates') and
> put you class template under the correct package directory in there.
>
> Then declare a additional resource in your pom:
>
> [...]
> <resources>
> <resource>
> <directory>src/main/classtemplates</directory>
> <filtering>true</filtering>
> <targetPath>target/generated-sources</targetPath>
> </resource>
> </resources>
> [...]
>
> and use the buildhelper-maven-plugin from mojo.codehaus.org to
> declare the additional source directory, so the compile plugin
> picks it up:
>
> [...]
> <plugin>
> <groupId>org.codehaus.mojo</groupId>
> <artifactId>build-helper-maven-plugin</artifactId>
> <executions>
> <execution>
> <id>add-source</id>
> <phase>process-resources</phase>
> <goals>
> <goal>add-source</goal>
> </goals>
> <configuration>
> <sources>
> <source>target/generated-sources</source>
> </sources>
> </configuration>
> </execution>
> </executions>
> </plugin>
> [...]
>
> -Tim
>
> bakito schrieb:
>> How is this done? Can you please give an example. I can not get it
>> working
>> using filtering java files like filtering resources.
>> bakito
>> Andrew Williams-5 wrote:
>>> You could configure the filtering to filter your java code as
>>> well as standard resources, though I don't know if that is what
>>> you want.
>>>
>>> Andy
>>>
>>> On 22 Jul 2007, at 22:56, Francois Fernandes wrote:
>>>
>>>> Hi list,
>>>>
>>>> for some time now I've been looking for a easy way to generate
>>>> a simple class containing version information of our artifact.
>>>> I know that it is possible to filter resources. But to avoid
>>>> any resource loading issues I would like maven to generate such
>>>> a class.
>>>> Does anyone have a idea how to solve this? I'm sure that using
>>>> resource filtering of a specific class template and then
>>>> attaching the generated source(-folder) using the build-helper-
>>>> maven-plugin, but is this a elegant way?
>>>>
>>>> thanks
>>>>
>>>> Francois
>>>>
>>>>
>>>> -------------------------------------------------------------------
>>>> --
>>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>>> For additional commands, e-mail: users-help@maven.apache.org
>>>>
>>>
>>> --------------------------------------------------------------------
>>> -
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Generate Version class
Posted by Tim Kettler <ti...@udo.edu>.
Create a new directory (for example 'src/main/classtemplates') and put
you class template under the correct package directory in there.
Then declare a additional resource in your pom:
[...]
<resources>
<resource>
<directory>src/main/classtemplates</directory>
<filtering>true</filtering>
<targetPath>target/generated-sources</targetPath>
</resource>
</resources>
[...]
and use the buildhelper-maven-plugin from mojo.codehaus.org to declare
the additional source directory, so the compile plugin picks it up:
[...]
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>target/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
[...]
-Tim
bakito schrieb:
> How is this done? Can you please give an example. I can not get it working
> using filtering java files like filtering resources.
>
> bakito
>
>
>
> Andrew Williams-5 wrote:
>> You could configure the filtering to filter your java code as well as
>> standard resources, though I don't know if that is what you want.
>>
>> Andy
>>
>> On 22 Jul 2007, at 22:56, Francois Fernandes wrote:
>>
>>> Hi list,
>>>
>>> for some time now I've been looking for a easy way to generate a
>>> simple class containing version information of our artifact. I know
>>> that it is possible to filter resources. But to avoid any resource
>>> loading issues I would like maven to generate such a class.
>>> Does anyone have a idea how to solve this? I'm sure that using
>>> resource filtering of a specific class template and then attaching
>>> the generated source(-folder) using the build-helper-maven-plugin,
>>> but is this a elegant way?
>>>
>>> thanks
>>>
>>> Francois
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org
Re: Generate Version class
Posted by bakito <ba...@gmx.net>.
How is this done? Can you please give an example. I can not get it working
using filtering java files like filtering resources.
bakito
Andrew Williams-5 wrote:
>
> You could configure the filtering to filter your java code as well as
> standard resources, though I don't know if that is what you want.
>
> Andy
>
> On 22 Jul 2007, at 22:56, Francois Fernandes wrote:
>
>> Hi list,
>>
>> for some time now I've been looking for a easy way to generate a
>> simple class containing version information of our artifact. I know
>> that it is possible to filter resources. But to avoid any resource
>> loading issues I would like maven to generate such a class.
>> Does anyone have a idea how to solve this? I'm sure that using
>> resource filtering of a specific class template and then attaching
>> the generated source(-folder) using the build-helper-maven-plugin,
>> but is this a elegant way?
>>
>> thanks
>>
>> Francois
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Generate-Version-class-tf4126624s177.html#a12232842
Sent from the Maven - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org