MOP

cleans up your Java classpath mess - easily run any Java application from the command line

What is MOP?

MOP is a small utility for executing Java programs which are stored as artifacts like jars or bundles in a Maven repository.

MOP automatically deals with the following for you

  • transitive dependencies
  • downloading artifacts from remote repositories and caching them locally
  • setting up your classpath

Using MOP

First download and install mop then you can run it from the command line as follows

  mop
  

This will then output the command line help to show the command line arguments you can use.

If you are inside the download directory (or you copy the mop.jar to your current directory) then you can just execute the jar directly instead of running the mop script as follows

  java -jar mop.jar
  

Running Java programs

The following example will boot up one of the Apache Camel example programs

  mop run org.apache.camel:camel-example-pojo-messaging org.apache.camel.spring.Main
  

The run command takes a maven artifact name then a Java class name along with optional command line arguments. The maven artifact uses the following format

  • groupId:artifactId[[:type[:classifier]]:version]
so that you can omit the type, classifier and version if you require. You typically may supply just groupId, artifactId, version if you like - or if you really need to specify type (jar/war etc) and classifier if needed. Typically the commands default to the right type; for example when using the war command it will default the type to be war for you.

The above will startup MOP in a JVM and then start the Main inside the same JVM in a separate class loader. If you want MOP to fork a separate JVM process then switch the run command with exec as follows

  mop exec org.apache.camel:camel-example-pojo-messaging org.apache.camel.spring.Main
  

If the jar is an executable jar so that its Jar manifest has a Main-Class entry, then you can use the jar command instead which allows you to omit the Java class name as follows

  mop jar org.apache.camel:camel-example-pojo-messaging
  

Running Web Applications

If you have a WAR in a repository somewhere you can run it via

  mop war <artifacts>
  

For example if you want to run the ActiveMQ Web console and broker you can run the following

  mop war org.apache.activemq:activemq-web-console:5.2.0
  

Though there is a simple alias to let you run Apache ActiveMQ

  mop broker:5.2.0
  

Scripting Goodies

Sometimes, you just want to see what command line you need to type in to run the Main. Try this

  mop echo org.apache.camel:camel-example-pojo-messaging org.apache.camel.spring.Main
  

Other times, you just need need the CLASSPATH so you can use it in a manually crafted script your running. Try this.

  mop classpath org.apache.camel:camel-example-pojo-messaging
  

Or maybe you just want to copy all those jars in the classpath to directory, perhaps your trying to populate a `WEB-INF/lib` directory.

  mop copy org.apache.camel:camel-example-pojo-messaging WEB-INF/lib