Un batch (de création d'un fichier .csv) non exécuté
Bonjour,
le même code dans un projet simple (sur netBeans) marche très bien, donc je suppose que j'ai une dépendance qui manque ou que un projet simple ajoute quelque chose que je ne voix pas. ?:(
bien sûr je me suis assurais que c'est le bon chemin (path) et que le persistance.xml soit bien.
voilà le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
package dz.elit.sirh.model.batchs;
import au.com.bytecode.opencsv.CSVReader;
import dz.elit.sirh.model.entity.ga.EventCarrierePre;
import dz.elit.sirh.model.manager.ga.EventCarrierePreManagerImpl;
import dz.elit.utlis.JpaUtil;
import java.io.FileReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
/**
*
* @author PC
*/
public class EventCarrierePreBatch {
static String currentDir = System.getProperty("user.dir");
private static final String eventCarrierePre_FILE = currentDir + "\\src\\main\\java\\dz\\elit\\sirh\\model\\batchs\\csv\\eventCarrierePre.csv";
private static final int CODEVT = 0;
private static final int LIBEVT = 1;
/**
* @param args the command line arguments
*/
public static void batch(String path, EntityManager em) {
try {
// TODO code application logic here
CSVReader reader = new CSVReader(new FileReader(eventCarrierePre_FILE), ';');
String[] nextLine;
EventCarrierePreManagerImpl eventCarrierePreManagerImpl = new ExtendEventCarrierePreManagerImpl(em);
int first = 0;
while ((nextLine = reader.readNext()) != null) {
if (first > 0) {
EventCarrierePre eventCarrierePre = new EventCarrierePre();
// eventCarrierePre.setId(Long.valueOf(first));
eventCarrierePre.setCodeEventPre(nextLine[CODEVT]);
eventCarrierePre.setLibelleEvent(nextLine[LIBEVT]);
eventCarrierePreManagerImpl.create(eventCarrierePre);
}
first++;
}
} catch (Exception ex) {
Logger.getLogger(EventCarrierePreBatch.class.getName()).log(Level.SEVERE, null, ex);
}
}// TODO code application logic here
public static void main(String[] args) {
EntityManager em = null;
EntityTransaction utx = null;
System.out.println("---path :---- : " + eventCarrierePre_FILE);
em = JpaUtil.getEntityManager("LOCAL_PU");
utx = em.getTransaction();
utx.begin();
batch(eventCarrierePre_FILE, em);
utx.commit();
}
} |
ce code utilise cette classe dans le mains pour récupérais le em locale
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
package dz.elit.utlis;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/*
* Class pour créer EM , EMF utlisée pour executer les requetes JPA sur
* une classe Main
*/
public final class JpaUtil {
public static EntityManagerFactory getEmf() {
return emf;
}
private static EntityManagerFactory emf;
public static EntityManager getEntityManager(String persistUnitString) {
emf = Persistence.createEntityManagerFactory(persistUnitString);
return emf.createEntityManager();
}
} |
et voilà mon pom.xml de mon ejb (tout en signalement que tout le projet compile parfaitement)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>GestionClient</artifactId>
<groupId>dz.elit.sirh</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>dz.elit.sirh</groupId>
<artifactId>GestionClient-ejb</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>ejb</packaging>
<name>GestionClient-ejb</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.jpa.modelgen.processor</artifactId>
<version>2.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>ApiGestionClient</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>2.3</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>EclipseLink Repo</id>
<name>EclipseLink Repository</name>
<url>http://linorg.usp.br/eclipse/rt/eclipselink/maven.repo/</url>
</repository>
<repository>
<url>http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo/</url>
<id>eclipselink</id>
<layout>default</layout>
<name>Repository for library Library[eclipselink]</name>
</repository>
</repositories>
</project> |
aussi voilà le résulta de l'exécution:
Citation:
run:
---all path :---- : C:\Users\ordinateur\Documents\NetBeansProjects\GestionClient\GestionClient-ejb\src\main\java\dz\elit\sirh\model\batchs\csv\eventCarrierePre.csv
Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/persistence/Persistence
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at dz.elit.utlis.JpaUtil.getEntityManager(JpaUtil.java:23)
at dz.elit.sirh.model.batchs.EventCarrierePreBatch.main(EventCarrierePreBatch.java:64)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
merci