This article was reproduced from: http://blog.csdn.net/qqhjqs/article/details/51491516
Using MAVEN to manage dependencies between jar packages in a Web project is very easy to use, but sometimes there are problems
With Net.sf.json in the project.
The following jar packages are configured with Maven
Jakarta Commons-lang 2.5 Jakarta commons-beanutils 1.8.0 Jakarta commons-collections 3.2.1 Jakarta Commons-logging 1.1.1 ezmorph 1.0.6
If you put the above jar package in a non-MAVEN managed project under LIB, there will be no problem
But under Maven, when the code runs to
Jsonobject.from (str), the console error message, the errors are as follows:
Java.lang.noclassdeffounderror:org/apache/commons/lang/exception/nestableruntimeexception at Java.lang.ClassLoader.defineClass1 (Native Method) at Java.lang.ClassLoader.defineClass (Unknown Source) at JAVA.S Ecurity. Secureclassloader.defineclass (Unknown Source) at Org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal (webappclassloaderbase.java:2496) at Org.apache.catalina.loader.WebappClassLoaderBase.findClass (webappclassloaderbase.java:860) at Org.apache.catalina.loader.WebappClassLoaderBase.loadClass (webappclassloaderbase.java:1302) at Org.apache.catalina.loader.WebappClassLoaderBase.loadClass (webappclassloaderbase.java:1167) at Com.iquant.simulated.messaging.StrategyManageTopicListener.processMessage (strategymanagetopiclistener.java:13) At Sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method) at Sun.reflect.NativeMethodAccessorImpl.invoke ( Unknown Source) at Sun.reflect.DelegatingMethodAccessorImpl.invoke (Unknown SOURCE) at Java.lang.reflect.Method.invoke (Unknown source)
At first I thought the package did not download the success, or the version is wrong, at that time, according to this idea, engaged in the majority of days, make sure that the jar package is downloaded, the version is also correct.
It occurred to me that the string was pulled out and ran in the main method to see if it was successful, and the result was as successful as I thought, which means that during the web run
"No related packages found"
Follow this idea went down all kinds of Baidu search.
And then I go to the Tomcate release directory to open the project in the Web-inf Lib
Check to see if there are no packages found---No
And then look at the configuration statement for Pom.xml configuration file Commons-lang
<Dependency> <groupId>Commons-lang</groupId> <Artifactid>Commons-lang</Artifactid> <version>2.6</version> <Scope>Provided</Scope> </Dependency></span>
<scope>provided</scope> get rid of success!
Summary of the following, about the project under MAVEN, if there is a problem with the jar package, this should be checked
Whether to download the full---can place the jar package in the file, delete the download again
Whether the version is consistent---can globally define a version, download related use version
Whether it is packaged---see if there are any corresponding jar packages under Webinf-lib in the corresponding project under the Tomcat file, and then look at how the Pom.xml is configured
Maven has some provisions on the scope of the jar package used
That is, add <scope>[compile after the jar package configuration, Provided,runtime,test,system]</scope>
Name |
Explain |
Compile (compilation scope) |
Compile is the default scope, and if a scope is not provided, the scope of the dependency is the compilation scope. Compilation scope dependencies are available in all classpath, and they are also packaged. |
Provided (range provided) |
Provided dependencies are only used when the JDK or a container has provided the dependency. For example, if you develop a Web application, you may need to compile the classpath The servlet API is available to compile a servlet, but you don't want to pack a good war This servlet API is included in the Servlet API JAR by your application server or servlet Containers are provided. A dependency that has been provided for scope is available at compile classpath (not at runtime). They are not transitive and will not be packaged.
|
Runtime (Runtime Range) |
Runtime relies on the need to run and test the system, but it is not required at compile time. For example, you might only need the JDBC API JAR when compiling, but only if you need the JDBC driver to run it. |
Test (Testing range) |
Test range dependencies are not required for general compilation and runtime, and they are available only during the test compilation and test run phases. |
System (systems-wide) |
The system-wide dependency is similar to provided, but you must explicitly provide a The path to the JAR file. This is done to allow compilation based on local objects, which are system class libraries Part of it. Such artifacts should always be available, and Maven will not look for it in the warehouse. If you set a dependency scope to a system scope, you must also provide a systempath Elements. Note that this range is deprecated (you should always try to reference dependencies from a public or custom Maven repository).
|
Maven under Java.lang.NoClassDefFoundError