简体   繁体   中英

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). 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

When JARs are added to the boot classpath, they have a different context than JARs that are on the application classpath. 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. The key is that any classes on the boot classpath are unaware of and can not reference anything from the application classpath.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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