0

I have a simple java main class and can execute it using the below command on server java com.....MainClass

Now we are trying to use Maven in our application.

I am seeing on web that the maven command to execute java program is mvn exec:java -Dexec.mainClass=com......MainClass

Can I still use regular java command or do I have to use the maven command exec:java?

It's not clear to me when to use the maven exec:java command.

Please help me understand when to use regular java command and when to use the maven exec:java command. when I use Maven can I still execute program using regular java command.

opai
  • 253
  • 1
  • 5
  • 14

2 Answers2

1

Maven

According to https://maven.apache.org/what-is-maven.html Maven's objectives are

  • Making the build process easy
  • Providing a uniform build system
  • Providing quality project information
  • Providing guidelines for best practices development
  • Allowing transparent migration to new features

So, you should use Maven for building your project... like building a JAR package with main class.

Running JAR packaged main class

See this answer or this Oracle's tutorial for running a JAR packaged Java class.

You can also use Maven for running the main class but you should not make your production environment depended on Maven.

haba713
  • 2,465
  • 1
  • 24
  • 45
1

maven is mainly a dependency mangement and a build tool.

u can still use java command to run your main class from the jar generated by maven under the target folder of your project.

java -cp "yourProject/target/folder-containing-dependenc-jars-if-exist/*:yourProject/target/thejar.jar" package.mainClass

ps: use the ":" separator on linux system , if you are under windows use ";"