ClassNotFound exception in Maven project after uploading a jar on Nexus
I working on a Maven project using Nexus as repository manager. In short there are 3 parts: "Business" (packaged in .jar), "Web" (packaged in .war) and "ear" (package the whole thing in .ear)
I was working perfectly fine, but lately I've been trying to add a "custom" jar (for md5 password conversion) to the repository and it didn't work so well, I did the following:
- Got java files from a website (www.twmacinta.com) to convert a String with md5.
- Used it as java files in my project, and it 开发者_StackOverflow中文版worked perfectly fine, then I decided to make a jar out of it.
- Compiled the sources with javac.
- Used "jar" command on to create the archive ("com/twmacinta/util/MD5-2.7.1.jar").
- Connect to Nexus and upload the jar.
Went to my pom.xml file in the Businness part, add the dependency through the tab "Dependency" and "Add..." (it found the jar, no problem) which add this to my pom.xml file:
<dependency> <groupId>com.twmacinta.util</groupId> <artifactId>MD5</artifactId> <version>2.7.1</version> </dependency>
Added the import in my business class (it automatically found the import, no problem) like this:
import com.twmacinta.util.MD5;
There's no error at this point, so I go for the clean / install / redeploy, everything is fine.
But when I try to log in my application, I got the following exception:
java.lang.ClassNotFoundException: com.twmacinta.util.MD5
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
[...]
The MD5-2.7.1.jar shows up in the MavenDependencies of Business and ear, it looks like any other library I'm already using (for all I can tell), so I don't get it ...
Please help me =)
Nicolas
Your jar file should be located in com/twmacinta/util/MD5/2.7.1/MD5-2.7.1.jar
Just compare to other artifacts, that's how jars are organized with Maven 2+.
May be application isn't getting properly getting published ..
It sounds like the library isn't being bundled in the ear or the war.
Where do you bundle your dependencies?
- ...war/web-inf/lib
- or ...ear/lib
Check inside both of the archives, to check where the other external libraries are being bundled, then check whether they are declared as dependencies in the parent, or the war or the ear modules.
EDIT:
OK, so check the contents of the jar files that you've created.
Run the following command against the MD5-2.7.1.jar
jar -tvf MD5-2.7.1.jar
this should list the contents of the file, ensure that com/twmacinta/util/MD5.class is listed at the root of the jar, and that any additional sub-directories have not been included in the jar resulting in a class entry such as build/com/twmacinta/util/MD5.class.
Also, after having now looked at the source, I notice that the library caters for native JNI or java implementations, there are ways of disabling the native interface using various system properties, or else you will need to ensure that the appropriate native libs are available in the expected location.
精彩评论