<p>I am getting a <code>NoClassDefFoundError</code> when I run my Java application.  What is typically the cause of this?</p>

[{'answer_id': 34419, 'author': 'Mocky', 'author_id': 3211, 'author_profile': 'https://Stackoverflow.com/users/3211', 'pm_score': 9, 'selected': True, 'text': '<p>This is caused when there is a class file that your code depends on and it is present at compile time but not found at runtime. Look for differences in your build time and runtime  classpaths. </p>\n'}, {'answer_id': 34444, 'author': 'shsteimer', 'author_id': 292, 'author_profile': 'https://Stackoverflow.com/users/292', 'pm_score': 5, 'selected': False, 'text': '<p>I have found that sometimes I get a NoClassDefFound error when code is compiled with an incompatible version of the class found at runtime.  The specific instance I recall is with the apache axis library.  There were actually 2 versions on my runtime classpath and it was picking up the out of date and incompatible version and not the correct one, causing a NoClassDefFound error.  This was in a command line app where I was using a command similar to this.  </p>\n\n<pre><code>set classpath=%classpath%;axis.jar\n</code></pre>\n\n<p>I was able to get it to pick up the proper version by using:</p>\n\n<pre><code>set classpath=axis.jar;%classpath%;\n</code></pre>\n'}, {'answer_id': 5756989, 'author': 'Jared', 'author_id': 44757, 'author_profile': 'https://Stackoverflow.com/users/44757', 'pm_score': 10, 'selected': False, 'text': "<p>While it's possible that this is due to a classpath mismatch between compile-time and run-time, it's not necessarily true.</p>\n\n<p>It is important to keep two or three different exceptions straight in our head in this case:</p>\n\n<ol>\n<li><p><strong><code>java.lang.ClassNotFoundException</code></strong>  This exception indicates that the class was not found on the classpath.  This indicates that we were trying to load the class definition, and the class did not exist on the classpath.</p></li>\n<li><p><strong><code>java.lang.NoClassDefFoundError</code></strong>  This exception indicates that the JVM looked in its internal class definition data structure for the definition of a class and did not find it.  This is different than saying that it could not be loaded from the classpath.  Usually this indicates that we previously attempted to load a class from the classpath, but it failed for some reason - now we're trying to use the class again (and thus need to load it, since it failed last time), but we're not even going to try to load it, because we failed loading it earlier (and reasonably suspect that we would fail again).  The earlier failure could be a ClassNotFoundException or an ExceptionInInitializerError (indicating a failure in the static initialization block) or any number of other problems.  The point is, a NoClassDefFoundError is not necessarily a classpath problem.</p></li>\n</ol>\n"}, {'answer_id': 28507116, 'author': 'xli', 'author_id': 1018906, 'author_profile': 'https://Stackoverflow.com/users/1018906', 'pm_score': 7, 'selected': False, 'text': '<p>Here is the code to illustrate <code>java.lang.NoClassDefFoundError</code>. Please see <a href="https://stackoverflow.com/a/5756989/1018906">Jared\'s answer</a> for detailed explanation.</p>\n\n<p><em>NoClassDefFoundErrorDemo.java</em></p>\n\n<pre><code>public class NoClassDefFoundErrorDemo {\n    public static void main(String[] args) {\n        try {\n            // The following line would throw ExceptionInInitializerError\n            SimpleCalculator calculator1 = new SimpleCalculator();\n        } catch (Throwable t) {\n            System.out.println(t);\n        }\n        // The following line would cause NoClassDefFoundError\n        SimpleCalculator calculator2 = new SimpleCalculator();\n    }\n\n}\n</code></pre>\n\n<p><em>SimpleCalculator.java</em></p>\n\n<pre><code>public class SimpleCalculator {\n    static int undefined = 1 / 0;\n}\n</code></pre>\n'}, {'answer_id': 31914707, 'author': 'Nikhil Sahu', 'author_id': 1889574, 'author_profile': 'https://Stackoverflow.com/users/1889574', 'pm_score': 3, 'selected': False, 'text': '<p>I was using <a href="http://en.wikipedia.org/wiki/Spring_Framework" rel="nofollow noreferrer">Spring Framework</a> with <a href="http://en.wikipedia.org/wiki/Apache_Maven" rel="nofollow noreferrer">Maven</a> and solved this error in my project.</p>\n\n<p>There was a runtime error in the class. I was reading a property as integer, but when it read the value from the property file, its value was double.</p>\n\n<p>Spring did not give me a full stack trace of on which line the runtime failed.\nIt simply said <code>NoClassDefFoundError</code>. But when I executed it as a native Java application (taking it out of MVC), it gave <code>ExceptionInInitializerError</code> which was the true cause and which is how I traced the error.</p>\n\n<p>@xli\'s answer gave me insight into what may be wrong in my code.</p>\n'}, {'answer_id': 32479072, 'author': 'codeDr', 'author_id': 108153, 'author_profile': 'https://Stackoverflow.com/users/108153', 'pm_score': 3, 'selected': False, 'text': '<p>I get NoClassFoundError when classes loaded by the runtime class loader cannot access classes already loaded by the java rootloader. Because the different class loaders are in different security domains (according to java) the jvm won\'t allow classes already loaded by the rootloader to be resolved in the runtime loader address space.</p>\n\n<p>Run your program with \'java -javaagent:tracer.jar [YOUR java ARGS]\'</p>\n\n<p>It produces output showing the loaded class, and the loader env that loaded the class.  It\'s very helpful tracing why a class cannot be resolved.</p>\n\n<pre><code>// ClassLoaderTracer.java\n// From: https://blogs.oracle.com/sundararajan/entry/tracing_class_loading_1_5\n\nimport java.lang.instrument.*;\nimport java.security.*;\n\n// manifest.mf\n// Premain-Class: ClassLoadTracer\n\n// jar -cvfm tracer.jar manifest.mf ClassLoaderTracer.class\n\n// java -javaagent:tracer.jar  [...]\n\npublic class ClassLoadTracer \n{\n    public static void premain(String agentArgs, Instrumentation inst) \n    {\n        final java.io.PrintStream out = System.out;\n        inst.addTransformer(new ClassFileTransformer() {\n            public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {\n\n                String pd = (null == protectionDomain) ? "null" : protectionDomain.getCodeSource().toString();\n                out.println(className + " loaded by " + loader + " at " + new java.util.Date() + " in " + pd);\n\n                // dump stack trace of the thread loading class \n                Thread.dumpStack();\n\n                // we just want the original .class bytes to be loaded!\n                // we are not instrumenting it...\n                return null;\n            }\n        });\n    }\n}\n</code></pre>\n'}, {'answer_id': 32593355, 'author': 'Ram Patra', 'author_id': 1385441, 'author_profile': 'https://Stackoverflow.com/users/1385441', 'pm_score': 3, 'selected': False, 'text': '<p>This is the <a href="https://en.wikipedia.org/wiki/Classpath_%28Java%29#Setting_the_path_to_execute_Java_programs" rel="noreferrer">best solution</a> I found so far.</p>\n\n<p>Suppose we have a package called <code>org.mypackage</code> containing the classes:</p>\n\n<ul>\n<li>HelloWorld (main class)  </li>\n<li>SupportClass </li>\n<li>UtilClass</li>\n</ul>\n\n<p>and the files defining this package are stored physically under the directory <code>D:\\myprogram</code> (on Windows) or <code>/home/user/myprogram</code> (on Linux).</p>\n\n<p>The file structure will look like this:\n<a href="https://i.stack.imgur.com/XOzAE.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XOzAE.png" alt="enter image description here"></a></p>\n\n<p>When we invoke Java, we specify the name of the application to run: <code>org.mypackage.HelloWorld</code>. However we must also tell Java where to look for the files and directories defining our package. So to launch the program, we have to use the following command:\n<a href="https://i.stack.imgur.com/cM8gu.png" rel="noreferrer"><img src="https://i.stack.imgur.com/cM8gu.png" alt="enter image description here"></a></p>\n'}, {'answer_id': 33122745, 'author': 'Eliran', 'author_id': 4417171, 'author_profile': 'https://Stackoverflow.com/users/4417171', 'pm_score': -1, 'selected': False, 'text': "<p>I got this message after removing two files from the SRC library, and when I brought them back I kept seeing this error message.</p>\n\n<p>My solution was: Restart Eclipse. Since then I haven't seen this message again :-)</p>\n"}, {'answer_id': 36870883, 'author': 'Alex ', 'author_id': 4644763, 'author_profile': 'https://Stackoverflow.com/users/4644763', 'pm_score': -1, 'selected': False, 'text': '<p>Make sure this matches in the <code>module:app</code> and <code>module:lib</code>:</p>\n\n<pre><code>android {\n    compileSdkVersion 23\n    buildToolsVersion \'22.0.1\'\n    packagingOptions {\n    }\n\n    defaultConfig {\n        minSdkVersion 17\n        targetSdkVersion 23\n        versionCode 11\n        versionName "2.1"\n    }\n</code></pre>\n'}, {'answer_id': 38383004, 'author': 'sudar', 'author_id': 5555429, 'author_profile': 'https://Stackoverflow.com/users/5555429', 'pm_score': -1, 'selected': False, 'text': '<p>I had the same problem, and I was stock for many hours.</p>\n\n<p>I found the solution. In my case, there was the static method defined due to that. The JVM can not create the another object of that class.</p>\n\n<p>For example,</p>\n\n<pre><code>private static HttpHost proxy = new HttpHost(proxyHost, Integer.valueOf(proxyPort), "http");\n</code></pre>\n'}, {'answer_id': 38614741, 'author': 'Aram Paronikyan', 'author_id': 1682984, 'author_profile': 'https://Stackoverflow.com/users/1682984', 'pm_score': 2, 'selected': False, 'text': '<p>The technique below helped me many times:</p>\n\n<pre><code>System.out.println(TheNoDefFoundClass.class.getProtectionDomain().getCodeSource().getLocation());\n</code></pre>\n\n<p>where the TheNoDefFoundClass is the class that might be "lost" due to a preference for an older version of the same library used by your program. This most frequently happens with the cases, when the client software is being deployed into a dominant container, armed with its own classloaders and tons of ancient versions of most popular libs.</p>\n'}, {'answer_id': 38879739, 'author': 'Aftab', 'author_id': 1599792, 'author_profile': 'https://Stackoverflow.com/users/1599792', 'pm_score': 6, 'selected': False, 'text': '<p><strong><em>NoClassDefFoundError In Java</em></strong></p>\n\n<p><strong>Definition:</strong> </p>\n\n<ol>\n<li><p>Java Virtual Machine is not able to find a particular class at runtime which was available at compile time.</p></li>\n<li><p>If a class was present during compile time but not available in java classpath during runtime.</p></li>\n</ol>\n\n<p><a href="https://i.stack.imgur.com/bDVNo.gif" rel="noreferrer"><img src="https://i.stack.imgur.com/bDVNo.gif" alt="enter image description here"></a></p>\n\n<p><strong>Examples:</strong></p>\n\n<ol>\n<li>The class is not in Classpath, there is no sure shot way of knowing it but many times you can just have a look to print System.getproperty("java.classpath") and it will print the classpath from there you can at least get an idea of your actual runtime classpath.</li>\n<li><p>A simple example of NoClassDefFoundError is class belongs to a missing JAR file or JAR was not added into classpath or sometimes jar\'s name has been changed by someone like in my case one of my colleagues has changed tibco.jar into tibco_v3.jar and the program is failing with java.lang.NoClassDefFoundError and I were wondering what\'s wrong.</p></li>\n<li><p>Just try to run with explicitly -classpath option with the classpath you think will work and if it\'s working then it\'s a sure short sign that someone is overriding java classpath.</p></li>\n<li>Permission issue on JAR file can also cause NoClassDefFoundError in Java.</li>\n<li>Typo on XML Configuration can also cause NoClassDefFoundError in Java.</li>\n<li>when your compiled class which is defined in a package, doesn’t present in the same package while loading like in the case of JApplet it will throw NoClassDefFoundError in Java.</li>\n</ol>\n\n<p><strong>Possible Solutions:</strong></p>\n\n<ol>\n<li>The class is not available in Java Classpath.</li>\n<li>If you are working in J2EE environment than the visibility of Class among multiple Classloader can also cause java.lang.NoClassDefFoundError, see examples and scenario section for detailed discussion.</li>\n<li>Check for java.lang.ExceptionInInitializerError in your log file. NoClassDefFoundError due to the failure of static initialization is quite common.</li>\n<li>Because NoClassDefFoundError is a subclass of java.lang.LinkageError it can also come if one of it dependency like native library may not available.</li>\n<li>Any start-up script is overriding Classpath environment variable.</li>\n<li>You might be running your program using jar command and class was not defined in manifest file\'s ClassPath attribute.</li>\n</ol>\n\n<p>Resources:</p>\n\n<p><a href="https://javarevisited.blogspot.com/2011/06/noclassdeffounderror-exception-in.html" rel="noreferrer">3 ways to solve NoClassDefFoundError</a></p>\n\n<p><a href="http://javaeesupportpatterns.blogspot.in/2011/08/javalangnoclassdeffounderror-problem.html" rel="noreferrer">java.lang.NoClassDefFoundError Problem patterns</a></p>\n'}, {'answer_id': 40467093, 'author': 'Aykut Kllic', 'author_id': 480478, 'author_profile': 'https://Stackoverflow.com/users/480478', 'pm_score': 2, 'selected': False, 'text': '<p>In case you have generated-code (EMF, etc.) there can be too many static initialisers which consume all stack space. </p>\n\n<p>See Stack&nbsp;Overflow question <em><a href="https://stackoverflow.com/questions/3700459/how-to-increase-the-java-stack-size">How to increase the Java stack size?</a></em>.</p>\n'}, {'answer_id': 44632379, 'author': 'ST7', 'author_id': 1855286, 'author_profile': 'https://Stackoverflow.com/users/1855286', 'pm_score': 0, 'selected': False, 'text': '<p>If someone comes here because of <code>java.lang.NoClassDefFoundError: org/apache/log4j/Logger</code> error, in my case it was produced because I used log4j 2 (but I didn\'t add all the files that come with it), and some dependency library used log4j 1. The solution was to add the Log4j 1.x bridge: the jar <code>log4j-1.2-api-&lt;version&gt;.jar</code> which comes with log4j 2. More info in the log4j 2 <a href="https://logging.apache.org/log4j/2.x/manual/migration.html" rel="nofollow noreferrer">migration</a>.</p>\n'}, {'answer_id': 46925897, 'author': 'manuelvigarcia', 'author_id': 5108777, 'author_profile': 'https://Stackoverflow.com/users/5108777', 'pm_score': 1, 'selected': False, 'text': "<h2>Two different checkout copies of the same project</h2>\n\n<p>In my case, the problem was Eclipse's inability to differentiate between two different copies of the same project. I have one locked on trunk (SVN version control) and the other one working in one branch at a time. I tried out one change in the working copy as a JUnit test case, which included extracting a private inner class to be a public class on its own and while it was working, I open the other copy of the project to look around at some other part of the code that needed changes. At some point, the <code>NoClassDefFoundError</code> popped up complaining that the private inner class was not there; double-clicking in the stack trace brought me to the source file in the wrong project copy.</p>\n\n<p>Closing the trunk copy of the project and running the test case again got rid of the problem.</p>\n"}, {'answer_id': 47553351, 'author': 'Pekmezli Dürüm', 'author_id': 5788964, 'author_profile': 'https://Stackoverflow.com/users/5788964', 'pm_score': -1, 'selected': False, 'text': '<p>Java was unable to find the class A in runtime. \nClass A was in maven project ArtClient from a different workspace.\nSo I imported ArtClient to my Eclipse project. \nTwo of my projects was using ArtClient as dependency.\nI changed library reference to project reference for these ones (Build Path -> Configure Build Path).</p>\n\n<p>And the problem gone away. </p>\n'}, {'answer_id': 48615116, 'author': 'Michael', 'author_id': 2739201, 'author_profile': 'https://Stackoverflow.com/users/2739201', 'pm_score': 1, 'selected': False, 'text': '<p>I fixed my problem by disabling the preDexLibraries for all modules:</p>\n\n<pre><code>dexOptions {\n        preDexLibraries false\n        ...\n</code></pre>\n'}, {'answer_id': 49601683, 'author': 'Brent Bradburn', 'author_id': 86967, 'author_profile': 'https://Stackoverflow.com/users/86967', 'pm_score': 0, 'selected': False, 'text': '<p>This error can be caused by unchecked <strong>Java version</strong> requirements.</p>\n\n<p>In my case I was able to resolve this error, while building a high-profile open-source project, by switching from Java 9 to Java 8 using <a href="http://sdkman.io/" rel="nofollow noreferrer">SDKMAN!</a>.</p>\n\n<pre><code>sdk list java\nsdk install java 8u152-zulu\nsdk use java 8u152-zulu\n</code></pre>\n\n<p>Then doing a clean install as described below.</p>\n\n<hr>\n\n<p>When using <strong>Maven</strong> as your build tool, it is sometimes helpful -- and usually gratifying, to do a <em>clean</em> \'install\' build <strong>with testing disabled</strong>.</p>\n\n<pre><code>mvn clean install -DskipTests\n</code></pre>\n\n<p>Now that <em>everything</em> has been built and installed, you can go ahead and run the tests.</p>\n\n<pre><code>mvn test\n</code></pre>\n'}, {'answer_id': 52544691, 'author': 'ᴠɪɴᴄᴇɴᴛ', 'author_id': 1548776, 'author_profile': 'https://Stackoverflow.com/users/1548776', 'pm_score': 1, 'selected': False, 'text': '<p><code>NoClassDefFoundError</code> can also occur when a <strong>static</strong> initializer tries to load a resource bundle that is not available in runtime, for example a properties file that the affected class tries to load from the <code>META-INF</code> directory, but isn’t there. If you don’t catch <code>NoClassDefFoundError</code>, sometimes you won’t be able to see the full stack trace; to overcome this you can temporarily use a <code>catch</code> clause for <code>Throwable</code>:</p>\n<pre><code>try {\n    // Statement(s) that cause(s) the affected class to be loaded\n} catch (Throwable t) {\n    Logger.getLogger(&quot;&lt;logger-name&gt;&quot;).info(&quot;Loading my class went wrong&quot;, t);\n}\n</code></pre>\n'}, {'answer_id': 53616950, 'author': 'Bartek Lipinski', 'author_id': 1993204, 'author_profile': 'https://Stackoverflow.com/users/1993204', 'pm_score': 3, 'selected': False, 'text': '<p>One interesting case in which you might see a lot of <code>NoClassDefFoundErrors</code> is when you:</p>\n\n<ol>\n<li><code>throw</code> a <code>RuntimeException</code> in the <code>static</code> block of your class <code>Example</code></li>\n<li>Intercept it (or if it just doesn\'t matter like it is thrown in a <strong>test case</strong>)</li>\n<li>Try to create an instance of this class <code>Example</code></li>\n</ol>\n\n<p></p>\n\n<pre><code>static class Example {\n    static {\n        thisThrowsRuntimeException();\n    }\n}\n\nstatic class OuterClazz {\n\n    OuterClazz() {\n        try {\n            new Example();\n        } catch (Throwable ignored) { //simulating catching RuntimeException from static block\n            // DO NOT DO THIS IN PRODUCTION CODE, THIS IS JUST AN EXAMPLE in StackOverflow\n        }\n\n        new Example(); //this throws NoClassDefFoundError\n    }\n}\n</code></pre>\n\n<p><code>NoClassDefError</code> will be thrown accompanied with <code>ExceptionInInitializerError</code> from the static block <code>RuntimeException</code>.</p>\n\n<hr>\n\n<p>This is especially important case when you see <code>NoClassDefFoundErrors</code> in your <strong>UNIT TESTS</strong>.</p>\n\n<p>In a way you\'re "sharing" the <code>static</code> block execution between tests, but the initial <code>ExceptionInInitializerError</code> will be just in one test case. The first one that uses the problematic <code>Example</code> class. Other test cases that use the <code>Example</code> class will just throw <code>NoClassDefFoundErrors</code>.</p>\n'}, {'answer_id': 55504952, 'author': 'Steve Stilson', 'author_id': 3435342, 'author_profile': 'https://Stackoverflow.com/users/3435342', 'pm_score': 0, 'selected': False, 'text': '<p>I got NoClassDefFound errors when I didn\'t export a class on the "Order and Export" tab in the Java Build Path of my project.  Make sure to put a checkmark in the "Order and Export" tab of any dependencies you add to the project\'s build path.  See <a href="https://stackoverflow.com/questions/8884818/eclipse-warning-xxxxxxxxxxx-jar-will-not-be-exported-or-published-runtime-clas">Eclipse warning: XXXXXXXXXXX.jar will not be exported or published. Runtime ClassNotFoundExceptions may result</a>.</p>\n'}, {'answer_id': 57379534, 'author': 'off99555', 'author_id': 2593810, 'author_profile': 'https://Stackoverflow.com/users/2593810', 'pm_score': 0, 'selected': False, 'text': '<p>It could also be because you copy the code file from an IDE with a certain package name and you want to try to run it using terminal. You will have to remove the package name from the code first.\nThis happens to me.</p>\n'}, {'answer_id': 58654225, 'author': 'Alan Ackart', 'author_id': 6060637, 'author_profile': 'https://Stackoverflow.com/users/6060637', 'pm_score': 1, 'selected': False, 'text': "<p>I got this error when I add  Maven dependency of another module to my project, the issue was finally solved by add <code>-Xss2m</code> to my program's JVM option(It's one megabyte by default since JDK5.0). It's believed the program does not have enough stack to load class.</p>\n"}, {'answer_id': 60383482, 'author': 'Ben Waters', 'author_id': 726741, 'author_profile': 'https://Stackoverflow.com/users/726741', 'pm_score': 1, 'selected': False, 'text': "<p>In my case I was getting this error due to a mismatch in the JDK versions. When I tried to run the application from Intelij it wasn't working but then running it from the command line worked. This is because Intelij was attempting to run it with the Java 11 JDK that was setup but on the command line it was running with the Java 8 JDK. After switching that setting under File > Project Structure > Project Settings > Project SDK, it worked for me.</p>\n"}, {'answer_id': 60467618, 'author': 'bdskfsdk321dsad3', 'author_id': 12059281, 'author_profile': 'https://Stackoverflow.com/users/12059281', 'pm_score': 0, 'selected': False, 'text': '<p>Everyone talks here about some Java configuration stuff, JVM problems etc., in my case the error was not related to these topics at all and had a very trivial and easy to solve reason: I had a wrong annotation at my endpoint in my Controller (Spring Boot application). </p>\n'}, {'answer_id': 61825298, 'author': 'pixel', 'author_id': 3453898, 'author_profile': 'https://Stackoverflow.com/users/3453898', 'pm_score': 0, 'selected': False, 'text': '<p>I have had an interesting issue wiht NoClassDefFoundError in JavaEE working with Liberty server.  I was using IMS resource adapters and my server.xml had already resource adapter for imsudbJXA.rar.\nWhen I added new adapter for imsudbXA.rar, I would start getting this error for instance objects for DLIException, IMSConnectionSpec or SQLInteractionSpec.\nI could not figure why but I resolved it by creating new server.xml for my work using only imsudbXA.rar.  I am sure using multiple resource adapters in server.xml is fine, I just had no time to look into that.</p>\n'}, {'answer_id': 63427546, 'author': 'logbasex', 'author_id': 10393067, 'author_profile': 'https://Stackoverflow.com/users/10393067', 'pm_score': 1, 'selected': False, 'text': "<p>Update [https://www.infoq.com/articles/single-file-execution-java11/]:</p>\n<blockquote>\n<p>In Java SE 11, you get the option to launch a single source code file\ndirectly, without intermediate compilation. Just for your convenience,\nso that newbies like you don't have to run javac + java (of course,\nleaving them confused why that is).</p>\n</blockquote>\n"}, {'answer_id': 64129484, 'author': 'Thomas McSwain', 'author_id': 6741141, 'author_profile': 'https://Stackoverflow.com/users/6741141', 'pm_score': 0, 'selected': False, 'text': "<p>I had this error but could not figure out the solution based on this thread but solved it myself.</p>\n<p>For my problem I was compiling this code:</p>\n<pre><code>package valentines;\n\nimport java.math.BigInteger;\nimport java.util.ArrayList;\n\npublic class StudentSolver {\n    public static ArrayList&lt;Boolean&gt; solve(ArrayList&lt;ArrayList&lt;BigInteger&gt;&gt; problems) {\n        //DOING WORK HERE\n        \n    }\n    public static void main(String[] args){\n        //TESTING SOLVE FUNCTION\n    }\n    \n}\n</code></pre>\n<p>I was then compiling this code in a folder structure that was like /ProjectName/valentines\nCompiling it worked fine but trying to execute: <code>java StudentSolver</code></p>\n<p>I was getting the NoClassDefError.</p>\n<p>To fix this I simply removed: <code>package valentines;</code></p>\n<p>I'm not very well versed in java packages and such but this how I fixed my error so sorry if this was already answered by someone else but I couldn't interpret it to my problem.</p>\n"}, {'answer_id': 66691405, 'author': 'priyanka_rao', 'author_id': 3568094, 'author_profile': 'https://Stackoverflow.com/users/3568094', 'pm_score': 1, 'selected': False, 'text': '<p>I was getting <strong>NoClassDefFoundError</strong> while trying to deploy application on Tomcat/JBOSS servers. I played with different dependencies to resolve the issue, but kept getting the same error. Marked all javax.* dependencies as provided in pom.xml, And war literally had no Dependency in it. Still the issue kept popping up.</p>\n<p>Finally realized that <em>src/main/webapps/WEB-INF/<strong>classes</strong></em> had <strong>classes</strong> folder which was getting copied into my war, so instead of compiled classes, this classes were getting copied, hence no dependency change was resolving the issue.</p>\n<p>Hence be careful if any <strong>previously compiled data</strong> is getting copied, After deleting classes folder and fresh compilation, It worked!..</p>\n'}, {'answer_id': 66816030, 'author': 'yoAlex5', 'author_id': 4770877, 'author_profile': 'https://Stackoverflow.com/users/4770877', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Java ClassNotFoundException vs NoClassDefFoundError</strong></p>\n<p><a href="https://stackoverflow.com/a/66815988/4770877">[ClassLoader]</a></p>\n<p>Static vs Dynamic class loading</p>\n<p><code>Static(Implicit) class loading</code> - result of reference, instantiation, or inheritance.</p>\n<pre><code>MyClass myClass = new MyClass();\n</code></pre>\n<p><code>Dynamic(Explicit) class loading</code> is result of Class.forName(), loadClass(), findSystemClass()</p>\n<pre><code>MyClass myClass = (MyClass) Class.forName(&quot;MyClass&quot;).newInstance();\n</code></pre>\n<p>Every class has a <code>ClassLoader</code> which uses <code>loadClass(String name);</code> that is why</p>\n<pre class="lang-none prettyprint-override"><code>explicit class loader uses implicit class loader\n</code></pre>\n<p><code>NoClassDefFoundError</code> is a part of <code>explicit class loader</code>. It is <code>Error</code> to guarantee that during compilation this class was presented but now (in run time) it is absent.</p>\n<p><code>ClassNotFoundException</code> is a part of <code>implicit class loader</code>. It is <code>Exception</code> to be elastic with scenarios where additionally it can be used - for example reflection.</p>\n'}, {'answer_id': 74520294, 'author': 'douglas', 'author_id': 5930157, 'author_profile': 'https://Stackoverflow.com/users/5930157', 'pm_score': 0, 'selected': False, 'text': '<p>My solution to this was to &quot;avail&quot; the classpath contents for the specific classes that were missing. In my case, I had 2 dependencies, and though I was able to compile successfully using javac ..., I was not able to run the resulting class file using java ..., because a Dynamic class in the BouncyCastle jar could not be loaded at runtime.</p>\n<pre><code>javac --classpath &quot;ext/commons-io-2.11.0;ext/bc-fips-1.0.2.3&quot; hello.java\n</code></pre>\n<p>So at compile time and by runtime, the JVM is aware of where to fetch Apache Commons and BouncyCastle dependencies, however, when running this, I got</p>\n<pre><code>Error: Unable to initialize main class hello\nCaused by: java.lang.NoClassDefFoundError: \norg/bouncycastle/jcajce/provider/BouncyCastleFipsProvider\n</code></pre>\n<p>And I therefore manually created a new folder named ext at the same location, as per the classpath, where I then placed the BouncyCastle jar to ensure it would be found at runtime. You can place the jar relative to the class file or the jar file as long as the resulting manifest has the location of the jar specified. Note I only need to avail the one jar containing the missing class file.</p>\n'}]
['https://Stackoverflow.com/questions/34413', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3535/']