You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by S Ahmed <sa...@gmail.com> on 2012/04/18 00:00:57 UTC

exclude folders during mvn assembly

I'm using the maven assembly plugin along with the maven jar plugin to
build a release version of my application:

mvn assembly:assembly

I want to exclude the /resources folder from the release so it doesn't get
compiled into my .jar

How can I do this?

Re: exclude folders during mvn assembly

Posted by Ryan Wexler <ry...@iridiumsuite.com>.
I am deploying artifacts with configuration files as well.  I have
different config files for each production server, so I am creating a
different artifact for each production server with the proper config files.

I create a generic war and then overlay it, adding the config files for
each production site.  Just a thought for you.

On Wed, Apr 18, 2012 at 2:14 PM, S Ahmed <sa...@gmail.com> wrote:

> The problem I was having was, when on the production server, I had a
> properties file in my /resources folder, and I modified in on the server
> but noticed it was still returning the old values.
>
> I then realized that the class loader was loading the file from the .jar
> itself, and not reading from the file (even though the file was updated to
> reflect production settings).
>
> On Wed, Apr 18, 2012 at 3:51 PM, Barrie Treloar <ba...@gmail.com>
> wrote:
>
> > On Thu, Apr 19, 2012 at 1:09 AM, S Ahmed <sa...@gmail.com> wrote:
> > > Yeah they are config files, I just wanted a simple way to reference
> them
> > in
> > > my code, i.e:
> > >
> > > ClassLoader classLoader =
> Thread.currentThread().getContextClassLoader();
> > > InputStream is = classLoader.getResourceAsStream("config.properties");
> > >
> > > I think what I should do is reference the file based on an
> environmental
> > > variable, which I will set both locally and on the production server.
> > > Plus having an EV let's other projects reference things in a more
> uniform
> > > way.
> >
> > You dont want stuff that changes across different environments baked
> > into your builds.
> >
> > We just add the directory "./config" to the classpath and at deploy
> > time swap in what environment settings are needed.
> > (For runnable jars)
> >
> > For web apps, we use an ugly hack where the web server has a global
> > classpath entry pointing to a config dir.
> > The configs then get dropped in there.
> >
> > Both ways allow us to continue to use class loader to avoid knowing
> > the actual location on disk.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>

Re: exclude folders during mvn assembly

Posted by Barrie Treloar <ba...@gmail.com>.
On Thu, Apr 19, 2012 at 11:48 PM, S Ahmed <sa...@gmail.com> wrote:
> Barrie,
>
> I see, ok I'm looking into the JNDI method.
>
> I'm hosting this app in both tomcat and jetty.
>
> Could I put this dndi file in my class path so I don't have to hard code
> the location, or does it have to be in the servlet container? i.e. jetty or
> tomcat
>
> My jetty instance is an embedded instance...

Have a look around at some of the recent similar posts.

I thought Ron's blog gave some details on how to use JNDI.

Yes, putting things on the class path is the best way to load resource files.
Then you don't have to worry about physical locations on disk.

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


Re: exclude folders during mvn assembly

Posted by S Ahmed <sa...@gmail.com>.
Barrie,

I see, ok I'm looking into the JNDI method.

I'm hosting this app in both tomcat and jetty.

Could I put this dndi file in my class path so I don't have to hard code
the location, or does it have to be in the servlet container? i.e. jetty or
tomcat

My jetty instance is an embedded instance...





On Thu, Apr 19, 2012 at 8:16 AM, Barrie Treloar <ba...@gmail.com> wrote:

> On Thu, Apr 19, 2012 at 8:26 PM, S Ahmed <sa...@gmail.com> wrote:
> > So what do you suggest?  Should I create a new maven module called Config
> > and drop my properties, log4net properties files there?
> >
> > I then add that module as a dependancy.
> > Also, during my production build, I will just make sure I have that
> folder
> > to my classpath right?
> >
> > In my java code, since I was assuming it was in my /resources before, and
> > now it is in a seperate maven module, will I need to change anything or
> > since it is still in my classpath all is good, the ONLY difference now is
> > that it won't be embedded in my .jar right?
> >
> > I am really getting confused by this, I need someone to clarify this as
> its
> > confusing me :)
>
> Read
> http://maven.40175.n5.nabble.com/Re-Releasing-Configured-Artifacts-how-tp5648372p5650944.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: exclude folders during mvn assembly

Posted by Barrie Treloar <ba...@gmail.com>.
On Thu, Apr 19, 2012 at 8:26 PM, S Ahmed <sa...@gmail.com> wrote:
> So what do you suggest?  Should I create a new maven module called Config
> and drop my properties, log4net properties files there?
>
> I then add that module as a dependancy.
> Also, during my production build, I will just make sure I have that folder
> to my classpath right?
>
> In my java code, since I was assuming it was in my /resources before, and
> now it is in a seperate maven module, will I need to change anything or
> since it is still in my classpath all is good, the ONLY difference now is
> that it won't be embedded in my .jar right?
>
> I am really getting confused by this, I need someone to clarify this as its
> confusing me :)

Read http://maven.40175.n5.nabble.com/Re-Releasing-Configured-Artifacts-how-tp5648372p5650944.html

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


Re: exclude folders during mvn assembly

Posted by S Ahmed <sa...@gmail.com>.
Barrie,

Yes I noticed both of those issues :)

So what do you suggest?  Should I create a new maven module called Config
and drop my properties, log4net properties files there?

I then add that module as a dependancy.
Also, during my production build, I will just make sure I have that folder
to my classpath right?

In my java code, since I was assuming it was in my /resources before, and
now it is in a seperate maven module, will I need to change anything or
since it is still in my classpath all is good, the ONLY difference now is
that it won't be embedded in my .jar right?

I am really getting confused by this, I need someone to clarify this as its
confusing me :)

On Wed, Apr 18, 2012 at 8:19 PM, Barrie Treloar <ba...@gmail.com> wrote:

> On Thu, Apr 19, 2012 at 6:44 AM, S Ahmed <sa...@gmail.com> wrote:
> > The problem I was having was, when on the production server, I had a
> > properties file in my /resources folder, and I modified in on the server
> > but noticed it was still returning the old values.
> >
> > I then realized that the class loader was loading the file from the .jar
> > itself, and not reading from the file (even though the file was updated
> to
> > reflect production settings).
>
> Read up on classpath resolution rules.
> Your file in the *.jar is trumping the one in the directory.
>
> The other sin to commit is including a log4j settings file in your jar. :)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: exclude folders during mvn assembly

Posted by Barrie Treloar <ba...@gmail.com>.
On Thu, Apr 19, 2012 at 6:44 AM, S Ahmed <sa...@gmail.com> wrote:
> The problem I was having was, when on the production server, I had a
> properties file in my /resources folder, and I modified in on the server
> but noticed it was still returning the old values.
>
> I then realized that the class loader was loading the file from the .jar
> itself, and not reading from the file (even though the file was updated to
> reflect production settings).

Read up on classpath resolution rules.
Your file in the *.jar is trumping the one in the directory.

The other sin to commit is including a log4j settings file in your jar. :)

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


Re: exclude folders during mvn assembly

Posted by S Ahmed <sa...@gmail.com>.
The problem I was having was, when on the production server, I had a
properties file in my /resources folder, and I modified in on the server
but noticed it was still returning the old values.

I then realized that the class loader was loading the file from the .jar
itself, and not reading from the file (even though the file was updated to
reflect production settings).

On Wed, Apr 18, 2012 at 3:51 PM, Barrie Treloar <ba...@gmail.com> wrote:

> On Thu, Apr 19, 2012 at 1:09 AM, S Ahmed <sa...@gmail.com> wrote:
> > Yeah they are config files, I just wanted a simple way to reference them
> in
> > my code, i.e:
> >
> > ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> > InputStream is = classLoader.getResourceAsStream("config.properties");
> >
> > I think what I should do is reference the file based on an environmental
> > variable, which I will set both locally and on the production server.
> > Plus having an EV let's other projects reference things in a more uniform
> > way.
>
> You dont want stuff that changes across different environments baked
> into your builds.
>
> We just add the directory "./config" to the classpath and at deploy
> time swap in what environment settings are needed.
> (For runnable jars)
>
> For web apps, we use an ugly hack where the web server has a global
> classpath entry pointing to a config dir.
> The configs then get dropped in there.
>
> Both ways allow us to continue to use class loader to avoid knowing
> the actual location on disk.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: exclude folders during mvn assembly

Posted by Barrie Treloar <ba...@gmail.com>.
On Thu, Apr 19, 2012 at 1:09 AM, S Ahmed <sa...@gmail.com> wrote:
> Yeah they are config files, I just wanted a simple way to reference them in
> my code, i.e:
>
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> InputStream is = classLoader.getResourceAsStream("config.properties");
>
> I think what I should do is reference the file based on an environmental
> variable, which I will set both locally and on the production server.
> Plus having an EV let's other projects reference things in a more uniform
> way.

You dont want stuff that changes across different environments baked
into your builds.

We just add the directory "./config" to the classpath and at deploy
time swap in what environment settings are needed.
(For runnable jars)

For web apps, we use an ugly hack where the web server has a global
classpath entry pointing to a config dir.
The configs then get dropped in there.

Both ways allow us to continue to use class loader to avoid knowing
the actual location on disk.

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


Re: exclude folders during mvn assembly

Posted by Ron Wheeler <rw...@artifact-software.com>.
JNDI?

On 18/04/2012 11:39 AM, S Ahmed wrote:
> Yeah they are config files, I just wanted a simple way to reference them in
> my code, i.e:
>
> ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
> InputStream is = classLoader.getResourceAsStream("config.properties");
>
> I think what I should do is reference the file based on an environmental
> variable, which I will set both locally and on the production server.
> Plus having an EV let's other projects reference things in a more uniform
> way.
>
> you agree?
>
>
>
> On Wed, Apr 18, 2012 at 1:26 AM, Barrie Treloar<ba...@gmail.com>  wrote:
>
>> On Wed, Apr 18, 2012 at 2:20 PM, Wayne Fay<wa...@gmail.com>  wrote:
>>>> I want to exclude the /resources folder from the release so it doesn't
>> get
>>>> compiled into my .jar
>>> If you can't sort out how to do this, you can always make another
>>> project, depend on the output of this one, then unpack the assembly,
>>> set your excludes there, and repack the assembly minus the files you
>>> don't want.
>> Also, why are you putting things in src/main/resources if you dont
>> want them in your jar?
>>
>> Just put them somewhere else and they wont be included.
>>
>> If they are needed for testing it should be src/test/resources.
>> If they are configuration files I put them in src/main/config and then
>> you can tell the assembly plugin to include them in the zip it builds.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>


-- 
Ron Wheeler
President
Artifact Software Inc
email: rwheeler@artifact-software.com
skype: ronaldmwheeler
phone: 866-970-2435, ext 102



Re: exclude folders during mvn assembly

Posted by S Ahmed <sa...@gmail.com>.
Yeah they are config files, I just wanted a simple way to reference them in
my code, i.e:

ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream is = classLoader.getResourceAsStream("config.properties");

I think what I should do is reference the file based on an environmental
variable, which I will set both locally and on the production server.
Plus having an EV let's other projects reference things in a more uniform
way.

you agree?



On Wed, Apr 18, 2012 at 1:26 AM, Barrie Treloar <ba...@gmail.com> wrote:

> On Wed, Apr 18, 2012 at 2:20 PM, Wayne Fay <wa...@gmail.com> wrote:
> >> I want to exclude the /resources folder from the release so it doesn't
> get
> >> compiled into my .jar
> >
> > If you can't sort out how to do this, you can always make another
> > project, depend on the output of this one, then unpack the assembly,
> > set your excludes there, and repack the assembly minus the files you
> > don't want.
>
> Also, why are you putting things in src/main/resources if you dont
> want them in your jar?
>
> Just put them somewhere else and they wont be included.
>
> If they are needed for testing it should be src/test/resources.
> If they are configuration files I put them in src/main/config and then
> you can tell the assembly plugin to include them in the zip it builds.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: exclude folders during mvn assembly

Posted by Barrie Treloar <ba...@gmail.com>.
On Wed, Apr 18, 2012 at 2:20 PM, Wayne Fay <wa...@gmail.com> wrote:
>> I want to exclude the /resources folder from the release so it doesn't get
>> compiled into my .jar
>
> If you can't sort out how to do this, you can always make another
> project, depend on the output of this one, then unpack the assembly,
> set your excludes there, and repack the assembly minus the files you
> don't want.

Also, why are you putting things in src/main/resources if you dont
want them in your jar?

Just put them somewhere else and they wont be included.

If they are needed for testing it should be src/test/resources.
If they are configuration files I put them in src/main/config and then
you can tell the assembly plugin to include them in the zip it builds.

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


Re: exclude folders during mvn assembly

Posted by Wayne Fay <wa...@gmail.com>.
> I want to exclude the /resources folder from the release so it doesn't get
> compiled into my .jar

If you can't sort out how to do this, you can always make another
project, depend on the output of this one, then unpack the assembly,
set your excludes there, and repack the assembly minus the files you
don't want.

Wayne

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