Eclipse以系统库的形式将用户库(包含Hibernate jars)创建为项目 [英] Eclipse created User Library (with Hibernate jars) to the project as System library

查看:199
本文介绍了Eclipse以系统库的形式将用户库(包含Hibernate jars)创建为项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个HelloWorld hibernate应用程序(hibernate.cfg.xml +一个POJO类+一个主类来坚持DB中的pojo类对象)。对于这一个 - 我创建了具有必需Hibernate jar的用户库并将其添加到项目中,但由于某种原因,在创建我的自定义用户Hibernate库时我检查了System Library(添加到引导类路径)复选框。



我尝试运行应用程序并得到

 线程mainjava中的异常.lang.ExceptionInInitializerError 
在org.hibernate.cfg.Configuration.reset(Configuration.java:309)
在org.hibernate.cfg.Configuration。< init>(Configuration.java:275)
at org.hibernate.cfg.Configuration。< init>(Configuration.java:279)
at com.woworks.secondhibernate.main.HibernateTest.main(HibernateTest.java:22)
由于:java.lang.NullPointerException
在org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
在org.hibernate.cfg.Environment。< clinit>(Environment .java:220)
... 4 more

如果我取消勾选这个Syst em库(添加到引导类路径) - 一切工作正常。有人可以解释为什么会发生这种情况,它的目的是什么系统库(添加到引导类路径)

谢谢!


解决方案

引导类路径用于运行并提供java。例如,javac(编译器)在引导类路径中使用java类来编译您的代码。当javac解析需要编译类的引用(例如:代码中引用的hibernate对象)时,它将使用编译类路径。

这同样适用于运行java应用程序。引导类路径(或系统类路径)类对运行时可见,但对用户应用程序不可见。



有关更多详细信息,请参阅此文档 http://docs.oracle.com/javase/7/docs/technotes/tools/findingclasses.html


I created a HelloWorld hibernate app (hibernate.cfg.xml + one POJO class + one main class to persist pojo class object in DB). For this one - I created user library with required Hibernate jars and added it to the project, BUT for some reason while creating my custom user Hibernate library I checked "System Library (added to the boot class path)" checkbox.

I tried to run the app and got

    Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.hibernate.cfg.Configuration.reset(Configuration.java:309)
    at org.hibernate.cfg.Configuration.<init>(Configuration.java:275)
    at org.hibernate.cfg.Configuration.<init>(Configuration.java:279)
    at com.woworks.secondhibernate.main.HibernateTest.main(HibernateTest.java:22)
Caused by: java.lang.NullPointerException
    at org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
    at org.hibernate.cfg.Environment.<clinit>(Environment.java:220)
    ... 4 more

If I uncheck this "System Library (added to the boot class path)" - everything works fine. Can someone please explain why this happens and what it the purpose of "System Library (added to the boot class path)"

Thanks!

解决方案

The boot class path is used to run and feed java. For example the javac (the compiler) is using java classes in the boot class path to compile your code. When javac resolves references required to compile your classes (for example: hibernate objects referenced in your code), it will use the compilation class path.

The same applies to running a java application. Boot class path (or system class path) classes are visible to the runtime but not to the user application.

See this documentation for more details http://docs.oracle.com/javase/7/docs/technotes/tools/findingclasses.html

这篇关于Eclipse以系统库的形式将用户库(包含Hibernate jars)创建为项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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