javamavenpom.xmlmainclass

Is "main.class" XML element required in Maven's pom.xml if the artefact is a library?


I'm creating a pom.xml for a project that is a library.

Is <main.class> POM XML element under <properties> required for this?

(the library has a small test Main.java which I didn't really intend to include in the library JAR file in the first place, so I'd rather not use that test file as main.class unless required).


Solution

  • Is “main.class” XML element required in Maven's pom.xml if the artefact is a library?

    No.

    At the most basic level, maven creates jars from projects of a certain structure, it does not care if you have a main class or not. Using mvn clean install:

    This command tells Maven to build all the modules, and to install it in the local repository. The local repository is created in your home directory (or alternative location that you created it)... (which other projects can declare as a dependency)

    The only time maven cares about having a main class, is when you want to make the jar executable