6.2. Installing a Plug-in from Its SourcesNow that you know how to write a plug-in, let's install your newly created Jarexec plug-in in your local Maven installation. 6.2.1. How do I do that?A plug-in is packaged as a JAR, so the first step is to configure the Jarexec project's build so that it generates a valid plug-in JAR. A valid plug-in JAR must contain some requisite files: plugin.jelly, plugin.properties, and (optionally) plug-in resources. Plug-in resources, as you will see in a following lab, are simply any file that is put in a plugin-resources/ directory in the JAR. You create a plug-in JAR by calling the plugin:plugin goal of the Plugin plug-in. In practice, this goal simply calls the jar:jar goal internally. To generate a valid JAR configure your jarexec/project.xml file and define a resources section to include plugin.jelly, plugin.properties, and any plug-in resources in your plug-in's JAR file: <?xml version="1.0"?> <project> <pomVersion>3</pomVersion> <artifactId>jarexec</artifactId> <name>JAR Executor</name> <groupId>mdn</groupId> [...] <build> <sourceDirectory>src/main</sourceDirectory> <unitTestSourceDirectory>src/test</unitTestSourceDirectory> <unitTest> <includes> <include>**/*Test.java</include> </includes> </unitTest> <resources> <resource> <directory>src/plugin-resources</directory> <targetPath>plugin-resources</targetPath> </resource> <resource> <directory>.</directory> <includes> <include>plugin.jelly</include> <include>plugin.properties</include> <include>project.xml</include> </includes> </resource> </resources> </build> </project> To build the plug-in and install it in your local Maven repository, run the plugin:install goal. Here is the output of this goal: C:\dev\mavenbook\code\plugins\jarexec>maven plugin:install [...] plugin:plugin: java:prepare-filesystem: java:compile: [echo] Compiling to C:\dev\mavenbook\code\plugins\jarexec/target/classes [echo] No java source files to compile. java:jar-resources: test:prepare-filesystem: test:test-resources: test:compile: [echo] No test source files to compile. test:test: [echo] No tests to run. jar:jar: plugin:install: [delete] Deleting 1 files from C:\apps\maven-1.0.2\plugins [delete] Deleting 4 files from C:\Documents and Settings\Vincent Massol\.maven\cache [delete] Deleted 2 directories from C:\Documents and Settings\Vincent Massol\.maven\cache [copy] Copying 1 file to C:\apps\maven-1.0.2\plugins BUILD SUCCESSFUL 6.2.2. What just happened?You just defined a plug-in's resources and installed a plug-in in your local Maven installation. Section 2.1 showed you how to install a plug-in from a remote repository, and this lab shows you how to install a plug-in from a local source. You should now be able to download, customize, and install any plug-in you may need to work with. The plugin:install goal simply builds a plug-in and installs it in your local Maven installation. It does this by copying your plug-in to MAVEN_HOME/plugins. Maybe you're thinking about publishing your plug-in at this stage. Hold on! You haven't tested it yet! Let's do that now; you'll discover how to publish your plug-in at the end of this chapter. |