简体   繁体   English

Eclipse将项目库(带有Hibernate jars)创建为项目库系统库

[英]Eclipse created User Library (with Hibernate jars) to the project as System library

I created a HelloWorld hibernate app (hibernate.cfg.xml + one POJO class + one main class to persist pojo class object in DB). 我创建了一个HelloWorld hibernate应用程序(hibernate.cfg.xml +一个POJO类+一个主类来保存数据库中的pojo类对象)。 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. 对于这个 - 我创建了具有所需Hibernate jar的用户库并将其添加到项目中,但由于某种原因,在创建我的自定义用户Hibernate库时,我选中了“System Library(添加到引导类路径)”复选框。

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. 引导类路径用于运行和提供java。 For example the javac (the compiler) is using java classes in the boot class path to compile your code. 例如,javac(编译器)在引导类路径中使用java类来编译代码。 When javac resolves references required to compile your classes (for example: hibernate objects referenced in your code), it will use the compilation class path. 当javac解析编译类所需的引用时(例如:代码中引用的hibernate对象),它将使用编译类路径。

The same applies to running a java application. 这同样适用于运行java应用程序。 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 有关更多详细信息,请参阅此文档http://docs.oracle.com/javase/7/docs/technotes/tools/findingclasses.html

When JARs are added to the boot classpath, they have a different context than JARs that are on the application classpath. 将JAR添加到引导类路径时,它们具有与应用程序类路径上的JAR不同的上下文。 I suspect that putting Hibernate on the boot classpath causes it trouble because it's trying to load some config resource from it's classpath but that resource is only available on the app classpath. 我怀疑将Hibernate放在引导类路径上会导致它出现问题,因为它试图从它的类路径加载一些配置资源,但该资源仅在app类路径上可用。 The key is that any classes on the boot classpath are unaware of and can not reference anything from the application classpath. 关键是引导类路径上的任何类都不知道,也不能从应用程序类路径引用任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM