Search code examples
javamavenjarm2eclipse

How do I create a JAR with m2e (m2eclipse)?


I'm new to Maven and m2e. It frustrates me that I have to ask this question, but the sparse m2e documentation and Google are failing me.

How do get m2e to build a JAR? I understand that this should happen during the maven package phase, but m2e doesn't seem to do this as part of the build process and I can't find a way to explicitly execute the package phase in Eclipse (nor any other phases that aren't part of the default build).

Thanks.


Solution

  • As long as you have your POM.xml file with the following parameters:

    <modelVersion>[a model number eg 4.0.0]</modelVersion>
    <groupId>[a group id eg com.myapp]</groupId>
    <artifactId>[a unique artifact id within your packages eg myapp]</artifactId>
    <version>[the version number eg 1.0-SNAPSHOT]</version>
    <packaging>jar</packaging>
    <name>[the name eg myapp]</name>
    

    then you just need to run maven build with the goals clean install to create a jar file from your project. You can run maven build by right clinking on the project and going to run > maven build ...

    The jar will be created in [project dir]/target