7.7 AgenPro Maven Plugin
The AgenPro Maven Plugin can be used to generate code for any language or format by using customized code generation templates. However the integration for Java is the primary use case.
Although the AgenPro command line interface provides already means to integrate AgenPro into an automated build process, the AgenPro Maven Plugin further improves and facilitates this integration for Java.
7.7.1 Upgrade From AgenPro Maven Plugin Version 3
Version 3.x of the AgenPro Maven plugin used Maven 2.x. With version 4 you need to use at least Maven 3.1.1 or later.
The Plugin now overwrites the Job Property package with the <packageName> parameter provided in the plugin configuration. This behavior is new and might cause problems if you used the MIB node based property package in your custom template code (or if you need to use old templates for SNMP4J-Agent 1.x).
The MIB node attribute will not be overwritten anymore by the Maven plugin and because the MIB node attribute has precedence over the job property package the MIB node value will be used by the generation templates.
7.7.2 Maven Plugin Installation
To install and use the AgenPro Maven Plugin you need
Maven 3.1.1 or later
AgenPro 4.0 or later.
Maven is available under the Apache License and is available for download from http://maven.apache.org.
Before you can start to install the AgenPro Maven Plugin you need to setup a local repository for your Maven installation and to specify a shortcut for the AgenPro Maven plugin prefix.
You can define your Maven settings in the settings.xml file in the .m2 directory within your home directory. The settings.xml file should contain at least the following configuration:
<settings>
<pluginGroups>
<pluginGroup>com.oosnmp.agenpro.maven.plugins
</pluginGroup>
</pluginGroups>
<localRepository>C:/maven/repo</localRepository>
</settings>
The pluginGroups element specifies a shortcut for the plugin and the localRepository element where local third-party libraries can be stored (cached).
SNMP4J and SNMP4J-Agent JARs
Download SNMP4J and SNMP4J-Agent JAR files from https://oosnmp.net/dist/release/org/snmp4j and unpack them in a local folder. Then run the following Maven commands from the dist and lib directories respectively:
mvn install:install-file -Dfile=SNMP4J.jar
-DgroupId=org.snmp4j -DartifactId=snmp4j
-Dversion=2.3.0 -Dpackaging=jar -DgeneratePom=true
mvn install:install-file -Dfile=SNMP4J-Agent.jar
-DgroupId=org.snmp4j -DartifactId=snmp4j-agent
-Dversion=2.2.2 -Dpackaging=jar -DgeneratePom=true
AgenPro JAR
Download the AgenPro.jar file and install it into your Maven repository:
mvn install:install-file -Dfile=agenpro4.jar
-DgroupId=com.oosnmp.agenpro -DartifactId=agenpro
-Dversion=4.0.0 -Dpackaging=jar -DgeneratePom=true
AgenPro Maven Plugin
Download the AgenPro Maven plugin and install it into your Maven repository:
Please always adjust the version parameter to the actual version of the plugin you are installing.
mvn install:install-file -Dfile=agenpro4-plugin.jar
-DgroupId=com.oosnmp.agenpro.maven.plugins
-DartifactId=agenpro-plugin -Dversion=4.0.0
-Dpackaging=jar -DgeneratePom=true
7.7.3 Using the AgenPro Maven Plugin
After installation of the plugin and the JARs it depends on, you can setup your SNMP agent Maven project. As a starting point for your own project, use the template project provided in directory agenpro-mvn-task of the AgenPro‘s installation directory or download it from http://www.agentpp.com/agenpro-mvn-task.zip.
The execution of the help:describe goal should print a description of the agenpro goal and its parameters. If you get a Maven error instead, please check if the AgenPro plugin is properly installed according to the description in “Maven Plugin Installation” on page 42.
To get a description of the plugin options, execute the following Maven goal:
mvn help:describe -DartifactId=agenpro-plugin
-DgroupId=com.oosnmp.agenpro.maven.plugins -Ddetail
Before you can use the AgenPro Maven plugin you will have to configure your license key first. Edit the settings.xml file in your .m2 directory (see “Maven Repository Settings” on page 42) and add the agenProLicenseKey property as follows:
...
<profiles>
<profile>
<properties>
<agenProLicenseKey>lic / key</agenProLicenseKey>
</properties>
</profile>
</profiles>
Now edit the pom.xml file in the agenpro-mvn-task directory to define
1. the directory where the plugin should search for MIB specification files
2. the MIB modules from that files you want to generate code for
3. the AgenPro project file that contains the code generation settings and properties.
By default, the project file for the latest SNMP4J-Agent release is used and the MIB specifications are read from the src/main/smi folder.
Creating and Compiling the SNMP Agent
To create a simulation agent based on Agent.java run Maven with
mvn clean install
in the agenpro-mvn-task directory. Maven will then generate the Java classes for the specified MIB modules in the src/generated folder, compile them together with the Agent.java class and build a JAR with (and without) all dependencies included in the target folder.
Running the SNMP Agent
To run the created agent simply execute
java -jar snmp4j-agenpro-agent-1.0-SNAPSHOT-jar-with-dependencies.jar udp:0.0.0.0/4700
The above command will run the agent on all local IP addresses on port 4700 using the UDP protocol.