How to compile Maven project from command line with all dependencies?

前端 未结 2 1407
面向向阳花
面向向阳花 2020-12-25 09:19

I have a Maven project that I can normally compile and run from eclipse but when I compile it from command line it\'s dependencies are missing and I\'m getting errors. I can

2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-25 09:47

    Javac knows nothing about maven. Thus it will not utilize the maven pom.xml.

    The value of maven is that it removes the manual work of building, testing and releasing a project.

    This includes getting dependencies, and running javac with them added to the classpath of the javac command.

    You can manually execute javac after maven downloads dependencies to ~/.m2/repository. However you'll need to tell javac where to find the jars. Thus is done via the classpath argument.

    If you are trying to run the project after using mvn to compile it, you'll need to do this in the same folder where your .class files were placed. Thus should be /target/java or similar.

提交回复
热议问题