Maven-related problems are often encountered, and this is from the previous article:

  • The Maven dependency problem, you dare to say you didn’t met: mp.weixin.qq.com/s/SzBbDtyRU…
  • This is how Maven snapshot versions really smell! : mp.weixin.qq.com/s/S0X1qY4uR…

Here’s another one today. First look at the error message. It looks familiar.

Caused by: java.lang.ClassNotFoundException: net.sf.json.JSONException
  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
  ... 57 more
Copy the code

Aliyun-log: aliyun-log: aliyun-log: aliyun-log: aliyun-log

< the dependency > < groupId >.net. Sf. Json - lib < / groupId > < artifactId > json - lib < / artifactId > < version > 2.4 < / version > <classifier>jdk15</classifier> </dependency>Copy the code

The jSON-lib jar package is available in the lib directory on the server. Check out json-lib-2.4.jar. Error: JSONException can’t be found, json-lib is not loaded. Class Path is set to json-lib in manifest.mf.

Jar = json-lib-2.4-jdk15.jar = json-lib-2.4-jdk15.jar = json-lib-2.4-jdk15.jar = jdk15

This time back to see the above classifier, which specifies the jdk15. Classifier is often used to distinguish different JDK version the generated jar package, if you specify the classifier, then the jar is to add the value of the classifier, which is a json – lib – 2.4 – jdk15. Jar is correct.

Jar (jSON-lib-2.4-jdk15.jar); jar (json-lib-2.4.jar); jar (json-lib-2.4.jar); jar (json-lib-2.4.jar);

Then look at the packaging method of the project, again the old Assembly, in the packaged JAR name modification.

<outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}</outputFileNameMapping>
Copy the code

The format is already fixed, and the classifier is not in the format, so the jar name will be changed after packaging. The solution is to define the classifier in outputFileNameMapping.

However, the classifier will not be available to every JAR, if you use the artifact directly. The classifier will not work, and there will be a problem with the one without the classifier. ${dashClassifier = dashClassifier; ${dashClassifier = dashClassifier; }, perfect solution.

<outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}${dashClassifier? }.${artifact.extension}</outputFileNameMapping>Copy the code

Documentation reference:

Maven.apache.org/plugins/mav…

About the author: Yin Jihuan, a simple technology lover, the author of Spring Cloud Micro-service – Full stack Technology and Case Analysis, Spring Cloud Micro-service Introduction combat and Progress, the founder of the public account Monkey World.

I have organized a very complete learning material. If you are interested, you can search “Monkey World” on wechat and reply to the keyword “learning material” to obtain the Spring Cloud, Spring Cloud Alibaba, Sharing-JDBC sub-library sub-table and task scheduling framework XXL-job that I have organized. MongoDB, crawler and other related information.