Maven for Python Programmers

Maven is the most commonly used build automation tool for Java programmers. While there is no Python tool that matches Maven feature for feature, it is analogous to a package management system like pip in Python, or PyBuilder, or Distutils.

It is also the single most convenient way to get up and running with Deeplearning4j, which offers a Scala API whose syntax will strike many Python programmers as eerily familiar, while offering them powerful concurrent features.

As a build automation tool, Maven compiles source to byte code and links object files to executables, library files etc. Its deliverable is a JAR file, created from Java source, as well as resources for deployment.

(A JAR is a Java ARchive, a package file format that aggregates many Java class files, associated metadata and resources such as text and images. It’s a compressed file format that helps Java runtimes deploy a set of classes and their resources.)

Maven dynamically downloads Java libraries and Maven plug-ins from Maven Central Repository which are specified in an XML file that stores a Project Object Model, which you’ll find in the file POM.xml.

Alt text

To quote Maven: The Complete Reference:

	Running mvn install from the command line will process resources, compile source, execute unit tests, create a JAR and install the JAR in a local repository for reuse in other projects. 

Like Deeplearning4j, Maven relies on convention over configuration, which means that it provides default values that allow it to run without the programmer having to specify each parameter for each new project.

If you have both IntelliJ and Maven installed, IntelliJ will allow you to choose Maven when creating a new project in the IDE, and will then take you through the wizard (we comment more thoroughly on the process in our Getting Started page). That is, you can make the build happen from within IntelliJ, without going anywhere else.

Alternatively, you can use Maven from your project’s root directory in the command prompt to freshly install it:

	mvn clean install -DskipTests -Dmaven.javadoc.skip=true

The above command instructs maven to clean any directories of compiled files before running install. This makes sure that the build is a clean build from scratch.

Several useful books have been written about Apache Maven. They are available on the website of Sonatype, the company that supports the open-source project.

Troubleshooting Maven

  • Older versions of Maven, such as 3.0.4, are likely to throw exceptions like a NoSuchMethodError. This can be fixed by upgrading to the latest version of Maven.
  • After you install Maven, you may receive a message like this: ‘mvn is not recognised as an internal or external command, operable program or batch file.’ That means you need Maven in your PATH variable, which you can change like any other environmental variable.
  • As the DL4J code base grows, installing from source requires more memory. If you encounter a Permgen error during the DL4J build, you may need to add more heap space. To do that, you’ll need to find and alter your hidden .bash_profile file, which adds environmental variables to bash. To see those variables, enter env in the command line. To add more heap space, enter this command in your console: echo “export MAVEN_OPTS=”-Xmx512m -XX:MaxPermSize=512m”” > ~/.bash_profile

Further reading:

Chat with us on Gitter