Skip to content

Instantly share code, notes, and snippets.

@EntityReborn
Created December 20, 2013 02:18
Show Gist options
  • Save EntityReborn/8049549 to your computer and use it in GitHub Desktop.
Save EntityReborn/8049549 to your computer and use it in GitHub Desktop.

#Example Extension/Extension Skeleton

This maven project is a sample extension layout that provides a basic framework, with all the proper checks in place as well as a few utilities to get you started. It is built with NetBeans and Maven in mind, although other configurations might be possible, with less functionality (compile time errors, etc).

##Usage ###Standalone use This method makes for a simpler way to get up and running, but requires you to clone the original repo for each project.

  1. Clone this repo from where it's hosted.
  2. Remove the .git folder. Can't skip this one!
  3. Run mvn clean from the pom directory.
  4. ...?
  5. Profit!

###Archetype installation This method adds a permanent copy of the template in your maven repo, allowing for quick replication across new projects.

  1. Clone this repo from where it's hosted.
  2. Run mvn archetype:create-from-project from the pom directory.
  3. Change to the target/generated-sources/archetype/ directory, which is where the archetype resides.
  4. Run mvn clean install from this directory.
  5. Tell maven to crawl it's local repo for available archetypes by running mvn archetype:crawl from anywhere.
  6. If you use an IDE with maven integrated, ask it to refresh it's cache.
  • Netbeans: Go to Tools, Options, select the Java icon at the top, then the Maven tab, select Index in the Categories list, and finally press the Index Now button.

Once the archetype is installed, you can use the New Project option.

  1. From the New Project wizard window, select maven from the categories pane
  2. Select Project from Archetype in the Projects pane.
  3. Wait for the list to populate.
  4. In the Search box, type chextension-archetype.
  5. Select chextension-archetype in the Known Archetypes list, and press Next.
  6. Fill out the data required then click Finish.
  7. ...?
  8. Profit!

Currently, you will need to rename the project from CHExtension. This is only visible/used in an IDE, and has no affect on the end result.

More info on creating (and thus updating) an archetype from an existing maven project can be found here.

##After project setup After your project is setup and ready to be developed on, there are a few things that need to be adjusted, before we get going.

###/pom.xml This file, as usual, is what defines the build process for your extension, including special directives and procedures, and defines what dependencies are needed. There are a few helpful comments, so be sure to read thru it.

Most notably, there is a helpful embedded version system, tied into git, if you use it. You need to have the project committed to an initialized git repo, and un-comment the relevant <scm> and <plugin> blocks for this to function correctly.

The project defaults to the more lenient MIT license. A LICENSE file is not provided for you, but the pom declares MIT as the default license. Feel free to change this!

The exec-maven-plugin and maven-processor-plugin build plugins aren't necessary, but they provide automatic verification and caching for when the extension is being compiled. Removing these is not advised, and could cripple startup time in larger projects as well as potentially cause errors at runtime.

###/src/main/java/some/package/here/LifeCycle.java This class is what aids in managing life events of your extension. Starting up, shutting down, reloading aliases, and some features are handled here.

First off, we need to change the identification tag for this extension, to "personalize" your extension. You will need to change exampleextension in the @CHExtension line to something that identifies your extension. For example, an extension exposing IRC functionality might say @MSExtension('CHIRC'). When this extension is referenced to in logs, etc, this is the name that will be used to identify it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment