Debug example of preparing code and JAR file
Consider the following sample Java code, which is the basis for a JMon application. The files containing the complete code are Simple.java and Tick.java, which are located in the samples\java_monitor\simple\src directory of your Apama installation.
@Application(name = "Simple",
author = "John Doe",
version = "1.0",
company = "Apama",
description = "sample",
classpath = ""
)
@MonitorType(description = "A simple Java monitor")
public class Simple implements Monitor, MatchListener {
public Simple() {}
public void onLoad() {
EventExpression eventExpr =
new EventExpression("all Tick(*, >10.0):t");
eventExpr.addMatchListener(this);
}
public void match(MatchEvent event) {
Tick tick = (Tick)event.getMatchingEvents().get("t");
tick.emit();
}
}
Here is the Tick class (Tick.java):
@EventType(description = "Event that signals a stock trade")
public class Tick extends Event {
public String name;
public double price;
public Tick() {
this("", 0);
}
public Tick(String name, double price){
this.name = name;
this.price = price;
}
}
Assume that Simple.java is part of your Apama project. Open or create the project in Software AG Designer and add the code if necessary. Note that this code is already annotated with the information required for creating the JMon JAR manifest.
The next step is to compile and pack the class bytecode into a JAR file, and create the manifest that flags and describes this JAR file as a JMon application. You can do this by setting up a new builder in the project properties in Software AG Designer or through the command line. For the sake of simplicity, the standard command line calls are described below:
1. Compile the Java code. For example:
javac -classpath "%APAMA_HOME%/lib/ap-correlator-extension-api.jar;%APAMA_HOME%/lib/ap-util.jar" *.java
2. Package the classes into your JAR file:
jar cf simple-jmon.jar *.class
3. Use the JarProcessor utility to create the manifest for the JAR file. For example, if the JAR is called simple-jmon.jar, enter:
java -classpath "%APAMA_HOME%/lib/ap-correlator-extension-api.jar" com.apama.jmon.annotation.JarProcessor simple-jmon.jar