Glassfish 中外部库的放置位置
我使用 Netbeans 7 创建了一个 JSF2 项目,并成功将其部署在 Glassfish 3.1 上。 不过,ear 文件已经变得相当大(6.5mb),其中大部分由外部 jar 文件(如 apache commons、solrj、primefaces 和 pdfrenderer 等)组成,这些文件被复制到各自的 war/ejb 文件中。
我的问题是:如何避免这种情况并使我的ear文件更小 - 它应该只包含我创建的内容,外部库应该只在服务器上部署一次。
我在网上搜索了这方面的答案,我发现的唯一一件事是将外部 jar 文件放在 glassfish 安装目录中的“domains/domain1/lib”或“domains/domain1/lib/ext”下,并取消选中“Package”标志在 Netbeans 项目库设置中,但到目前为止这些都不起作用(我总是得到 ClassNotFoundExceptions)。
我是否必须做其他事情,在某处调整类路径设置或者如何实现这一目标?有人有解决办法吗?
更新: 好吧,我发现这只发生在我本地安装的 Netbeans 附带的 Glassfish(它是一台运行 64 位 Windows 7 的笔记本电脑)上。在我的远程 Linux 机器上,它按预期工作,即我能够将所有外部库放入“domains/domain1/lib”中 - 我的 Ear 文件现在只有 ~700k :) 我将在我的 Mac 和另一个 Windows 7 机器上尝试此操作,看看这是与操作系统相关的问题还是其他问题。
I have created a JSF2 project with Netbeans 7 and successfully deployed it on Glassfish 3.1.
The ear file has grown quite big (6.5mb) though, most of it consists of external jar files (like apache commons, solrj, primefaces and pdfrenderer etc.) which are copied into the respective war/ejb files.
My question is: how can I avoid that and make my ear file smaller - it should only contain the stuff that I created, the external libs should only be deployed once on the server.
I searched the web for answers on this and the only thing I found was putting the external jar files under 'domains/domain1/lib' or 'domains/domain1/lib/ext' in the glassfish installation directory and unchecking the 'Package' flag in the Netbeans project library settings, but none of this worked so far (I always get ClassNotFoundExceptions).
Do I have to do something else, adapt a classpath setting somewhere or how can I achieve this? Does anyone have a solution?
Update: Ok I found out that this is only happening on my local Glassfish install that comes with Netbeans (its a laptop with 64bit Windows 7 running on it). On my remote Linux box it works as expected, i.e. I was able to put all external libs into 'domains/domain1/lib' - my ear file is only ~700k now :)
I will try this on my Mac and on another Windows 7 box too, to see if this is a OS related issue or something else.
我想我现在可以自己回答这个问题:domain1/lib 似乎是放置所有这些 jar 文件的正确位置。至少它在我尝试过的 2 个 Linux 盒子和我的 Mac 上运行得很好。我还发现了为什么它在我的 Windows 7 笔记本电脑上运行不一样。
如果您使用 Netbeans 附带的 Glassfish 安装,则域路径是用户特定的,这意味着您必须将 jar 文件放在
按预期工作,jars 在
另一方面,
I think I can answer the question myself now: domain1/lib seems to be the right place to put all those jar files. At least it works perfectly on the 2 Linux boxes I tried and on my Mac. I also found out why it didnt work the same on my Windows 7 laptop.
The domain path is user specific if you use the Glassfish install that comes with Netbeans, that means you have to put the jar files under
to work as expectd, jars under
on the other hand seem to be ignored by the classloader.