Wednesday, December 2, 2015

Example of running Java program calling external "jar" file

In this example, my java program is calling Juniper's Netconf.jar to interact with routers running JUNOS.
reia-mba:~/Devel/SRXFlowInfo/bin reia$ java -cp ../lib/Netconf.jar:. getFlowInfo arg0 arg1 arg2

In this example,

  • "reia-mba:~/Devel/SRXFlowInfo/bin reia$ " is the command prompt on my MacBook Air.
  • The next portion of the command is "java" - the name of Java virtual machine.
  • Next up is "-cp", this is called a flag. This particular flag - "cp" is an abbreviation of "CLASS PATH". This flag consumes the next argument - "../lib/Netconf.jar:.", which is the location of "Netconf.jar" Class Library that provided by Juniper.
  • getFlowInfo is the class that we want to execute. It is shown in the directory as getFlowInfo.class. This is the output of Java compiled code. Pretty much an equivalent of a.out, I think. I will have to look this out later on.
    One note about this .class extension. When you want to run the Java program, don't put in the .class extension. You will get an error that the java can not find "main"

No comments:

Post a Comment