AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
![]() ![]() I ended up having to add C 2.0 to my pom.xml so that it can be chosen over C 1.0. C 2.0 is indeed installed and your IDE knows about it, but it's just ignored when running the application. Now the weird thing is: if you navigate the code of B in your IDE and try to jump to the class that only exists in C 2.0, it works correctly. As a result, when B tries to use the class that only exists in C 2.0, a ClassNotFoundException is thrown.However, A is "closer" in the dependency tree, so Maven uses C 1.0 for both A and B and doesn't even warn you about this (it's quite astounding to me).B makes use of a class that only exists in C 2.0.Let's say A depends on C 1.0 and B depends on C 2.0 Both A and B depends on another library C, but different versions of C. ![]() I had the same error and it took me a whole day to realize it's a dependency conflict issue: In an IDE such as Eclipse, you'll have a menu option to specify your classpath. You define a classpath on the command line by saying java -cp and then your classpath. The solution, as so often in the Java world, is to check your classpath. When you get a ClassNotFoundException, it means the JVM has traversed the entire classpath and not found the class you've attempted to reference. The JVM will attempt to look in the directory classes first, then in stuff.jar and finally in otherstuff.jar. For example, in the classpath :Ĭ:/myproject/classes C:/myproject/lib/stuff.jar C:/myproject/lib/otherstuff.jar So the JVM traverses a classpath from start to finish looking for the definition of the class when it attempts to load the class definition. If you unzip a jar file, you'll get a bunch of directories and class files following the pattern above. A jar file is in reality just a zipped collection of directories like the above. In the second instance, for jar files, it will search the jar file for that class. If I have the directory C:/myproject/classes in my classpath, and I attempt to load a class, it will look under the classes directory for a directory called com, then under that a directory called mycompany, and finally it will look for a file called Foo.class in that directory. These 'locations' can either be directories, or jar files.įor directories, the JVM will follow an expected pattern for loading a class. A classpath is a list of locations to load classes from.
0 Comments
Read More
Leave a Reply. |