padmalcom
padmalcom

Reputation: 1449

Build and include JSF taglib as jar in a Dynamic Web Project using Maven

I am working on a JSF taglib. To test it I compile it to a JAR as described here and add it manually to a Dynamic Web Project (In the WEB-INF/lib directory).

I know that this step can be automated, but I do not know how. Can anybody explain how to copy a generated jar to a second project in Eclipse?

Thanks in advance!

Upvotes: 1

Views: 1206

Answers (1)

wemu
wemu

Reputation: 8160

quite some steps to do :)

  • add a pom.xml into your project and follow the maven directory structure. use packaging "jar" for the taglib project. Lets assume you use groupId=com.company.taglib artifactId=company-taglib version=1.0.0-SNAPSHOT
  • if you do a mvn install on this project it will copy the jar into your local maven repository (usually found at ~/.m2/ - now maven can resolve the dependency on your local machine
  • add a pom.xml to your webproject, use packaging "war" and add the taglib project as a dependency (within <dependencies> in pom.xml).
<dependency>
  <groupId>com.company.taglib</groupId>
  <artifactId>company-taglib</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>

Maven will resolve this dependency from your local repository. In Eclipse using the m2e Plugin it will resolve the project directly.

To "publish" the taglib.jar you need an infrastructure to share artifacts. Usually using a repository proxy (Sonatype Nexus or Artifactory). You can also use a network folder using the file:// protocol for quick startup.

In the pom.xml you need to add the <distributionManagement> section (in the taglib pom.xml) to specify the folder / proxy the artifacts are uploaded to. A mvn deploy will then build and copy the jar file for you.

Other developers need to add that location as repository in settings.xml (I dont recommend doing that in pom.xml) or if you setup a maven proxy configure a mirrorOf in settings.xml

There are archteypes available (project templates) that will help you creating initial project structures: http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

see also: http://maven.apache.org/guides/getting-started/index.html

Upvotes: 1

Related Questions