Currently, the only reasonable way to achieve this goal is to use the command line from Java (runtime.exec). You should use im4java for this, as suggested above. im4java allows you to create the string "gm command" using calls to java methods, and also provides a number of other useful functions.
The big advantage of using this method over actual language relationships is its simplicity and reliability. Reliability is important, especially if your Java application runs on a Java server or servlet engine such as tomcat. The reason is that a memory error or other error when using language bindings can cause the failure of the entire Java virtual machine.
source share