H2 java 应用未启动但正在调试

H2 java app not starting but working in debug

我的 Java 8 + ControlsFX 2 应用程序有这个问题。 我正在使用 H2 数据库无服务器,并且在 run/debug 中的 Eclipse 中一切正常,但是当我创建可运行的 jar 并启动它时,我收到此消息

2015-07-02 15:29:23,535|JavaFX Application Thread|ERROR|GestioneProdottiView.<init>() Errore creazione tabella
    org.eclipse.persistence.exceptions.PersistenceUnitLoadingException: 
    Exception Description: An exception was thrown while trying to load persistence unit at url: rsrc:../
    Internal Exception: Exception [EclipseLink-30004] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
    Exception Description: An exception was thrown while processing persistence.xml from URL: rsrc:../
    Internal Exception: java.net.MalformedURLException
        at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionLoadingFromUrl(PersistenceUnitLoadingException.java:100) ~[jar:rsrc:org.eclipse.persistence.core-2.6.0.jar!/:?]
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:616) ~[jar:rsrc:org.eclipse.persistence.jpa-2.6.0.jar!/:?]
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.getPersistenceUnits(PersistenceUnitProcessor.java:500) ~[jar:rsrc:org.eclipse.persistence.jpa-2.6.0.jar!/:?]
        at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchive(JPAInitializer.java:178) ~[jar:rsrc:org.eclipse.persistence.jpa-2.6.0.jar!/:?]
        at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfoInArchives(JPAInitializer.java:160) ~[jar:rsrc:org.eclipse.persistence.jpa-2.6.0.jar!/:?]
        at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.findPersistenceUnitInfo(JPAInitializer.java:141) ~[jar:rsrc:org.eclipse.persistence.jpa-2.6.0.jar!/:?]
        at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:183) ~[jar:rsrc:org.eclipse.persistence.jpa-2.6.0.jar!/:?]
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63) ~[jar:rsrc:hibernate-jpa-2.0-api-1.0.1.Final.jar!/:?]
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47) ~[jar:rsrc:hibernate-jpa-2.0-api-1.0.1.Final.jar!/:?]
        at com.cremonaufficio.appbarsangiorgio.backend.database.DaoBase.<init>(DaoBase.java:34) ~[rsrc:./:?]
        at com.cremonaufficio.appbarsangiorgio.frontend.prodotti.GestioneProdottiView.<init>(GestioneProdottiView.java:93) [rsrc:./:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_45]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) [?:1.8.0_45]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) [?:1.8.0_45]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) [?:1.8.0_45]
        at java.lang.Class.newInstance(Unknown Source) [?:1.8.0_45]
        at sun.reflect.misc.ReflectUtil.newInstance(Unknown Source) [?:1.8.0_45]
        at javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(Unknown Source) [rsrc:./:?]
        at javafx.fxml.FXMLLoader$ValueElement.processStartElement(Unknown Source) [rsrc:./:?]
        at javafx.fxml.FXMLLoader.processStartElement(Unknown Source) [rsrc:./:?]
        at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) [rsrc:./:?]
        at javafx.fxml.FXMLLoader.loadImpl(Unknown Source) [rsrc:./:?]
        at javafx.fxml.FXMLLoader.load(Unknown Source) [rsrc:./:?]
        at com.cremonaufficio.appbarsangiorgio.frontend.main.MainView.<init>(MainView.java:18) [rsrc:./:?]
        at com.cremonaufficio.appbarsangiorgio.ApplicationRoot.start(ApplicationRoot.java:60) [rsrc:./:?]
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication19(Unknown Source) [rsrc:./:?]
        at com.sun.javafx.application.LauncherImpl$$Lambda/1019606772.run(Unknown Source) [rsrc:./:?]
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait2(Unknown Source) [rsrc:./:?]
        at com.sun.javafx.application.PlatformImpl$$Lambda/672080502.run(Unknown Source) [rsrc:./:?]
        at com.sun.javafx.application.PlatformImpl.lambda$null0(Unknown Source) [rsrc:./:?]
        at com.sun.javafx.application.PlatformImpl$$Lambda/1955345122.run(Unknown Source) [rsrc:./:?]
        at java.security.AccessController.doPrivileged(Native Method) ~[?:1.8.0_45]
        at com.sun.javafx.application.PlatformImpl.lambda$runLater1(Unknown Source) [rsrc:./:?]
        at com.sun.javafx.application.PlatformImpl$$Lambda/1936897764.run(Unknown Source) [rsrc:./:?]
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source) [rsrc:./:?]
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) ~[rsrc:./:?]
        at com.sun.glass.ui.win.WinApplication.lambda$null5(Unknown Source) [rsrc:./:?]
        at com.sun.glass.ui.win.WinApplication$$Lambda/479808962.run(Unknown Source) [rsrc:./:?]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: org.eclipse.persistence.exceptions.PersistenceUnitLoadingException: 
    Exception Description: An exception was thrown while processing persistence.xml from URL: rsrc:../
    Internal Exception: java.net.MalformedURLException
        at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionProcessingPersistenceXML(PersistenceUnitLoadingException.java:118) ~[jar:rsrc:org.eclipse.persistence.core-2.6.0.jar!/:?]
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:657) ~[jar:rsrc:org.eclipse.persistence.jpa-2.6.0.jar!/:?]
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:614) ~[jar:rsrc:org.eclipse.persistence.jpa-2.6.0.jar!/:?]
        ... 37 more
    Caused by: java.net.MalformedURLException
        at java.net.URL.<init>(Unknown Source) ~[?:1.8.0_45]
        at java.net.URL.<init>(Unknown Source) ~[?:1.8.0_45]
        at java.net.URL.<init>(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) ~[?:1.8.0_45]
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:655) ~[jar:rsrc:org.eclipse.persistence.jpa-2.6.0.jar!/:?]
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:614) ~[jar:rsrc:org.eclipse.persistence.jpa-2.6.0.jar!/:?]
        ... 37 more
    Caused by: java.lang.NullPointerException
        at java.net.URL.<init>(Unknown Source) ~[?:1.8.0_45]
        at java.net.URL.<init>(Unknown Source) ~[?:1.8.0_45]
        at java.net.URL.<init>(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source) ~[?:1.8.0_45]
        at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) ~[?:1.8.0_45]
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceXML(PersistenceUnitProcessor.java:655) ~[jar:rsrc:org.eclipse.persistence.jpa-2.6.0.jar!/:?]
        at org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processPersistenceArchive(PersistenceUnitProcessor.java:614) ~[jar:rsrc:org.eclipse.persistence.jpa-2.6.0.jar!/:?]
        ... 37 more

我的持久化单元文件是

<?xml version="1.0" encoding="UTF-8"?>
<persistence 
    version="2.1" 
    xmlns="http://xmlns.jcp.org/xml/ns/persistence" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

    <persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>

        <class>com.cremonaufficio.appbarsangiorgio.backend.database.entity.ProdottoEntity</class>

        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:h2:~/scanner/database/database" /><!-- ~/ -->
            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
            <property name="javax.persistence.jdbc.user" value="app" />
            <property name="javax.persistence.jdbc.password" value="app1505" /> 
            <property name="eclipselink.logging.level" value="INFO" />
            <property name="eclipselink.ddl-generation" value="create-tables" />
        </properties>

    </persistence-unit>


</persistence>

我想问题出在 url 但即使使用 ./ 指向 jar 旁边的文件夹,它也无法正常工作。有什么猜测吗?

我知道问题出在哪里了。结果是我生成 JAR 的方式:我不得不选择 "Extract required libraries" 而不仅仅是 "Package required libraries".

干杯。