Hi Felipe,
If you want to do this you can create another maven project and have your war project include that as a dependency. The multiproject plugin ties all this together nicely.
There's really good wiki entry and a sample project/sub-projects zip file at http://wiki.codehaus.org/maven/CreatingJ2eeApplications (also see the wiki entry CreatingWebApplications)
This fits with the one-artifact-one-project guideline. Each project (or sub-project) should only create one jar/ear/war file.
So say you have a main project with an id of "myapp-webapp". You could then create a second project "myapp-common". In myapp-webapp you would then include a dependency for myapp-common with the war.bundle property set to true. The just move all your java code into myapp-common/src/java.
Here's a possible directory structure:
mainproject
- root
- project.xml
- project.properties
- webapp
- project.xml
- project.properties
- src
- webapp
- *.jsp
- *.html
- common
- project.xml
- project.properties
- src
- java
- com/yourcompany/project/*.javaTo use multiproject you need to setup a couple things, then you just run "maven multiproject:install" and it will figure out the build order and everything :-)
In the webapp subproject's project.properties put the line: maven.multiproject.type=war
Then in webapp subproject's project.xml just include the dependency
<dependency>
<groupId>mygroupid</groupId>
<artifactId>myapp-common</artifactId>
<version>1.0</version>
<properties>
<war.bundle>true</war.bundle>
</properties>
</dependency>Root is pretty much a skeleton. Here's a simple project.xml:
<?xml version="1.0"?> <project> <pomVersion>3</pomVersion> <id>myapp-root</id> <groupId>mygroupid</groupId> <name>MyApp Root Application</name> <currentVersion>1.0</currentVersion> <package>com.mycompany.myapp</package> </project>
And in the root project's project.properties:
maven.multiproject.basedir=${basedir}/../
maven.multiproject.includes=*/project.xml
maven.multiproject.excludes=root/project.xmlAh, this should be all set. Just cd to the root subproject directory (perhaps ~/cvs/myproject/root) and "maven multiproject:install". You can then find the war file in ~/.maven/repository/mygroupid/wars/myapp-webapp-1.0.war.
We have had very good luck with this process. My group uses maven to build some internal web applications. This has really cleaned up our build process.
Matt
Felipe Leme wrote:
Hi Eric,
On Thu, 2 Sep 2004 20:57:02 +0800, Eric Chow <[EMAIL PROTECTED]> wrote:
Is it possible to create a JAR file for those classes and copy it into
/WEB-INF/lib rather than those classes into /WEB-INF/classes ????
Currently, no. But I've opened an issue about it a couple of weeks ago:
http://jira.codehaus.org/browse/MPWAR-30
If you're interested in that change, please vote for it and put some comments, so we can discuss it in the dev list.
-- Felipe
