You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Gary Aitken <ma...@dreamchaser.org> on 2017/01/20 04:49:45 UTC

generated resources not in target jar

I'm having trouble getting resources generated post-compile into the final
jar package (packaging type jar).

During the process-classes phase, I run a task which reads some xml files 
and produces other xml files.  I can't figure out how to get the output 
xml files into the jar.

Issues:

1. The output is written into target/xmldata,
   but the xmldata subtree is not written into the jar.
   I also tried generating into target/resources/xmldata

2. I tried the following in the <build> section of pom.xml:
    <resources>
      <resource>
        <directory>${generated-xml.dir}</directory>
        <excludes>
          <exclude>${generated-src-xml.dir}</exclude>
        </excludes>
      </resource>
    </resources>

3. I also tried adding an 
        <includes>
          <include>**_consolidated.xml</include>
        </includes>
   to the above <resource> section; no luck.

Hints?
Thanks,
Gary

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


Re: generated resources not in target jar

Posted by Anders Hammar <an...@hammar.net>.
Typically, a plugin that generates sources/resources during build should
add that output folder to the project model. It's not something that you
should do. However, if you do this the homebrewed way (e.g. antrun plugin)
it's not added automatically. Your friend in that case is the build-helper
plugin to add it to the project model during build. I'd argue, although
somewhat academically, that doing it via the sources/resources section is
not the right way (as the folder doesn't exist unless the plugin is
executed).

/Anders

On Fri, Jan 20, 2017 at 1:33 PM, Jörg Schaible <
joerg.schaible@bpm-inspire.com> wrote:

> Give target/generated-resources a try.
>
> Gary Aitken wrote:
>
> > I'm having trouble getting resources generated post-compile into the
> final
> > jar package (packaging type jar).
> >
> > During the process-classes phase, I run a task which reads some xml files
> > and produces other xml files.  I can't figure out how to get the output
> > xml files into the jar.
> >
> > Issues:
> >
> > 1. The output is written into target/xmldata,
> >    but the xmldata subtree is not written into the jar.
> >    I also tried generating into target/resources/xmldata
> >
> > 2. I tried the following in the <build> section of pom.xml:
> >     <resources>
> >       <resource>
> >         <directory>${generated-xml.dir}</directory>
> >         <excludes>
> >           <exclude>${generated-src-xml.dir}</exclude>
> >         </excludes>
> >       </resource>
> >     </resources>
> >
> > 3. I also tried adding an
> >         <includes>
> >           <include>**_consolidated.xml</include>
> >         </includes>
> >    to the above <resource> section; no luck.
> >
> > Hints?
> > Thanks,
> > Gary
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: generated resources not in target jar

Posted by Jörg Schaible <jo...@bpm-inspire.com>.
Give target/generated-resources a try.

Gary Aitken wrote:

> I'm having trouble getting resources generated post-compile into the final
> jar package (packaging type jar).
> 
> During the process-classes phase, I run a task which reads some xml files
> and produces other xml files.  I can't figure out how to get the output
> xml files into the jar.
> 
> Issues:
> 
> 1. The output is written into target/xmldata,
>    but the xmldata subtree is not written into the jar.
>    I also tried generating into target/resources/xmldata
> 
> 2. I tried the following in the <build> section of pom.xml:
>     <resources>
>       <resource>
>         <directory>${generated-xml.dir}</directory>
>         <excludes>
>           <exclude>${generated-src-xml.dir}</exclude>
>         </excludes>
>       </resource>
>     </resources>
> 
> 3. I also tried adding an
>         <includes>
>           <include>**_consolidated.xml</include>
>         </includes>
>    to the above <resource> section; no luck.
> 
> Hints?
> Thanks,
> Gary



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


Re: generated resources not in target jar

Posted by Gary Aitken <ma...@dreamchaser.org>.
On 01/21/17 21:12, Gary Aitken wrote:
> On 01/20/17 00:38, Anders Hammar wrote:
>> The best option to handle this is to use the add-resource goal of the
>> build-helper-maven-plugin. Just bind that to the build lifecycle as
>> outlined in the usage example [1]
>>
>> [1] http://www.mojohaus.org/build-helper-maven-plugin/usage.html
> 
> Can you explain why this is needed, when there is already a <resource> 
> specification in the normal <build> part of the pom?  
> 
> In any case I tried that, but the plugin appears to have a bug:
> 
>       <plugin>
>         <groupId>org.codehaus.mojo</groupId>
>         <artifactId>build-helper-maven-plugin</artifactId>
>         <version>1.12</version>
>         <executions>
>           <execution>
>             <id>package-generated-xml</id>
>             <phase>prepare-package</phase>  <!-- <phase>generate-resources</phase> -->
>             <goals>
>               <goal>add-resource</goal>
>             </goals>
>             <configuration>
>               <resources>
>                 <resource>${generated-xml.dir}</resource>
>               </resources>
>             </configuration>
>           </execution>
>         </executions>
>       </plugin>
> 
> [ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:1.12:add-resource (package-generated-xml) on project patientrecords-xml: Unable to parse configuration of mojo org.codehaus.mojo:build-helper-maven-plugin:1.12:add-resource for parameter resource: Cannot find default setter in class org.apache.maven.model.Resource -> [Help 1]
> 
> Note that the above pom fragment specifies the prepare-package phase, for
> the reason cited below:
> 
> On 01/20/17 08:52, Karl Heinz Marbaise wrote:
> 
>> Why are you running in the process-class phase instead of generate-resources phase?
> 
> The resources are generated via execution of a program compiled during the
> compile phase.  I presume the classes would not be built yet in the 
> generate-resources phase.  It probably makes more sense to be in the 
> prepare-package phase, however.  If there's something I'm missing, I'd 
> appreciate a pointer or explanation as to how it works -- how something
> needed in generate-resources gets compiled before running the compile
> phase.
> 
>> On Fri, Jan 20, 2017 at 5:49 AM, Gary Aitken <ma...@dreamchaser.org> wrote:
>>
>>> I'm having trouble getting resources generated post-compile into the final
>>> jar package (packaging type jar).
>>>
>>> During the process-classes phase, I run a task which reads some xml files
>>> and produces other xml files.  I can't figure out how to get the output
>>> xml files into the jar.
>>>
>>> Issues:
>>>
>>> 1. The output is written into target/xmldata,
>>>    but the xmldata subtree is not written into the jar.
>>>    I also tried generating into target/resources/xmldata
>>>
>>> 2. I tried the following in the <build> section of pom.xml:
>>>     <resources>
>>>       <resource>
>>>         <directory>${generated-xml.dir}</directory>
>>>         <excludes>
>>>           <exclude>${generated-src-xml.dir}</exclude>
>>>         </excludes>
>>>       </resource>
>>>     </resources>
>>>
>>> 3. I also tried adding an
>>>         <includes>
>>>           <include>**_consolidated.xml</include>
>>>         </includes>
>>>    to the above <resource> section; no luck.
>>>
>>> Hints?
>>> Thanks,
>>> Gary

This is a bug in the plugin; it will not add resources in any phase after
generate-resources. (bug filed)


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


Re: generated resources not in target jar

Posted by Gary Aitken <ma...@dreamchaser.org>.
On 01/23/17 10:49, Thomas Broyer wrote:
> You have a chicken-and-egg problem: resources:copy is run before
> compile:compile, and jar:jar takes what was copied/written to
> target/classes. So if you generate resources after the
> process-resources phase, then you either have to write them directly
> to target/classes or run the maven-resources-plugin afterwards to
> copy them.

Thank you!  They do not belong in target/classes but running the plugin
in prepare-package does the job.

Gary

> Le dim. 22 janv. 2017 05:13, Gary Aitken <maven@dreamchaser.org
> <ma...@dreamchaser.org>> a �crit :
> 
> On 01/20/17 00:38, Anders Hammar wrote:
>> The best option to handle this is to use the add-resource goal of
>> the build-helper-maven-plugin. Just bind that to the build
>> lifecycle as outlined in the usage example [1]
>> 
>> [1] http://www.mojohaus.org/build-helper-maven-plugin/usage.html
> 
> Can you explain why this is needed, when there is already a
> <resource> specification in the normal <build> part of the pom?
> 
> In any case I tried that, but the plugin appears to have a bug:
> 
> <plugin> <groupId>org.codehaus.mojo</groupId> 
> <artifactId>build-helper-maven-plugin</artifactId> 
> <version>1.12</version> <executions> <execution> 
> <id>package-generated-xml</id> <phase>prepare-package</phase>  <!--
> <phase>generate-resources</phase> --> <goals> 
> <goal>add-resource</goal> </goals> <configuration> <resources> 
> <resource>${generated-xml.dir}</resource> </resources> 
> </configuration> </execution> </executions> </plugin>
> 
> [ERROR] Failed to execute goal
> org.codehaus.mojo:build-helper-maven-plugin:1.12:add-resource
> (package-generated-xml) on project patientrecords-xml: Unable to
> parse configuration of mojo
> org.codehaus.mojo:build-helper-maven-plugin:1.12:add-resource for
> parameter resource: Cannot find default setter in class
> org.apache.maven.model.Resource -> [Help 1]
> 
> Note that the above pom fragment specifies the prepare-package phase,
> for the reason cited below:
> 
> On 01/20/17 08:52, Karl Heinz Marbaise wrote:
> 
>> Why are you running in the process-class phase instead of
>> generate-resources phase?
> 
> The resources are generated via execution of a program compiled
> during the compile phase.  I presume the classes would not be built
> yet in the generate-resources phase.  It probably makes more sense to
> be in the prepare-package phase, however.  If there's something I'm
> missing, I'd appreciate a pointer or explanation as to how it works
> -- how something needed in generate-resources gets compiled before
> running the compile phase.
> 
>> On Fri, Jan 20, 2017 at 5:49 AM, Gary Aitken <maven@dreamchaser.org
>> <ma...@dreamchaser.org>> wrote:
>> 
>>> I'm having trouble getting resources generated post-compile into
>>> the final jar package (packaging type jar).
>>> 
>>> During the process-classes phase, I run a task which reads some
>>> xml files and produces other xml files.  I can't figure out how
>>> to get the output xml files into the jar.
>>> 
>>> Issues:
>>> 
>>> 1. The output is written into target/xmldata, but the xmldata
>>> subtree is not written into the jar. I also tried generating into
>>> target/resources/xmldata
>>> 
>>> 2. I tried the following in the <build> section of pom.xml: 
>>> <resources> <resource> 
>>> <directory>${generated-xml.dir}</directory> <excludes> 
>>> <exclude>${generated-src-xml.dir}</exclude> </excludes> 
>>> </resource> </resources>
>>> 
>>> 3. I also tried adding an <includes> 
>>> <include>**_consolidated.xml</include> </includes> to the above
>>> <resource> section; no luck.
>>> 
>>> Hints? Thanks, Gary

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


Re: generated resources not in target jar

Posted by Thomas Broyer <t....@gmail.com>.
You have a chicken-and-egg problem: resources:copy is run before
compile:compile, and jar:jar takes what was copied/written to
target/classes. So if you generate resources after the process-resources
phase, then you either have to write them directly to target/classes or run
the maven-resources-plugin afterwards to copy them.

Le dim. 22 janv. 2017 05:13, Gary Aitken <ma...@dreamchaser.org> a écrit :

> On 01/20/17 00:38, Anders Hammar wrote:
> > The best option to handle this is to use the add-resource goal of the
> > build-helper-maven-plugin. Just bind that to the build lifecycle as
> > outlined in the usage example [1]
> >
> > [1] http://www.mojohaus.org/build-helper-maven-plugin/usage.html
>
> Can you explain why this is needed, when there is already a <resource>
> specification in the normal <build> part of the pom?
>
> In any case I tried that, but the plugin appears to have a bug:
>
>       <plugin>
>         <groupId>org.codehaus.mojo</groupId>
>         <artifactId>build-helper-maven-plugin</artifactId>
>         <version>1.12</version>
>         <executions>
>           <execution>
>             <id>package-generated-xml</id>
>             <phase>prepare-package</phase>  <!--
> <phase>generate-resources</phase> -->
>             <goals>
>               <goal>add-resource</goal>
>             </goals>
>             <configuration>
>               <resources>
>                 <resource>${generated-xml.dir}</resource>
>               </resources>
>             </configuration>
>           </execution>
>         </executions>
>       </plugin>
>
> [ERROR] Failed to execute goal
> org.codehaus.mojo:build-helper-maven-plugin:1.12:add-resource
> (package-generated-xml) on project patientrecords-xml: Unable to parse
> configuration of mojo
> org.codehaus.mojo:build-helper-maven-plugin:1.12:add-resource for parameter
> resource: Cannot find default setter in class
> org.apache.maven.model.Resource -> [Help 1]
>
> Note that the above pom fragment specifies the prepare-package phase, for
> the reason cited below:
>
> On 01/20/17 08:52, Karl Heinz Marbaise wrote:
>
> > Why are you running in the process-class phase instead of
> generate-resources phase?
>
> The resources are generated via execution of a program compiled during the
> compile phase.  I presume the classes would not be built yet in the
> generate-resources phase.  It probably makes more sense to be in the
> prepare-package phase, however.  If there's something I'm missing, I'd
> appreciate a pointer or explanation as to how it works -- how something
> needed in generate-resources gets compiled before running the compile
> phase.
>
> > On Fri, Jan 20, 2017 at 5:49 AM, Gary Aitken <ma...@dreamchaser.org>
> wrote:
> >
> >> I'm having trouble getting resources generated post-compile into the
> final
> >> jar package (packaging type jar).
> >>
> >> During the process-classes phase, I run a task which reads some xml
> files
> >> and produces other xml files.  I can't figure out how to get the output
> >> xml files into the jar.
> >>
> >> Issues:
> >>
> >> 1. The output is written into target/xmldata,
> >>    but the xmldata subtree is not written into the jar.
> >>    I also tried generating into target/resources/xmldata
> >>
> >> 2. I tried the following in the <build> section of pom.xml:
> >>     <resources>
> >>       <resource>
> >>         <directory>${generated-xml.dir}</directory>
> >>         <excludes>
> >>           <exclude>${generated-src-xml.dir}</exclude>
> >>         </excludes>
> >>       </resource>
> >>     </resources>
> >>
> >> 3. I also tried adding an
> >>         <includes>
> >>           <include>**_consolidated.xml</include>
> >>         </includes>
> >>    to the above <resource> section; no luck.
> >>
> >> Hints?
> >> Thanks,
> >> Gary
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: generated resources not in target jar

Posted by Gary Aitken <ma...@dreamchaser.org>.
On 01/20/17 00:38, Anders Hammar wrote:
> The best option to handle this is to use the add-resource goal of the
> build-helper-maven-plugin. Just bind that to the build lifecycle as
> outlined in the usage example [1]
> 
> [1] http://www.mojohaus.org/build-helper-maven-plugin/usage.html

Can you explain why this is needed, when there is already a <resource> 
specification in the normal <build> part of the pom?  

In any case I tried that, but the plugin appears to have a bug:

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.12</version>
        <executions>
          <execution>
            <id>package-generated-xml</id>
            <phase>prepare-package</phase>  <!-- <phase>generate-resources</phase> -->
            <goals>
              <goal>add-resource</goal>
            </goals>
            <configuration>
              <resources>
                <resource>${generated-xml.dir}</resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>

[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:1.12:add-resource (package-generated-xml) on project patientrecords-xml: Unable to parse configuration of mojo org.codehaus.mojo:build-helper-maven-plugin:1.12:add-resource for parameter resource: Cannot find default setter in class org.apache.maven.model.Resource -> [Help 1]

Note that the above pom fragment specifies the prepare-package phase, for
the reason cited below:

On 01/20/17 08:52, Karl Heinz Marbaise wrote:

> Why are you running in the process-class phase instead of generate-resources phase?

The resources are generated via execution of a program compiled during the
compile phase.  I presume the classes would not be built yet in the 
generate-resources phase.  It probably makes more sense to be in the 
prepare-package phase, however.  If there's something I'm missing, I'd 
appreciate a pointer or explanation as to how it works -- how something
needed in generate-resources gets compiled before running the compile
phase.

> On Fri, Jan 20, 2017 at 5:49 AM, Gary Aitken <ma...@dreamchaser.org> wrote:
> 
>> I'm having trouble getting resources generated post-compile into the final
>> jar package (packaging type jar).
>>
>> During the process-classes phase, I run a task which reads some xml files
>> and produces other xml files.  I can't figure out how to get the output
>> xml files into the jar.
>>
>> Issues:
>>
>> 1. The output is written into target/xmldata,
>>    but the xmldata subtree is not written into the jar.
>>    I also tried generating into target/resources/xmldata
>>
>> 2. I tried the following in the <build> section of pom.xml:
>>     <resources>
>>       <resource>
>>         <directory>${generated-xml.dir}</directory>
>>         <excludes>
>>           <exclude>${generated-src-xml.dir}</exclude>
>>         </excludes>
>>       </resource>
>>     </resources>
>>
>> 3. I also tried adding an
>>         <includes>
>>           <include>**_consolidated.xml</include>
>>         </includes>
>>    to the above <resource> section; no luck.
>>
>> Hints?
>> Thanks,
>> Gary


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


Re: generated resources not in target jar

Posted by Anders Hammar <an...@hammar.net>.
The best option to handle this is to use the add-resource goal of the
build-helper-maven-plugin. Just bind that to the build lifecycle as
outlined in the usage example [1]

[1] http://www.mojohaus.org/build-helper-maven-plugin/usage.html

/Anders

On Fri, Jan 20, 2017 at 5:49 AM, Gary Aitken <ma...@dreamchaser.org> wrote:

> I'm having trouble getting resources generated post-compile into the final
> jar package (packaging type jar).
>
> During the process-classes phase, I run a task which reads some xml files
> and produces other xml files.  I can't figure out how to get the output
> xml files into the jar.
>
> Issues:
>
> 1. The output is written into target/xmldata,
>    but the xmldata subtree is not written into the jar.
>    I also tried generating into target/resources/xmldata
>
> 2. I tried the following in the <build> section of pom.xml:
>     <resources>
>       <resource>
>         <directory>${generated-xml.dir}</directory>
>         <excludes>
>           <exclude>${generated-src-xml.dir}</exclude>
>         </excludes>
>       </resource>
>     </resources>
>
> 3. I also tried adding an
>         <includes>
>           <include>**_consolidated.xml</include>
>         </includes>
>    to the above <resource> section; no luck.
>
> Hints?
> Thanks,
> Gary
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: generated resources not in target jar

Posted by Karl Heinz Marbaise <kh...@gmx.de>.
Hi,

On 20/01/17 05:49, Gary Aitken wrote:
> I'm having trouble getting resources generated post-compile into the final
> jar package (packaging type jar).
>
> During the process-classes phase, I run a task which reads some xml files
> and produces other xml files.  I can't figure out how to get the output
> xml files into the jar.

Why are you running in the process-class phase instead of 
generate-resources phase?

Kind regards
Karl Heinz Marbaise
>
> Issues:
>
> 1. The output is written into target/xmldata,
>    but the xmldata subtree is not written into the jar.
>    I also tried generating into target/resources/xmldata
>
> 2. I tried the following in the <build> section of pom.xml:
>     <resources>
>       <resource>
>         <directory>${generated-xml.dir}</directory>
>         <excludes>
>           <exclude>${generated-src-xml.dir}</exclude>
>         </excludes>
>       </resource>
>     </resources>
>
> 3. I also tried adding an
>         <includes>
>           <include>**_consolidated.xml</include>
>         </includes>
>    to the above <resource> section; no luck.
>
> Hints?
> Thanks,
> Gary
>

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