Dependency for WebProject in maven
i want to create a web project(war)..which will depend on other jar(java project)
Once i build my war it should automatically build th开发者_运维百科e java project to jar and add it to its local repository.
Can anyone help?
you can have multi module maven project.. hope that is what you are looking for.. like below
<modules>
<module>example-jar</module>
</modules>
check this out: multimodule-web-spring-sect-simple-parent
Yes. Sure you can, and it is probably the most common use-case. Most of the web projects has a shared library that contains utility code shared among various other project.
There are two ways, to do this:
Create a parent project, under that create your web project and other project at the same level. In your Web project add the Jar project as dependency. Now, whenever you will build the parent project using
mvn clean install
, you will have both of the projects built and installed in your local repository.parent +------- pom.xml (has two modules webProject and jarProject) +------- webProject | + pom.xml (depends on jarProject) +------- jarProject + pom.xml
There is another way, using
Maven reactor plug-in
, this plug-in enables you to build all related projects to a project. You can see details here. Particularly,reactor:make-dependents
If your jar project and war project follow the same release cycle, it would be a good idea to create a common parent pom and make the 2 projects modules of that parent.
Then you can build from the parent directory and Maven's reactor will always ensure that the jar project is built first.
If they don't follow the same release cycle, then you will probably just have to make sure that you manually build them in the right order.
If running these builds in Hudson, the maven plugin can ensure that a build of a downstream project is triggered after the completion of an upstream project.
This is doesn't quite make sense. If the WAR depends on the JAR, then the JAR needs to be build and added to the local repository before the WAR is built (not after, as you have written in your question). (It has to be done in this order so that the JAR file can be included in the WAR file.)
Assuming that you really mean that the JAR should be built first, this is easy. Just create a parent-module, with child modules for the JAR and the WAR, and declare that the WAR module depends on the JAR module. Then build the parent module.
I recommend that you take the time to read the Multi-module Projects chapter of "Maven by Example", and or the relevant documentation on the Maven site.
精彩评论