You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Richard Chamberlain <ri...@caplin.com> on 2008/12/10 14:48:42 UTC

creating a JAR file of the source code in a war project

Hi,

 

I've got a standard war project. I'd like to jar up my source code and
put it in WEB-INF/lib instead of compiling it to WEB-INF/classes.

 

This would allow me to overlay it into another war project without
mixing up WEB-INF/classes

 

Is this possible/advisable?

 

Regards,

 

Richard


RE: creating a JAR file of the source code in a war project

Posted by Richard Chamberlain <ri...@caplin.com>.
Yeah, I meant classes. That'll help while I restructure the project. 

Thanks Guys!

-----Original Message-----
From: Wendy Smoak [mailto:wsmoak@gmail.com] 
Sent: 10 December 2008 13:57
To: Maven Users List
Subject: Re: creating a JAR file of the source code in a war project

On Wed, Dec 10, 2008 at 8:48 AM, Richard Chamberlain
<ri...@caplin.com> wrote:
> I've got a standard war project. I'd like to jar up my source code and
> put it in WEB-INF/lib instead of compiling it to WEB-INF/classes.
>
> This would allow me to overlay it into another war project without
> mixing up WEB-INF/classes
>
> Is this possible/advisable?

The best thing would be to put the code in a separate module and
include it as a dependency jar in the war projects.

If you can't move the code, you can configure the war plugin to deploy
a jar containing the classes, and use that jar from the other war.

http://maven.apache.org/plugins/maven-war-plugin/faq.html#attached

I don't understand why you'd want the sources in WEB-INF/lib though...

-- 
Wendy

---------------------------------------------------------------------
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: creating a JAR file of the source code in a war project

Posted by Wendy Smoak <ws...@gmail.com>.
On Wed, Dec 10, 2008 at 8:48 AM, Richard Chamberlain
<ri...@caplin.com> wrote:
> I've got a standard war project. I'd like to jar up my source code and
> put it in WEB-INF/lib instead of compiling it to WEB-INF/classes.
>
> This would allow me to overlay it into another war project without
> mixing up WEB-INF/classes
>
> Is this possible/advisable?

The best thing would be to put the code in a separate module and
include it as a dependency jar in the war projects.

If you can't move the code, you can configure the war plugin to deploy
a jar containing the classes, and use that jar from the other war.

http://maven.apache.org/plugins/maven-war-plugin/faq.html#attached

I don't understand why you'd want the sources in WEB-INF/lib though...

-- 
Wendy

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


Re: creating a JAR file of the source code in a war project

Posted by Jörg Schaible <jo...@gmx.de>.
Richard Chamberlain wrote at Mittwoch, 10. Dezember 2008 14:48:

> Hi,
> 
>  
> 
> I've got a standard war project. I'd like to jar up my source code and
> put it in WEB-INF/lib instead of compiling it to WEB-INF/classes.
> 
>  
> 
> This would allow me to overlay it into another war project without
> mixing up WEB-INF/classes
> 
>  
> 
> Is this possible/advisable?

We do this all the time. That way the jar "transports" the dependencies and
the war file can be used for overlays. However to get the jar into the lib
directory you have to create the jar before the war. Therefore you have to
set the type of your project to "jar" and configure for the war-plugin a
classifier:

        <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                        <outputDirectory>${our.webapp.directory}/WEB-INF/lib</outputDirectory>
                </configuration>
        </plugin>
        <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <executions>
                        <execution>
                                <id>war</id>
                                <phase>package</phase>
                                <goals>
                                        <goal>war</goal>
                                </goals>
                                <configuration>
                                        <classifier>webapp</classifier>
                                        <webappDirectory>${our.webapp.directory}</webappDirectory>
                                </configuration>
                        </execution>
                </executions>
        </plugin>

Caveats:
- You should declare the war artifact in a dependencyManagement section
always with the scope "provided" and only in projects where you use this
war for an overlay you should declare it as runtime. The overlay mechanism
will otherwise overlay all dependend war artifacts again.
- You can no longer overlay the resources (property files) or class files.
They are now part of the jar and if you have a deeper dependency tree the
sequence of the jars in the class path is no longer deterministic.

- Jörg


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