我在尝试导出独立应用程序时遇到问题。
当我使用eclise执行它时,它运行良好,但当我试图导出到可运行的jar时,它会给我一些错误。
我的persistence.xml看起来像
<persistence-unit transaction-type="RESOURCE_LOCAL" name="alctel_server_monitor">
<provider>org.hibernate.ejb.HibernatePersistenceProvider</provider>
<class>br.com.monitor.database.vo.Servidor</class>
<class>br.com.monitor.database.vo.Banco</class>
<class>br.com.monitor.database.vo.Servico</class>
<class>br.com.monitor.database.vo.alerta.Alerta</class>
<class>br.com.monitor.database.vo.alerta.AlertaAtivo</class>
<class>br.com.monitor.database.vo.email.Email</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="hibernate.connection.url" value="jdbc:sqlserver://192.168.99.222;databaseName=MONITOR;" />
<property name="hibernate.connection.username" value="" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
<property name="hibernate.hbm2ddl.auto" value="none" />
<property name="hibernate.hbm2ddl.import_files_sql_extractor"
value="org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor" />
<property name="hibernate.connection.useUnicode" value="true" />
<property name="hibernate.connection.characterEncoding"
value="UTF-8" />
</properties>
</persistence-unit>
它位于src/META-INF/persistence.xml
当我从终端运行它时,我得到的堆栈跟踪是:
位于java.lang.reflect.Method.ioke(未知源)网址:org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)引起原因:javax.persistence.PersistenceException:找不到持久性单元位于org.hibernate.jpa.Hhibernate PersistenceProvider.getEntityManagerFactoryBuilderOrNull(hibernate Persistence Provider.java:99)位于org.hibernate.ejb.Hhibernate Persistence.getEntityManagerFactoryBuilderOrNull(hibernate Persistency.java:93)位于org.hibernate.jpa.Hhibernate PersistenceProvider.getEntityManagerFactoryBuilderOrNull(hibernate Persistence Provider.java:86)位于org.hibernate.ejb.Hhibernate Persistence.getEntityManagerFactoryBuilderOrNull(hibernate Persistency.java:101)位于org.hibernate.jpa.Hhibernate PersistenceProvider.createEntityManagerFactory(hibernate Persistence Provider.java:67)位于org.hibernate.ejb.Hhibernate Persistence.createEntityManagerFactory(hibernate Persistency.java:54)在javax.persistence.persistence.createEntityManagerFactory(persistence.java:55)
我不知道发生了什么,有人能帮我吗?
谢谢!
我遇到了同样的问题,我通过以下方式解决了:
右键单击项目>属性>Java构建路径>订单和导出,然后选择库
右键单击项目>导出…>可运行的JAR文件>将所需的库复制到生成的JAR 旁边的子文件夹