Doorgaan naar hoofdcontent

Posts

Er worden posts getoond met het label main-class

Starting a main-class with maven

To run a traditional java program we have to start a main class, preferably in a JAR. However, these jars usually have dependencies, which need to be on the classpath. This leads us to two options: 1) we create a 'fat' jar, in which all are included (see one-jar, which I talked about here ) 2) when we are allowed to use maven, we can let maven create the classpath for us. In this post, I'll discuss option 2. With the maven exec:java plugin (documented here ), we can execute a main class from a specific jar. Maven then builds the classpath! For an example, we assume we have a main class in my.personal.projects.MainClass, which is hosted in the my.personal.projects.coolapp-1.0.jar, which is in the repository. It might have any number of dependencies. A sample pom.xml looks like the following:      <dependency>         <groupId>my.personal.projects</groupId>         <artifactId>coolapp<...

Creating a single jarfile with all dependencies

Sometimes, you do not have the option to deploy to an applicationserver, and it is necessary to release a single stand-alone jar. For this, we can use the excellent one-jar code, or, the maven one-jar plugin. A simple link to the documentation should suffice. It is exactly what you want as it supports it's own classpath, ensuring that multiple files can exist with the same name (of course, it'll warn you about that, but). It's much better then the normal maven assembly plugin, as it gives all sorts of problems. You can then use the normal java -jar myOneJar.jar to start your program. Of course, if you're allowed to use maven, you can let maven set up the classpath for you... But that will be in a different post.