Thursday, January 8, 2009

Making Eclipse (Ganymede) Create Your Custom JSF jar file

Apparently I am an IDE man. I know it is possible to remember the flags to run the jar command so that you can package up a set of directories, but I would rather let the IDE do the work.

But I am having a bit of difficulty making Eclipse do what I want.
I decided to package up one of my custom components into a jar file, so that someone (like me) could use the component by dropping the jar into their application’s WEB-INF/lib directory.

So I moved everything my components needed to a different project, and made the project path have every library it needed to build the java files. This worked fine.

When you want to create a jar file for your custom JSF component, your jar is pretty simple. The root directory of the jar contains package trees with class files on the leaves of these trees, and resource files like message bundles or anything else you would put in the src directory to have it on the class path.

In Eclipse-ese, creating a Jar is called “export…” So if you export to a Jar by right-clicking your project, selecting Export… from the context menu, and following the instruction in the Jar export wizard when all is said and done your classes will be in the right place if you select the src directory and the build directory that eclipse manages for you. But the META-INF directory that eclipse builds for you as a sibling to the WEB-INF file cannot stay where it is if your Jar is going to have the META-INF file in the right place. The right place for the META-INF file in your jar is in the root directory of the Jar. In the jar should be your faces-config.xml and your whatever.tld file where you describe your tags.

So my solution (which worked) was to move the META-INF from being a child of the Web Content directory, to being a sibling of the Web Content directory. Then you can simply check the box next to the META-INF directory, and it is moved to the right place.

No comments: