Я не знаю, существует ли этот вопрос и нашел ли он ответ, но сейчас я ищу в Google и даже на этом сайте уже месяц, но я не нашел решения своей проблемы.
Я разрабатываю приложение для управления запасами с NebtBeans 8.2 и EclipseLink JPA 2.1 с jdk 8.
Вот моя проблема: когда я компилирую и запускаю с IDE, все работает, кроме предупреждений, но один разЯ сгенерировал .jar и пытаюсь запустить, программа вылетает и выдает мне такую ошибку:
java -jar "/home/instantech/Bureau/JAVA Projects/AfricaBadja/dist/AfricaBadja.jar"
Exception in thread "AWT-EventQueue-0" Local Exception Stack:
Exception [EclipseLink-30005] (Eclipse Persistence Services - 2.6.1.v20150605-31e8258): org.eclipse.persistence.exceptions.PersistenceUnitLoadingException
Exception Description: An exception was thrown while searching for persistence archives with ClassLoader: jdk.internal.loader.ClassLoaders$AppClassLoader@1affbebc
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.PersistenceUnitLoadingException.exceptionSearchingForPersistenceResources(PersistenceUnitLoadingException.java:127)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:115)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:188)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at Entity.ManagerEntity.<init>(ManagerEntity.java:28)
at Manager.AdminManager.<init>(AdminManager.java:21)
at frontend.FormLogin.<init>(FormLogin.java:26)
at frontend.FormLogin.lambda$main$0(FormLogin.java:213)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Caused by: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:2022)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:100)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:104)
... 20 more
Итак, это моя конфигурация файла persistence.xml:
<?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="AfricaBadjaPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<class>Manager.Admin</class>
<class>Manager.Client</class>
<class>Manager.Credit</class>
<class>Manager.Role</class>
<class>Manager.Produit</class>
<class>Manager.Commande</class>
<class>Manager.Depense</class>
<class>Manager.LigneCommande</class>
<class>Manager.Sauvegarde</class>
<class>Manager.HistoryStock</class>
<class>Manager.Caisse</class>
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/africa_badja_18_19"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipselink.ddl-generation.output-mode" value="database"/>
<property name="eclipselink.ddl-generation-mode" value="ddl_database_generation"/>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
Это мой ManagerEntity, который инициализирует соединение с базой данных:
package Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/**
*
* @author instantech
*/
public class ManagerEntity {
private final EntityManagerFactory emfactory;
private final EntityManager entitymanager;
public ManagerEntity() {
this.emfactory = Persistence.createEntityManagerFactory("AfricaBadjaPU");
this.entitymanager = this.emfactory.createEntityManager();
}
public EntityManagerFactory getEmfactory() {
return emfactory;
}
public EntityManager getEntitymanager() {
return entitymanager;
}
public void close() {
this.entitymanager.close();
this.emfactory.close();
}
public boolean save(Object object) {
try {
this.getEntitymanager().getTransaction().begin();
this.getEntitymanager().persist(object);
this.getEntitymanager().getTransaction().commit();
this.close();
return true;
} catch (Exception e) {
System.err.println("Error : " + e.getMessage());
}
return false;
}
public boolean remove(Object object, Integer id) {
try {
this.getEntitymanager().getTransaction().begin();
object = this.getEntitymanager().find(object.getClass(), id);
this.getEntitymanager().remove(object);
this.getEntitymanager().getTransaction().commit();
this.close();
return true;
} catch (Exception e) {
System.err.println("Error : " + e.getMessage());
}
return false;
}
}
Если кто-то может помочь мне исправить эту ошибку.