Question about maven dependencies

maven jar can be very easy to manage package dependencies.

Problems encountered in the past few days is: using maven run flink program prompts the idea

java.lang.ClassNotFoundException
java.lang.NoClassDefFoundError

 

-libraries is commenced by the idea project structure (shortcut Ctrl + Alt + Shift + s) jar package, there are a lot jar package, manually add one by one is not the case Yeah.

Relearn Liao Xuefeng teacher's maven.

maven would have been able to manage their own package depends. So maven configuration is wrong?

.M2 delete all the files inside the directory repository, the idea right project-maven-reimport, re-download jar package from Ali cloud (to be configured in settings.xml .m2 directory).

Modify pom.xml <flink.version> here 1.9.1 </flink.version> of flink version 1.9.1.

jar package has been downloaded again good. NoClassDefFoundError problem still occurs.

View .m catalog has been downloaded jar package, flink-streaming-java_2.11-1.9.1.jar have that class, why not import it?

The original: pom.xml in dependency is provided, not compile.

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-java</artifactId>
<version>${flink.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
<version>${flink.version}</version>
<scope>compile</scope>
</dependency>

 

Maven defines several dependencies, are compile, test, runtimeand provided:

scope Explanation Examples
compile You need to use the jar package compile time (default) commons-logging
test Compile need to use the jar package when Test junit
runtime No, but need to use runtime compile time mysql
provided Need to use compile-time, but the runtime provided by a server or JDK servlet-api

Wherein, the default compileis the most common, Maven of this type will depend directly into the classpath.

The dependency modified to compile, in the project right -maven-reimport, run the program. So far, the problem is solved.

Ask: In fact, this procedure successfully many times before I had to run, why run successfully started it?

 

Inspiration: to solve the problem can not be reckless, but to explore the nature of the problem and the tools to start from the source.

 

reference:

https://www.liaoxuefeng.com/wiki/1252599548343744/1309301178105890

https://blog.csdn.net/qq_24003079/article/details/87920001

http://wuchong.me/blog/2018/11/07/5-minutes-build-first-flink-application/

Guess you like

Origin www.cnblogs.com/zgq25302111/p/12077807.html