Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

java - Maven clean causes spring app run to fail

I guess there is something I don't quite understand about the mvn clean command.

I use mvn spring-boot:run to run my Spring App, but whenever I run mvn clean, running mvn spring-boot:run right away returns the following :

mvn clean error

When I run my app before cleaning my app, it works just fine.

Someone I know that has more Spring Apps experience than me, told me to use mvn clean before running my app whenever I make a major change (dependencies etc).

Any idea why I get this error ?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Typically this error happens when maven cannot find a suitable JDK. When you run

  $ mvn clean ...

Maven delete the target folder, therefore the .jar file and all the classes resulting from the compilation cycle. Therefore when you ask maven to run your application it needs to compile and package you application again. That is the reason why you need a JDK installed.

Your best guesses are:

  1. You have not installed yet a JDK
  2. The JDK has been installed, but you have not defined the environment variable JAVA_HOME (for linux or Mac: export JAVA_HOME=path/to/java/folder)
  3. You have done the above, but you have not close and reopened the terminal (or command line)

I hope this might shed some light


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...