I just created a framework (it would be more accurate to describe it as an integration), and I'm wondering what would be the best way to distribute it. The project is mavenized and uses Spring 3, but I am a novice in both areas and I am not sure what would be the best way to distribute this.

The framework involves an integration between a Javascript library that I created, Spring 3 (the web MVC part), and Hibernate Validator.

  • I have a pom.xml for the whole project.
  • I have a src/main/java (properly namespaced) with the classes relevant to the integration.
  • I have a webapp directory with a js folder that contains the Javascript files necessary for this integration.
  • I have a WEB-INF/tlds directory with a tld for a custom tag implemented in Java.
  • I have a WEBINF/tags directory for a custom tag.
  • I have an applicationContext.xml in src/main/resources.
  • I have a springmvc-servlet.xml in WEB-INF.
  • I have a web.xml in WEB-INF (looks to be standard and out of the box; I don't recall making any changes).
  • I have a src/test/java/ that includes tests for the integration framework

What files/directories should I include/exclude, and what would be a good way to distribute this integration (for Spring 3 that is)? Is there a standard?

UPDATE

Sorry I wasn't cleared about what I meant by "distribute" :) I meant in the sense that other developers can include this framework as an artifact in their project (perhaps as a jar), similar to how libraries are distributed. I'm just confused by the fact that there is webapp-specific stuff in there.

有帮助吗?

解决方案

Making a maven webapp project into a framework will be a bit of hassle for other people to use. The problem isn't about what you should include/exclude but what the downstream webapp project should include/exclude. The downstream project will need to exclude the web.xml from its war dependency and need to make sure that it doesn't contain file/folder names which collide with its depending war files.

Normally, web.xml is exculded by maven-war-plugin but configurations files like logger configurations will not be exculded by default and it will be crash with the downstream project's. Since the web.xml is exculded, the downstream project will not be able to know what are the servlet definitions in its war dependencies. You will need to copy or define them accordingly yourself.

Since you do not have any changes to your web.xml, I think you are not going to run it as webapp. You should make it into jar package, instead of war package, and convert it to normal maven jar project, i.e. remove src/main/webapp folder

Although it is possible to have a war dependency, I highly recommend not to.

Update

From your comment, that's what I am worried about too. It is probably the only reason you have to use war package. So you will need to keep in mind that:

  1. If you have the spring dispatcher configuration xml and bean definition under src/main/webapp, make sure to include/exculde them in your downstream project correctly using configuration setting for maven-war-plugin. Make sure the filename won't crash with the downstream project. You will need to becareful when you want to reuse beans definition since it may not be configured to suit the need of the downstream project. In many case, you will end up writing a new definition. Tip: putting them as resources under unique package name in the classpath is the safest and easiest way.

  2. The web.xml have to be there in order to make a war package, but it will be exculded from downstream war project by maven-war-plugin. You need to inculde this plugin in your downstream project. If you have any servlet definition in web.xml, it will have be redefined in downstream project web.xml.

  3. Becareful with folder/file collision in under src/main/webapp folder.

In summary, the main concern is the place where you put xml configuration nd how you want to include/exclude it in the downstream project (not in your integration).

其他提示

Depending on what you mean by "distribute" here. :)

If you are merely distributing to fellow developers so that they can work on the same project, perhaps you want to invoke mvn clean to remove target folder, compiled classes, etc. This command will take care of the inclusion and exclusion of files/directories. All you need to do is to zip the entire project up and "distribute" it. When the developer imports this project into workspace, they are obtain all the jars through your pom.xml. Pom.xml, in my opinion, is the most important piece of any Maven project.

If you want end user to be able to run your project rather than making changes to your code, you may want to invoke mvn package to create the war file. This way, your user can drop this war file into the application server and run it.

Use Maven WAR overlays also described in this question.

Also create an example - probably from the webapp you already have - of all these and generate a Maven archetype from it.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top