从ear / war in ear / lib / jar获取类会返回ClassNotFoundException [英] Getting class from ear/war in ear/lib/jar returns ClassNotFoundException

查看:127
本文介绍了从ear / war in ear / lib / jar获取类会返回ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目结构如下。服务器是Glassfish 4. IDE - netbeans 7.4。项目临时用于项目a。

My project structure is the following. Server is Glassfish 4. IDE - netbeans 7.4. Project temp is used by project a.

EAR
 + lib/temp.jar
 + a.war

Temp.jar 包含核心类。他们被战争使用。 Temp.jar 不会从战争中导入任何文件,它必须知道战争什么都没有。但是, temp.jar 具有通过反射创建war类实例的类(根据xml文件)。在这里,我得到 ClassNotFoundException 。怎么修好?有可能修复或我有错误的项目结构?

Temp.jar contains core classes. They are used by war. Temp.jar doesn't import any files from war, and it must know about war nothing. But, temp.jar has classes that creates instances of war classes by reflection (according to xml file). Here I get ClassNotFoundException. How can it be fixed? Is it possible to fix or I have wrong project structure?

注意:我没有把temp.jar放在a.war中,因为可以使用不同的war文件来使用这个jar。

Note: I didn't put temp.jar in a.war as there can be different war files that can use this jar.

推荐答案

我找到了答案。

如果我们把jar放到ear / lib文件夹中,那么可以访问它中的类但是它们无法访问lib中的类(在这种情况下没有需要添加一些东西到战争的清单文件)。

If we put jar into ear/lib folder then the classes in it can be accessed but they can't access the classes out of lib (in this case there is no need to add something to manifest file of war).

如果我们把jar放在耳根或任何其他文件夹ear / bum中,那么这些jar的类可以访问war类。

If we put jar in root of ear or in any other folder ear/bum than the classes of these jar can access war classes.

所以我得出结论,/ lib是单向的,任何其他都是双向的。

So I conclude, that /lib is monodirectional, any other are bidirectional.

希望它能为人节省很多时间。

Hope it will save someone a lot of time.

这篇关于从ear / war in ear / lib / jar获取类会返回ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆