1

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).

DVK
  • 126,886
  • 32
  • 213
  • 327

2 Answers2

2

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

maydawn
  • 498
  • 8
  • 20
  • "you meant to ask if you need to declare a main class for maven" - yes, that's exactly what I was asking. – DVK Jul 14 '17 at 13:52
  • Ok then. If that answered your question, and you have no further ones, please consider marking it as an answer – maydawn Jul 14 '17 at 15:06
  • I'd prefer a bit more references to back up your "no" claim with proof, but this is already good enough for "accept". thanks! – DVK Jul 14 '17 at 15:15
-1

What do you mean by "main.class"? A class Main? No, it's not required.

If you meant a method main, an entrypoint to execution like below, it's not required either. Unless you want to execute the code directly.

public static void main(String[] args) {

}
Alfabravo
  • 7,493
  • 6
  • 46
  • 82
gramos
  • 67
  • 1
  • 11
  • "main.class" is a property in pom.xml (as i was hoping is obvious from the tagging, sorry :) The question isn't about classes – DVK Jul 13 '17 at 20:16