You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Thomas Sundberg <ts...@kth.se> on 2012/07/21 10:13:08 UTC

Writing my own mojo - how do I specify a default goal?

Hi!

I am trying to write my own Maven plugin. I want to be able to specify
it in a build without specifying any additional parameters. I don't
seem to find any example after some googling. In a perfect world, I
would like to write my pom like this:

    <build>
        <plugins>
            <plugin>
                <groupId>se.somath</groupId>
                <artifactId>publisher-plugin</artifactId>
                <version>1.0-SNAPSHOT</version>
            </plugin>
        </plugins>
    </build>

That is, just specify that this plugin should be used.

At the moment I have to specify it like this:

    <build>
        <plugins>
            <plugin>
                <groupId>se.somath</groupId>
                <artifactId>publisher-plugin</artifactId>
                <version>1.0-SNAPSHOT</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>process</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Currently I have just one goal and it doesn't take any parameters.

This question might be better to send to the developers list, but I
don't follow that list and I assume that there are some mojo
developers following this list that might be able to assist me.

Thomas

-- 
Thomas Sundberg
M. Sc. in Computer Science

Mobile: +46 70 767 33 15
Blog: http://thomassundberg.wordpress.com/
Twitter: @thomassundberg

Better software through faster feedback

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Writing my own mojo - how do I specify a default goal?

Posted by Thomas Sundberg <ts...@kth.se>.
On 21 July 2012 20:51, Wayne Fay <wa...@gmail.com> wrote:
>>> Plugin that does not have execution defined but it still executes (as you
>>> say you'd want) is usually bound to lifecycle of the packaging in it's
>>> lifecycle mapping. So, unless you write your own packaging (I doubt this is
>>> what you need), you are left to declare plugin _with_ executions.
>>
>> But it is either a well guarded secret how to package a plugin so it
>> has knowledge about when it should be executed or impossible.
>
> There is no great conspiracy at work here. You simply fail to
> understand what is meant by the term "packaging." Tamás is not saying
> you need to package your plugin a particular way for this to work. He
> is literally talking about Maven's concept of a package (jar, war,
> ear, pom, etc) and how that determines the lifecycle which will be
> used and thus which plugins are bound to the build.

Yes, that was the part I failed to understand.

>
> Read more here:
> http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Packaging
>
> If you really want to do this, read Robert's links. It is nontrivial
> stuff but can certainly be done if this is truly what you require.

I have gotten it to work now and while preparing dinner I suddenly
understood what Tamas meant. The pointers Robert gave me was good and
got me in the right direction.

> Most people find this to be way more than they need and resort to
> providing a couple extra lines of configuration in their plugin
> declarations instead.

You are probably right. Adding the extra configuration makes it easier
to execute your own Mojo, but for some reasons I didn't want them
there. I ended up with an additional <extensions>true</extensions>
instead. I guess that's something I have to live with.

Thanks for your help!
Thomas

-- 
Thomas Sundberg
M. Sc. in Computer Science

Mobile: +46 70 767 33 15
Blog: http://thomassundberg.wordpress.com/
Twitter: @thomassundberg

Better software through faster feedback

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Writing my own mojo - how do I specify a default goal?

Posted by Wayne Fay <wa...@gmail.com>.
>> Plugin that does not have execution defined but it still executes (as you
>> say you'd want) is usually bound to lifecycle of the packaging in it's
>> lifecycle mapping. So, unless you write your own packaging (I doubt this is
>> what you need), you are left to declare plugin _with_ executions.
>
> But it is either a well guarded secret how to package a plugin so it
> has knowledge about when it should be executed or impossible.

There is no great conspiracy at work here. You simply fail to
understand what is meant by the term "packaging." Tamás is not saying
you need to package your plugin a particular way for this to work. He
is literally talking about Maven's concept of a package (jar, war,
ear, pom, etc) and how that determines the lifecycle which will be
used and thus which plugins are bound to the build.

Read more here:
http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Packaging

If you really want to do this, read Robert's links. It is nontrivial
stuff but can certainly be done if this is truly what you require.
Most people find this to be way more than they need and resort to
providing a couple extra lines of configuration in their plugin
declarations instead.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven-jar-plugin refuses to include META-INF/persistence.xml !

Posted by Aliaksei Lahachou <al...@gmail.com>.
Which packaging do have? Can you post your POM?
Am 21.07.2012 22:51 schrieb "Tommy Svensson" <to...@me.com>:

> Hello maven fans,
>
> I've become slightly balder today. I've been tearing my hair over why JPA
> keeps insisting it cannot find my persistence unit. Everything in my
> persistence.xml file is correct I've checked it over an over.
>
> I've just discovered that the problem is not in the JPA provider (tried
> both EclipseLink and OpenJPA), but in Maven!!!
>
> Maven just refuses to include META-INF/persistence.xml in the jar no
> matter what I do! It resides in src/main/resources/META-INF. After building
> it is also in target/classes/META-INF along with MANIFEST.MF, but it is
> missing in the jar file.
>
> I googled and someone suggested this (yes, I'm not alone with this
> problem):
>
>         <resources>
>             <resource>
>                 <filtering>false</filtering>
>                 <directory>${basedir}/src/main/resources</directory>
>                 <includes>
>                     <include>META-INF/persistence.xml</include>
>                 </includes>
>             </resource>
>         </resources>
>
> That however had no effect what so ever. Next I tried this:
>
>             <plugin>
>                 <artifactId>maven-jar-plugin</artifactId>
>                 <configuration>
>                     <includes>
>                         <include>META-INF/persistence.xml</include>
>                     </includes>
>                     <archive>
>
> <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
>                     </archive>
>                 </configuration>
>             </plugin>
>
> That didn't help either. Then I found at codehaus that this was a bug and
> that it was fixed in version 2.1 of the maven-jar-plugin. So I tried to add
> version to the plugin specification. Version 2.4 was the latest I found:
>
>             <plugin>
>                 <artifactId>maven-jar-plugin</artifactId>
>                 <version>2.4</version>
>                 <configuration>
>                     <includes>
>                         <include>META-INF/persistence.xml</include>
>                     </includes>
>                     <archive>
>
> <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
>                     </archive>
>                 </configuration>
>             </plugin>
>
> That didn't work either. I'm out of ideas and my fingers hurt from all the
> googling. Do anyone have any idea how to solve this truly annoying problem ?
>
> I can add that I'm also using the Apache Felix maven-bundle-plugin. I
> don't know if it can affect this behavior.
>
> Anyhow, any suggestions are appreciated. Currently I have to manually jar
> my project.
>
> Regards,
> Tommy Svensson
>
>

Re: maven-jar-plugin refuses to include META-INF/persistence.xml ! - Problem solved

Posted by Wayne Fay <wa...@gmail.com>.
>> Most likely the "bundle" packaging does not include META-INF for some
>> reason. I would talk to the Apache Felix people about this issue so
>> they can resolve it in their code.
>
> This is working as designed, as covered in the FAQ:

Thanks Stuart. This is a good thing to keep in mind for when future
felix users land here complaining about similar problems.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven-jar-plugin refuses to include META-INF/persistence.xml ! - Problem solved

Posted by Stuart McCulloch <mc...@gmail.com>.
On 12 Aug 2012, at 03:54, Wayne Fay <wa...@gmail.com> wrote:

>> I'm also using the Apache Felix bundle-plugin which allows for:
>> 
>>        <packaging>bundle</packaging>
> 
> This is not a packaging delivered by Apache Maven. Thus you can
> "blame" whoever is making this packaging available to you.
> 
>> That is, I can use either or of "bundle" or "jar" for packaging. However when i use:
>> 
>>        <packaging>bundle</packaging>
>> 
>> I don't get the META-INF/persistence.xml file in the jar.
> 
> Most likely the "bundle" packaging does not include META-INF for some
> reason. I would talk to the Apache Felix people about this issue so
> they can resolve it in their code.

This is working as designed, as covered in the FAQ:

   http://felix.apache.org/site/apache-felix-bundle-plugin-faq.html#ApacheFelixBundlePluginFAQ-WhenIbuildabundle%252Csomeclassesarebuiltin%2522target%252Fclasses%2522butthey%2527renotincludedinthefinaljar.

Not everything in target/classes ends up in the bundle by default (unlike jar) - the underlying bnd library will only pull what resources/packages you tell it to into the bundle. While the plugin attempts to generate reasonable defaults based on your source, it can't do this for generated resources such as this persistence.xml file (see last FAQ item). Instead you need something like:

   <Include-Resource>{maven-resources}, META-INF/persistence.xml=target/classes/META-INF/persistence.xml</Include-Resource>

Where {maven-resources} is a placeholder for the default detected resources, as described in the Include-Resource section of http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html

The raw format of bnd's Include-Resource instruction can be found at http://www.aqute.biz/Bnd/Format#include-resource

HTH

--
Cheers, Stuart

> Wayne
> 
> ---------------------------------------------------------------------
> 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: maven-jar-plugin refuses to include META-INF/persistence.xml ! - Problem solved

Posted by Wayne Fay <wa...@gmail.com>.
> I'm also using the Apache Felix bundle-plugin which allows for:
>
>         <packaging>bundle</packaging>

This is not a packaging delivered by Apache Maven. Thus you can
"blame" whoever is making this packaging available to you.

> That is, I can use either or of "bundle" or "jar" for packaging. However when i use:
>
>         <packaging>bundle</packaging>
>
> I don't get the META-INF/persistence.xml file in the jar.

Most likely the "bundle" packaging does not include META-INF for some
reason. I would talk to the Apache Felix people about this issue so
they can resolve it in their code.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven-jar-plugin refuses to include META-INF/persistence.xml ! - Problem solved

Posted by Mark Derricutt <ma...@talios.com>.
If you use the <packaging>bundle</packaging> style in your pom, then its bnd that does the actual jar creation, and NOT the traditional jar plugin.

We hit this same issue awhile ago when including compiled coffee-script into our jars, just putting them directly in target/classes doesn't "just work".

Mark

On 13/08/2012, at 2:29 AM, Tommy Svensson <to...@natusoft.se> wrote:

> I didn't know that the bundle-plugin affected jar:ing. I thought it just packaged things correctly under target and then the maven-jar-plugin did the rest. 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


RE: maven-jar-plugin refuses to include META-INF/persistence.xml ! - Problem solved

Posted by Martin Gainty <mg...@hotmail.com>.
from now on we're going to rely on you... as our BND expert!

Glad to hear that worked
Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.


> Subject: Re: maven-jar-plugin refuses to include META-INF/persistence.xml ! - Problem solved
> From: tommy@natusoft.se
> Date: Sun, 12 Aug 2012 16:29:18 +0200
> To: users@maven.apache.org
> 
> I pulled those parts out and replaced them with "..." to make the example smaller. I didn't think those parts relevant, but apparently they are since the following suggested by Stuart McCulloch does work:
> 
> 	<Include-Resource>{maven-resources}, META-INF/persistence.xml=target/classes/META-INF/persistence.xml</Include-Resource>
> 
> I didn't know that the bundle-plugin affected jar:ing. I thought it just packaged things correctly under target and then the maven-jar-plugin did the rest. 
> 
> I'm starting to realize that just assuming is probably a bad idea ...
> 
> /Tommy 
> 
> 12 aug 2012 kl. 03:54 skrev Martin Gainty <mg...@hotmail.com>:
> 
> > 
> > http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
> > 
> > I didnt see your  
> > Export-Package
> > Private-Package
> > Bundle-Activator
> > At execution time you will need to config the maven-bundle-plugin with configuration instructions such as what is here:
> > <build>
> >   <plugins>
> >     <plugin>    <!-- (2) START -->
> >       <groupId>org.apache.felix</groupId>
> >       <artifactId>maven-bundle-plugin</artifactId>
> >       <extensions>true</extensions>
> >       <configuration>
> >         <instructions>
> >           <Export-Package>com.my.company.api</Export-Package>
> >           <Private-Package>com.my.company.*</Private-Package>
> >           <Bundle-Activator>com.my.company.Activator</Bundle-Activator>
> >         </instructions>
> >       </configuration>
> >     </plugin>    <!-- (2) END -->
> >   </plugins>
> > </build> The Export-Package of com.my.company.api indicates
> > the plugin will copy the Log Service package into the resulting bundle JAR file and export to other bundles
> > The Private-Package of com.my.company.* indicates
> > the available package(s) to copy into the bundle but NOT export to other bundles
> > 
> > But if you really want total control of your bundle you'll want to learn BND
> > The *best* example of BND configuration and an explanation of BND supported attributes are located here
> > http://www.aqute.biz/Bnd/Bnd
> > 
> > Martin Gainty 
> > ______________________________________________ 
> > Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
> > 
> > Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
> > Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
> > 
> > 
> >> From: tommybsvensson@me.com
> >> Subject: Re: maven-jar-plugin refuses to include META-INF/persistence.xml ! - Problem solved
> >> Date: Sat, 11 Aug 2012 18:56:43 +0200
> >> To: users@maven.apache.org
> >> 
> >> I finally found the source of this problem! Or close to it at least. I have managed to get my META-INF/persistence.xml included in the jar, but I'm unsure what is to blame :-).
> >> 
> >> I'm also using the Apache Felix bundle-plugin which allows for:
> >> 
> >> 	<packaging>bundle</packaging>
> >> 
> >> This due to the following configuration:
> >> 
> >>           <plugin>
> >>               <groupId>org.apache.felix</groupId>
> >>               <artifactId>maven-bundle-plugin</artifactId>
> >>               <version>2.3.5</version>
> >>               <extensions>true</extensions>
> >>              ...
> >>               <configuration>
> >>                   <supportedProjectTypes>
> >>                       <supportedProjectType>jar</supportedProjectType>
> >>                       <supportedProjectType>bundle</supportedProjectType>
> >>                   </supportedProjectTypes>
> >>                   ...
> >>               </configuration>
> >>           </plugin>
> >> 
> >> That is, I can use either or of "bundle" or "jar" for packaging. However when i use:
> >> 
> >> 	<packaging>bundle</packaging>
> >> 
> >> I don't get the META-INF/persistence.xml file in the jar.
> >> 
> >> But when I change to:
> >> 
> >> 	<packaging>jar</packaging>
> >> 
> >> It is included! So my guess is that the maven-jar-plugin is affected by the packaging. The Felix bundle-plugin still works OK with packaging "jar" so I'll stick with that for now on.
> >> 
> >> /Tommy
> >> 
> >> 22 jul 2012 kl. 18:27 skrev Wayne Fay <wa...@gmail.com>:
> >> 
> >>>> I was hoping for a "Well, thats easy, just do ..." :-). But you are of course right
> >>>> Wayne, I need to isolate what is causing this. Thanks.
> >>> 
> >>> If META-INF/persistence.xml was not even showing up in target, then we
> >>> might be able to provide a simple "recipe" to solve it. But that is
> >>> not the case here. Come back and let us know when you solve it.
> >>> 
> >>> Wayne
> >>> 
> >>> ---------------------------------------------------------------------
> >>> 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: maven-jar-plugin refuses to include META-INF/persistence.xml ! - Problem solved

Posted by Tommy Svensson <to...@natusoft.se>.
I pulled those parts out and replaced them with "..." to make the example smaller. I didn't think those parts relevant, but apparently they are since the following suggested by Stuart McCulloch does work:

	<Include-Resource>{maven-resources}, META-INF/persistence.xml=target/classes/META-INF/persistence.xml</Include-Resource>

I didn't know that the bundle-plugin affected jar:ing. I thought it just packaged things correctly under target and then the maven-jar-plugin did the rest. 

I'm starting to realize that just assuming is probably a bad idea ...

/Tommy 

12 aug 2012 kl. 03:54 skrev Martin Gainty <mg...@hotmail.com>:

> 
> http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
> 
> I didnt see your  
> Export-Package
> Private-Package
> Bundle-Activator
> At execution time you will need to config the maven-bundle-plugin with configuration instructions such as what is here:
> <build>
>   <plugins>
>     <plugin>    <!-- (2) START -->
>       <groupId>org.apache.felix</groupId>
>       <artifactId>maven-bundle-plugin</artifactId>
>       <extensions>true</extensions>
>       <configuration>
>         <instructions>
>           <Export-Package>com.my.company.api</Export-Package>
>           <Private-Package>com.my.company.*</Private-Package>
>           <Bundle-Activator>com.my.company.Activator</Bundle-Activator>
>         </instructions>
>       </configuration>
>     </plugin>    <!-- (2) END -->
>   </plugins>
> </build> The Export-Package of com.my.company.api indicates
> the plugin will copy the Log Service package into the resulting bundle JAR file and export to other bundles
> The Private-Package of com.my.company.* indicates
> the available package(s) to copy into the bundle but NOT export to other bundles
> 
> But if you really want total control of your bundle you'll want to learn BND
> The *best* example of BND configuration and an explanation of BND supported attributes are located here
> http://www.aqute.biz/Bnd/Bnd
> 
> Martin Gainty 
> ______________________________________________ 
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
> 
> Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
> 
> 
>> From: tommybsvensson@me.com
>> Subject: Re: maven-jar-plugin refuses to include META-INF/persistence.xml ! - Problem solved
>> Date: Sat, 11 Aug 2012 18:56:43 +0200
>> To: users@maven.apache.org
>> 
>> I finally found the source of this problem! Or close to it at least. I have managed to get my META-INF/persistence.xml included in the jar, but I'm unsure what is to blame :-).
>> 
>> I'm also using the Apache Felix bundle-plugin which allows for:
>> 
>> 	<packaging>bundle</packaging>
>> 
>> This due to the following configuration:
>> 
>>           <plugin>
>>               <groupId>org.apache.felix</groupId>
>>               <artifactId>maven-bundle-plugin</artifactId>
>>               <version>2.3.5</version>
>>               <extensions>true</extensions>
>>              ...
>>               <configuration>
>>                   <supportedProjectTypes>
>>                       <supportedProjectType>jar</supportedProjectType>
>>                       <supportedProjectType>bundle</supportedProjectType>
>>                   </supportedProjectTypes>
>>                   ...
>>               </configuration>
>>           </plugin>
>> 
>> That is, I can use either or of "bundle" or "jar" for packaging. However when i use:
>> 
>> 	<packaging>bundle</packaging>
>> 
>> I don't get the META-INF/persistence.xml file in the jar.
>> 
>> But when I change to:
>> 
>> 	<packaging>jar</packaging>
>> 
>> It is included! So my guess is that the maven-jar-plugin is affected by the packaging. The Felix bundle-plugin still works OK with packaging "jar" so I'll stick with that for now on.
>> 
>> /Tommy
>> 
>> 22 jul 2012 kl. 18:27 skrev Wayne Fay <wa...@gmail.com>:
>> 
>>>> I was hoping for a "Well, thats easy, just do ..." :-). But you are of course right
>>>> Wayne, I need to isolate what is causing this. Thanks.
>>> 
>>> If META-INF/persistence.xml was not even showing up in target, then we
>>> might be able to provide a simple "recipe" to solve it. But that is
>>> not the case here. Come back and let us know when you solve it.
>>> 
>>> Wayne
>>> 
>>> ---------------------------------------------------------------------
>>> 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: maven-jar-plugin refuses to include META-INF/persistence.xml ! - Problem solved

Posted by Martin Gainty <mg...@hotmail.com>.
http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html

I didnt see your  
Export-Package
Private-Package
Bundle-Activator
At execution time you will need to config the maven-bundle-plugin with configuration instructions such as what is here:
 <build>
    <plugins>
      <plugin>    <!-- (2) START -->
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
          <instructions>
            <Export-Package>com.my.company.api</Export-Package>
            <Private-Package>com.my.company.*</Private-Package>
            <Bundle-Activator>com.my.company.Activator</Bundle-Activator>
          </instructions>
        </configuration>
      </plugin>    <!-- (2) END -->
    </plugins>
  </build> The Export-Package of com.my.company.api indicates
the plugin will copy the Log Service package into the resulting bundle JAR file and export to other bundles
The Private-Package of com.my.company.* indicates
the available package(s) to copy into the bundle but NOT export to other bundles

But if you really want total control of your bundle you'll want to learn BND
The *best* example of BND configuration and an explanation of BND supported attributes are located here
http://www.aqute.biz/Bnd/Bnd

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.


> From: tommybsvensson@me.com
> Subject: Re: maven-jar-plugin refuses to include META-INF/persistence.xml ! - Problem solved
> Date: Sat, 11 Aug 2012 18:56:43 +0200
> To: users@maven.apache.org
> 
> I finally found the source of this problem! Or close to it at least. I have managed to get my META-INF/persistence.xml included in the jar, but I'm unsure what is to blame :-).
> 
> I'm also using the Apache Felix bundle-plugin which allows for:
> 
> 	<packaging>bundle</packaging>
> 
> This due to the following configuration:
> 
>             <plugin>
>                 <groupId>org.apache.felix</groupId>
>                 <artifactId>maven-bundle-plugin</artifactId>
>                 <version>2.3.5</version>
>                 <extensions>true</extensions>
>                ...
>                 <configuration>
>                     <supportedProjectTypes>
>                         <supportedProjectType>jar</supportedProjectType>
>                         <supportedProjectType>bundle</supportedProjectType>
>                     </supportedProjectTypes>
>                     ...
>                 </configuration>
>             </plugin>
> 
> That is, I can use either or of "bundle" or "jar" for packaging. However when i use:
> 
> 	<packaging>bundle</packaging>
> 
> I don't get the META-INF/persistence.xml file in the jar.
> 
> But when I change to:
> 
> 	<packaging>jar</packaging>
> 
> It is included! So my guess is that the maven-jar-plugin is affected by the packaging. The Felix bundle-plugin still works OK with packaging "jar" so I'll stick with that for now on.
> 
> /Tommy
> 
> 22 jul 2012 kl. 18:27 skrev Wayne Fay <wa...@gmail.com>:
> 
> >> I was hoping for a "Well, thats easy, just do ..." :-). But you are of course right
> >> Wayne, I need to isolate what is causing this. Thanks.
> > 
> > If META-INF/persistence.xml was not even showing up in target, then we
> > might be able to provide a simple "recipe" to solve it. But that is
> > not the case here. Come back and let us know when you solve it.
> > 
> > Wayne
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> > 
> 
 		 	   		  

Re: maven-jar-plugin refuses to include META-INF/persistence.xml ! - Problem solved

Posted by Tommy Svensson <to...@me.com>.
I finally found the source of this problem! Or close to it at least. I have managed to get my META-INF/persistence.xml included in the jar, but I'm unsure what is to blame :-).

I'm also using the Apache Felix bundle-plugin which allows for:

	<packaging>bundle</packaging>

This due to the following configuration:

            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.5</version>
                <extensions>true</extensions>
               ...
                <configuration>
                    <supportedProjectTypes>
                        <supportedProjectType>jar</supportedProjectType>
                        <supportedProjectType>bundle</supportedProjectType>
                    </supportedProjectTypes>
                    ...
                </configuration>
            </plugin>

That is, I can use either or of "bundle" or "jar" for packaging. However when i use:

	<packaging>bundle</packaging>

I don't get the META-INF/persistence.xml file in the jar.

But when I change to:

	<packaging>jar</packaging>

It is included! So my guess is that the maven-jar-plugin is affected by the packaging. The Felix bundle-plugin still works OK with packaging "jar" so I'll stick with that for now on.

/Tommy

22 jul 2012 kl. 18:27 skrev Wayne Fay <wa...@gmail.com>:

>> I was hoping for a "Well, thats easy, just do ..." :-). But you are of course right
>> Wayne, I need to isolate what is causing this. Thanks.
> 
> If META-INF/persistence.xml was not even showing up in target, then we
> might be able to provide a simple "recipe" to solve it. But that is
> not the case here. Come back and let us know when you solve it.
> 
> Wayne
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 


Re: maven-jar-plugin refuses to include META-INF/persistence.xml !

Posted by Wayne Fay <wa...@gmail.com>.
> I was hoping for a "Well, thats easy, just do ..." :-). But you are of course right
> Wayne, I need to isolate what is causing this. Thanks.

If META-INF/persistence.xml was not even showing up in target, then we
might be able to provide a simple "recipe" to solve it. But that is
not the case here. Come back and let us know when you solve it.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: maven-jar-plugin refuses to include META-INF/persistence.xml !

Posted by Tommy Svensson <to...@natusoft.se>.
I was hoping for a "Well, thats easy, just do ..." :-). But you are of course right Wayne, I need to isolate what is causing this. Thanks.

/Tommy

22 jul 2012 kl. 05:30 skrev Wayne Fay:

>> Maven just refuses to include META-INF/persistence.xml in the jar no matter
>> what I do! It resides in src/main/resources/META-INF. After building it is also
>> in target/classes/META-INF along with MANIFEST.MF, but it is missing in the
>> jar file.
> 
> Try a very simple test...
> Run "mvn archetype:generate" (and pick maven-archetype-quickstart
> which is 205 for me). Specify whatever values when prompted.
> Then "mkdir src/main/resources/META-INF".
> Copy your persistence.xml file there.
> Run "mvn package" from the project directory.
> Then "cd target" and "jar -tvf blah-1.0-SNAPSHOT.jar | grep
> persistence" and see if it is in the jar.
> 
> If so, there *must* be some additional configuration which you are
> applying which is causing this to fail.
> 
> "mvn help:effective-pom" might be helpful in tracking this down more.
> I would remove as much configuration from your pom as possible while
> keeping the basic functionality you require.
> 
>> I can add that I'm also using the Apache Felix maven-bundle-plugin. I don't know
>> if it can affect this behavior.
> 
> No clue. If your test above works, I'd try to build things without
> this plugin and see if the problem goes away. If that works, I'd ask
> the Apache Felix team about it. Perhaps they are doing something funky
> which causes this file to not be included in your artifacts.
> 
> Wayne
> 
> ---------------------------------------------------------------------
> 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: maven-jar-plugin refuses to include META-INF/persistence.xml !

Posted by Wayne Fay <wa...@gmail.com>.
> Maven just refuses to include META-INF/persistence.xml in the jar no matter
> what I do! It resides in src/main/resources/META-INF. After building it is also
> in target/classes/META-INF along with MANIFEST.MF, but it is missing in the
> jar file.

Try a very simple test...
Run "mvn archetype:generate" (and pick maven-archetype-quickstart
which is 205 for me). Specify whatever values when prompted.
Then "mkdir src/main/resources/META-INF".
Copy your persistence.xml file there.
Run "mvn package" from the project directory.
Then "cd target" and "jar -tvf blah-1.0-SNAPSHOT.jar | grep
persistence" and see if it is in the jar.

If so, there *must* be some additional configuration which you are
applying which is causing this to fail.

"mvn help:effective-pom" might be helpful in tracking this down more.
I would remove as much configuration from your pom as possible while
keeping the basic functionality you require.

> I can add that I'm also using the Apache Felix maven-bundle-plugin. I don't know
> if it can affect this behavior.

No clue. If your test above works, I'd try to build things without
this plugin and see if the problem goes away. If that works, I'd ask
the Apache Felix team about it. Perhaps they are doing something funky
which causes this file to not be included in your artifacts.

Wayne

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


maven-jar-plugin refuses to include META-INF/persistence.xml !

Posted by Tommy Svensson <to...@me.com>.
Hello maven fans,

I've become slightly balder today. I've been tearing my hair over why JPA keeps insisting it cannot find my persistence unit. Everything in my persistence.xml file is correct I've checked it over an over. 

I've just discovered that the problem is not in the JPA provider (tried both EclipseLink and OpenJPA), but in Maven!!!

Maven just refuses to include META-INF/persistence.xml in the jar no matter what I do! It resides in src/main/resources/META-INF. After building it is also in target/classes/META-INF along with MANIFEST.MF, but it is missing in the jar file. 

I googled and someone suggested this (yes, I'm not alone with this problem):

        <resources>
            <resource>
                <filtering>false</filtering>
                <directory>${basedir}/src/main/resources</directory>
                <includes>
                    <include>META-INF/persistence.xml</include>
                </includes>
            </resource>
        </resources>

That however had no effect what so ever. Next I tried this:

            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <includes>
                        <include>META-INF/persistence.xml</include>
                    </includes>
                    <archive>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>

That didn't help either. Then I found at codehaus that this was a bug and that it was fixed in version 2.1 of the maven-jar-plugin. So I tried to add version to the plugin specification. Version 2.4 was the latest I found:

            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <includes>
                        <include>META-INF/persistence.xml</include>
                    </includes>
                    <archive>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>

That didn't work either. I'm out of ideas and my fingers hurt from all the googling. Do anyone have any idea how to solve this truly annoying problem ?

I can add that I'm also using the Apache Felix maven-bundle-plugin. I don't know if it can affect this behavior. 

Anyhow, any suggestions are appreciated. Currently I have to manually jar my project. 

Regards,
Tommy Svensson


Re: Writing my own mojo - how do I specify a default goal?

Posted by Robert Scholte <rf...@apache.org>.
I'd start with
http://www.sonatype.com/books/mvnref-book/reference/writing-plugins-sect-intro.html

And have a good look at  
http://www.sonatype.com/books/mvnref-book/reference/writing-plugins-sect-plugins-lifecycle.html#writing-plugins-sect-override-default-lifecycle

-Robert

Op Sat, 21 Jul 2012 17:13:46 +0200 schreef Thomas Sundberg <ts...@kth.se>:

> Hi!
>
> On 21 July 2012 10:45, Tamás Cservenák <ta...@cservenak.net> wrote:
>> You cannot have that, you need to bind the goal at least (and goal  
>> usually
>> have a "preferred" phase it will bind to).
>> Plugin that does not have execution defined but it still executes (as  
>> you
>> say you'd want) is usually bound to lifecycle of the packaging in it's
>> lifecycle mapping. So, unless you write your own packaging (I doubt  
>> this is
>> what you need), you are left to declare plugin _with_ executions.
>
> This is what I want. I want to package my plugin so that it knows
> which phase to execute in. It is also ok for my use case if the
> execution phase is impossible to change.
>
> But it is either a well guarded secret how to package a plugin so it
> has knowledge about when it should be executed or impossible.
>
> So, assuming that it is a matter of packaging, does anybody have any
> good pointers I could look at?
>
> /Thomas
>
>
>
>
>
>>
>> Thanks,
>> ~t~
>>
>> On Sat, Jul 21, 2012 at 10:13 AM, Thomas Sundberg <ts...@kth.se> wrote:
>>
>>> Hi!
>>>
>>> I am trying to write my own Maven plugin. I want to be able to specify
>>> it in a build without specifying any additional parameters. I don't
>>> seem to find any example after some googling. In a perfect world, I
>>> would like to write my pom like this:
>>>
>>>     <build>
>>>         <plugins>
>>>             <plugin>
>>>                 <groupId>se.somath</groupId>
>>>                 <artifactId>publisher-plugin</artifactId>
>>>                 <version>1.0-SNAPSHOT</version>
>>>             </plugin>
>>>         </plugins>
>>>     </build>
>>>
>>> That is, just specify that this plugin should be used.
>>>
>>> At the moment I have to specify it like this:
>>>
>>>     <build>
>>>         <plugins>
>>>             <plugin>
>>>                 <groupId>se.somath</groupId>
>>>                 <artifactId>publisher-plugin</artifactId>
>>>                 <version>1.0-SNAPSHOT</version>
>>>                 <executions>
>>>                     <execution>
>>>                         <goals>
>>>                             <goal>process</goal>
>>>                         </goals>
>>>                     </execution>
>>>                 </executions>
>>>             </plugin>
>>>         </plugins>
>>>     </build>
>>>
>>> Currently I have just one goal and it doesn't take any parameters.
>>>
>>> This question might be better to send to the developers list, but I
>>> don't follow that list and I assume that there are some mojo
>>> developers following this list that might be able to assist me.
>>>
>>> Thomas
>>>
>>> --
>>> Thomas Sundberg
>>> M. Sc. in Computer Science
>>>
>>> Mobile: +46 70 767 33 15
>>> Blog: http://thomassundberg.wordpress.com/
>>> Twitter: @thomassundberg
>>>
>>> Better software through faster feedback
>>>
>>> ---------------------------------------------------------------------
>>> 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: Writing my own mojo - how do I specify a default goal?

Posted by Thomas Sundberg <ts...@kth.se>.
Hi!

On 21 July 2012 10:45, Tamás Cservenák <ta...@cservenak.net> wrote:
> You cannot have that, you need to bind the goal at least (and goal usually
> have a "preferred" phase it will bind to).
> Plugin that does not have execution defined but it still executes (as you
> say you'd want) is usually bound to lifecycle of the packaging in it's
> lifecycle mapping. So, unless you write your own packaging (I doubt this is
> what you need), you are left to declare plugin _with_ executions.

This is what I want. I want to package my plugin so that it knows
which phase to execute in. It is also ok for my use case if the
execution phase is impossible to change.

But it is either a well guarded secret how to package a plugin so it
has knowledge about when it should be executed or impossible.

So, assuming that it is a matter of packaging, does anybody have any
good pointers I could look at?

/Thomas





>
> Thanks,
> ~t~
>
> On Sat, Jul 21, 2012 at 10:13 AM, Thomas Sundberg <ts...@kth.se> wrote:
>
>> Hi!
>>
>> I am trying to write my own Maven plugin. I want to be able to specify
>> it in a build without specifying any additional parameters. I don't
>> seem to find any example after some googling. In a perfect world, I
>> would like to write my pom like this:
>>
>>     <build>
>>         <plugins>
>>             <plugin>
>>                 <groupId>se.somath</groupId>
>>                 <artifactId>publisher-plugin</artifactId>
>>                 <version>1.0-SNAPSHOT</version>
>>             </plugin>
>>         </plugins>
>>     </build>
>>
>> That is, just specify that this plugin should be used.
>>
>> At the moment I have to specify it like this:
>>
>>     <build>
>>         <plugins>
>>             <plugin>
>>                 <groupId>se.somath</groupId>
>>                 <artifactId>publisher-plugin</artifactId>
>>                 <version>1.0-SNAPSHOT</version>
>>                 <executions>
>>                     <execution>
>>                         <goals>
>>                             <goal>process</goal>
>>                         </goals>
>>                     </execution>
>>                 </executions>
>>             </plugin>
>>         </plugins>
>>     </build>
>>
>> Currently I have just one goal and it doesn't take any parameters.
>>
>> This question might be better to send to the developers list, but I
>> don't follow that list and I assume that there are some mojo
>> developers following this list that might be able to assist me.
>>
>> Thomas
>>
>> --
>> Thomas Sundberg
>> M. Sc. in Computer Science
>>
>> Mobile: +46 70 767 33 15
>> Blog: http://thomassundberg.wordpress.com/
>> Twitter: @thomassundberg
>>
>> Better software through faster feedback
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>



-- 
Thomas Sundberg
M. Sc. in Computer Science

Mobile: +46 70 767 33 15
Blog: http://thomassundberg.wordpress.com/
Twitter: @thomassundberg

Better software through faster feedback

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: Writing my own mojo - how do I specify a default goal?

Posted by Tamás Cservenák <ta...@cservenak.net>.
You cannot have that, you need to bind the goal at least (and goal usually
have a "preferred" phase it will bind to).
Plugin that does not have execution defined but it still executes (as you
say you'd want) is usually bound to lifecycle of the packaging in it's
lifecycle mapping. So, unless you write your own packaging (I doubt this is
what you need), you are left to declare plugin _with_ executions.

Thanks,
~t~

On Sat, Jul 21, 2012 at 10:13 AM, Thomas Sundberg <ts...@kth.se> wrote:

> Hi!
>
> I am trying to write my own Maven plugin. I want to be able to specify
> it in a build without specifying any additional parameters. I don't
> seem to find any example after some googling. In a perfect world, I
> would like to write my pom like this:
>
>     <build>
>         <plugins>
>             <plugin>
>                 <groupId>se.somath</groupId>
>                 <artifactId>publisher-plugin</artifactId>
>                 <version>1.0-SNAPSHOT</version>
>             </plugin>
>         </plugins>
>     </build>
>
> That is, just specify that this plugin should be used.
>
> At the moment I have to specify it like this:
>
>     <build>
>         <plugins>
>             <plugin>
>                 <groupId>se.somath</groupId>
>                 <artifactId>publisher-plugin</artifactId>
>                 <version>1.0-SNAPSHOT</version>
>                 <executions>
>                     <execution>
>                         <goals>
>                             <goal>process</goal>
>                         </goals>
>                     </execution>
>                 </executions>
>             </plugin>
>         </plugins>
>     </build>
>
> Currently I have just one goal and it doesn't take any parameters.
>
> This question might be better to send to the developers list, but I
> don't follow that list and I assume that there are some mojo
> developers following this list that might be able to assist me.
>
> Thomas
>
> --
> Thomas Sundberg
> M. Sc. in Computer Science
>
> Mobile: +46 70 767 33 15
> Blog: http://thomassundberg.wordpress.com/
> Twitter: @thomassundberg
>
> Better software through faster feedback
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>