Using Plug-in Resources

The Logifier plug-in requires that the Logging Aspect file be bundled in the plug-in JAR so that, at runtime, it can weave the Logging Aspect onto the target project's code.

How do I do that?

There's a special place for plug-in resources in a plug-in project: src/plugin-resources. Figure 6-4 shows the Logifier plug-in file structure showing the Aspect saved in a Logging.aj file.

Logifier plug-in's file structure showing the Logging.aj plug-in resource

Figure 6-4. Logifier plug-in's file structure showing the Logging.aj plug-in resource

Tell Maven to copy these resources in the generated plug-in JAR. You do this by using the resource element in the plug-in's project.xml file:

  <build>
  [...]
  
    <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>

This means that your Logging.aj file will be located in a plugin-resources/aspect directory inside the generated plug-in JAR.

Now you can reference any resource from your plugin.jelly file, or in the plugin.properties file using the ${plugin.resources} expression. For example, to reference the Logging.aj Aspect you'd write ${plugin.resources}/aspect/Logging.aj. You'll see how this is used in the next section.

Get Maven: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.