You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by eyal edri <ey...@gmail.com> on 2010/01/21 10:25:20 UTC

best practice to include resources in the jar file and unpack them on target server

Hi,

i'v included resource files inside the jar file using the include tag:

<profile>
      <id>devel</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
              <classesDirectory>src/main/resources</classesDirectory>
              <includes>
                <include>**/*</include>
              </includes>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

# jar tf /usr/lib/ctch/java/IncreasePriority-jar/IncreasePriority.jar
META-INF/
META-INF/MANIFEST.MF
increase-priority.properties
increase-priority.cron
META-INF/maven/
META-INF/maven/com.url.unknowns/
META-INF/maven/com.url.unknowns/IncreasePriority/
META-INF/maven/com.url.unknowns/IncreasePriority/pom.xml
META-INF/maven/com.url.unknowns/IncreasePriority/pom.properties


what's the best way (via pom) to copy them to targetDirectories,
e.g *.cron to /etc/cron.d
     *.properties to /etc/${artifactId}/

thanks

-- 
Eyal Edri

Re: best practice to include resources in the jar file and unpack them on target server

Posted by Lóránt Pintér <lo...@gmail.com>.
I've had a similar problem. What you can do is to use the assembly
plugin to create a separate zip or jar of your extra resources, attach
the created archive to the build with a different classifier, and
extract this artifact with the dependency plugin's unpack goal.

Lóránt

On Thu, Jan 21, 2010 at 12:52, eyal edri <ey...@gmail.com> wrote:
> I don't agree with the conception that uber (or fat) jar is the way to go.
> IMO, you loose all the advantages maven dependency supplies if you do so (as
> i mentioned, you need to install all your application in case you change one
> line of code in one of your infrastructure jars..)
>
> i know maven isn't supposed to be used for deployment, but with a little
> open mind and flexibility, it can be done.
>
> On Thu, Jan 21, 2010 at 1:46 PM, Martin Höller <ma...@xss.co.at> wrote:
>
>> Am Donnerstag, 21. Januar 2010 11:54:14 schrieb eyal edri:
>> > so to my original question, how to i copy the files from the jar after i
>> > install it on the target server?
>>
>> Extract the resource files from the JAR-File using 'jar' or 'zip'
>> utilities,
>> and copy them to the location where you want them to be.
>>
>> This is not related to maven any more. There was actually a thread about
>> something similar two days ago... and while searching for it, I found that
>> you were the original poster. The last mail from Thod Tiessen [0] in this
>> thread hits the nail on the head, IMHO.
>>
>> hth,
>> - martin
>>
>> [0]
>>
>> http://old.nabble.com/install-maven-project-from-repository-to-local-fs-to27209691.html#a27227458
>>
>
>
>
> --
> Eyal Edri
>

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


Re: best practice to include resources in the jar file and unpack them on target server

Posted by eyal edri <ey...@gmail.com>.
I don't agree with the conception that uber (or fat) jar is the way to go.
IMO, you loose all the advantages maven dependency supplies if you do so (as
i mentioned, you need to install all your application in case you change one
line of code in one of your infrastructure jars..)

i know maven isn't supposed to be used for deployment, but with a little
open mind and flexibility, it can be done.

On Thu, Jan 21, 2010 at 1:46 PM, Martin Höller <ma...@xss.co.at> wrote:

> Am Donnerstag, 21. Januar 2010 11:54:14 schrieb eyal edri:
> > so to my original question, how to i copy the files from the jar after i
> > install it on the target server?
>
> Extract the resource files from the JAR-File using 'jar' or 'zip'
> utilities,
> and copy them to the location where you want them to be.
>
> This is not related to maven any more. There was actually a thread about
> something similar two days ago... and while searching for it, I found that
> you were the original poster. The last mail from Thod Tiessen [0] in this
> thread hits the nail on the head, IMHO.
>
> hth,
> - martin
>
> [0]
>
> http://old.nabble.com/install-maven-project-from-repository-to-local-fs-to27209691.html#a27227458
>



-- 
Eyal Edri

Re: best practice to include resources in the jar file and unpack them on target server

Posted by Martin Höller <ma...@xss.co.at>.
Am Donnerstag, 21. Januar 2010 11:54:14 schrieb eyal edri:
> so to my original question, how to i copy the files from the jar after i
> install it on the target server?

Extract the resource files from the JAR-File using 'jar' or 'zip' utilities, 
and copy them to the location where you want them to be.

This is not related to maven any more. There was actually a thread about 
something similar two days ago... and while searching for it, I found that 
you were the original poster. The last mail from Thod Tiessen [0] in this 
thread hits the nail on the head, IMHO.

hth,
- martin

[0] 
http://old.nabble.com/install-maven-project-from-repository-to-local-fs-to27209691.html#a27227458

Re: best practice to include resources in the jar file and unpack them on target server

Posted by eyal edri <ey...@gmail.com>.
I'm actually very familiar with maven, and i read both "better builds with
maven" and "the definite guide".

i wasn't aware that the jar auto packs the resources files as well.
i removed the section of the jar plugin below, and i still see the files
included:

$ jar tf /usr/lib/ctch/java/IncreasePriority/IncreasePriority.jar
META-INF/
META-INF/MANIFEST.MF
com/
com/company/
com/company/url/
com/company/url/unknowns/
com/company/url/unknowns/IncreasePriority.class
increase-priority.properties
increase-priority.cron
META-INF/maven/
META-INF/maven/com.company.url.unknowns/
META-INF/maven/com.company.url.unknowns/IncreasePriority/
META-INF/maven/com.company.url.unknowns/IncreasePriority/pom.xml
META-INF/maven/com.company.url.unknowns/IncreasePriority/pom.properties


so to my original question, how to i copy the files from the jar after i
install it on the target server?

On Thu, Jan 21, 2010 at 12:32 PM, Martin Höller <ma...@xss.co.at> wrote:

> Hi!
>
> Am Donnerstag, 21. Januar 2010 10:25:20 schrieb eyal edri:
> > i'v included resource files inside the jar file using the include tag:
> >
> > <profile>
> >       <id>devel</id>
> >       <build>
> >         <plugins>
> >           <plugin>
> >             <groupId>org.apache.maven.plugins</groupId>
> >             <artifactId>maven-jar-plugin</artifactId>
> >             <configuration>
> >               <classesDirectory>src/main/resources</classesDirectory>
> >               <includes>
> >                 <include>**/*</include>
> >               </includes>
> >             </configuration>
> >           </plugin>
> >         </plugins>
> >       </build>
> >     </profile>
>
> What you are doing here is telling the maven-jar-plugin, that classes are
> found in src/main/resources, which is nonsense!
>
> What you should do, is put your resources in src/main/resources and they
> should end up in target/classes and the produced JAR automatically when
> running mvn package or the like.
>
> It seems you are not familiar with maven and I strongly recommend reading a
> maven book, like sonatype's Maven: The Definitve Guide", which is available
> online [0] for free.
>
> hth,
> - martin
>
> [0] http://www.sonatype.com/book/
>



-- 
Eyal Edri

Re: best practice to include resources in the jar file and unpack them on target server

Posted by Martin Höller <ma...@xss.co.at>.
Hi!

Am Donnerstag, 21. Januar 2010 10:25:20 schrieb eyal edri:
> i'v included resource files inside the jar file using the include tag:
>
> <profile>
>       <id>devel</id>
>       <build>
>         <plugins>
>           <plugin>
>             <groupId>org.apache.maven.plugins</groupId>
>             <artifactId>maven-jar-plugin</artifactId>
>             <configuration>
>               <classesDirectory>src/main/resources</classesDirectory>
>               <includes>
>                 <include>**/*</include>
>               </includes>
>             </configuration>
>           </plugin>
>         </plugins>
>       </build>
>     </profile>

What you are doing here is telling the maven-jar-plugin, that classes are 
found in src/main/resources, which is nonsense!

What you should do, is put your resources in src/main/resources and they 
should end up in target/classes and the produced JAR automatically when 
running mvn package or the like.

It seems you are not familiar with maven and I strongly recommend reading a 
maven book, like sonatype's Maven: The Definitve Guide", which is available 
online [0] for free.

hth,
- martin

[0] http://www.sonatype.com/book/