我正在使用 Nexus 作为存储库管理器来开发 Maven 项目。简而言之,有 3 个部分:“Business”(打包在 .jar 中)、“Web”(打包在 .war 中)和“ear”(将整个内容打包在 .ear 中)
我工作得很好,但最近我一直在尝试将“自定义”jar(用于 md5 密码转换)添加到存储库,但效果不太好,我执行了以下操作:
- 从网站获取 java 文件(www.twmacinta.com) 用 md5 转换字符串。
- 在我的项目中将它用作java文件,并且它工作得很好,然后我决定用它制作一个jar。
- 使用 javac 编译源代码。
- 使用“jar”命令创建存档(“com/twmacinta/util/MD5-2.7.1.jar”)。
- 连接到 Nexus 并上传 jar。
-
转到 Business 部分中的 pom.xml 文件,通过选项卡“Dependency”和“Add...”添加依赖项(它找到了 jar,没问题),将其添加到我的 pom.xml 文件中:
<依赖>;
com.twmacinta.util
MD5
<版本>2.7.1
-
在我的业务类中添加了导入(它自动找到导入,没问题),如下所示:
import com.twmacinta.util.MD5;
此时没有错误,所以我进行了清理/安装/重新部署,一切都很好。
但是当我尝试登录我的应用程序时,出现以下异常:
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)
[...]
MD5-2.7.1.jar 显示在 Business 和 Ear 的 MavenDependency 中,它看起来像我已经在使用的任何其他库(尽我所能)告诉),所以我不明白......
请帮助我=)
尼古拉斯
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 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
发布评论
评论(3)
您的 jar 文件应位于 com/twmacinta/util/MD5/2.7.1/MD5-2.7.1.jar 中。
与其他工件进行比较,这就是 Maven 2+ 组织 jar 的方式。
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 ..
听起来图书馆并没有被捆绑在耳朵或战争中。
您将依赖项捆绑在哪里?
检查两个档案的内部,检查其他外部库的捆绑位置,然后检查它们是否在父级或 war 中声明为依赖项或耳模块。
编辑:
好的,请检查您创建的 jar 文件的内容。
针对 MD5-2.7.1.jar 运行以下命令
jar -tvf MD5-2.7.1.jar
这应该列出文件的内容,确保 com/twmacinta/util/MD5.class 列在 jar 的根目录中,并且 jar 中未包含任何其他子目录生成一个类条目,例如 build/com/twmacinta/util/MD5.class。
另外,在查看源代码后,我注意到该库适合本机 JNI 或 java 实现,有多种方法可以使用各种系统属性禁用本机接口,否则您将需要确保适当的本机库可用在预期的位置。
It sounds like the library isn't being bundled in the ear or the war.
Where do you bundle your dependencies?
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.