salut,

voici mon problème : je voudrais créer un projet maven avec netbeans contenant un EJB, une classe JPA, et un client.
j'ai donc créé un EAR maven contenant 1 module EJB; donc netbeans me créé 3 projets : un projet EJB, un projet Assembly, et un projet "Enterprise Application".
dans le projet EJB, j'ai ceci :

une classe JPA
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
127
128
129
130
131
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package jpa;
 
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
 
/**
 *
 * @author lolveley
 */
@Entity
@NamedQuery(name="findAllBooks",query="select b from Book2 b")
public class Book2 implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
 
    @Column(nullable=false)
    private String title;
 
    public String getTitle() {
        return title;
    }
 
    public void setTitle(String title) {
        this.title = title;
    }
 
    private Float price;
 
    public Float getPrice() {
        return price;
    }
 
    public void setPrice(Float price) {
        this.price = price;
    }
 
    @Column(length=2000)
    private String description;
 
    public String getDescription() {
        return description;
    }
 
    public void setDescription(String description) {
        this.description = description;
    }
 
 
    private String ISBN;
 
    public String getISBN() {
        return ISBN;
    }
 
    public void setISBN(String ISBN) {
        this.ISBN = ISBN;
    }
 
    private Integer nbOfPages;
 
    public Integer getNbOfPages() {
        return nbOfPages;
    }
 
    public void setNbOfPages(Integer nbOfPages) {
        this.nbOfPages = nbOfPages;
    }
 
    private Boolean illustrations;
 
    public Boolean getIllustrations() {
        return illustrations;
    }
 
    public void setIllustrations(Boolean illustrations) {
        this.illustrations = illustrations;
    }
 
 
 
 
 
 
 
    public Long getId() {
        return id;
    }
 
    public void setId(Long id) {
        this.id = id;
    }
 
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }
 
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Book2)) {
            return false;
        }
        Book2 other = (Book2) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }
 
    @Override
    public String toString() {
        return "jpa.Book[id=" + id + "]";
    }
 
}
un EJB :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package ejb;
 
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import jpa.Book2;
 
/**
 *
 * @author lolveley
 */
@Stateless
public class BookEJB implements BookEJBRemote {
 
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
 
    @PersistenceContext(unitName="lorry1")
    private EntityManager em;
 
    public List<Book2> findBooks() {
 
        Query query = em.createNamedQuery("findAllBooks");
        return query.getResultList();
 
    }
 
    public Book2 findBookById(Long id) {
 
        return em.find(Book2.class, id);
 
    }
 
    public Book2 createBook(Book2 book) {
 
        EntityTransaction tx=em.getTransaction();
        tx.begin();
        em.persist(book);
        tx.commit();
        return book;
    }
 
    public void deleteBook(Book2 book) {
 
        em.remove(em.merge(book));
    }
 
    public Book2 updateBook(Book2 book) {
 
        return em.merge(book);
    }
 
}
avec son interface distante (que je ne mets pas dans la post, il n'y a rien de particulier).

voici la classe Main:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package lorry;
 
import ejb.BookEJBRemote;
import javax.ejb.EJB;
import jpa.Book2;
 
/**
 *
 * @author lolveley
 */
public class Main {
 
    @EJB
    private static BookEJBRemote bookEJB;
 
    public static void main(String[] args){
 
        Book2 book=new Book2();
        book.setId(0L);
        book.setTitle("guerre & paix");
        book.setPrice(12.5F);
        book.setDescription("un grand livre, une fresque!");
        book.setISBN("1254-5558-9872");
        book.setNbOfPages(354);
        book.setIllustrations(false);
 
        System.out.println("c fait");
        book=bookEJB.createBook(book);
        System.out.println(book.getId());
 
    }
 
}
et voici encore le fichier persistence.xml:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="lorry1" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/myjdbc2</jta-data-source>
    <properties>
      <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
      <property name="eclipselink.logging.level" value="INFO"/>
    </properties>
  </persistence-unit>
</persistence>
et le pom.xml :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>librairie3_chap06</artifactId>
        <groupId>lorry.12082010</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>lorry.12082010</groupId>
    <artifactId>librairie3_chap06-ejb</artifactId>
    <packaging>ejb</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>librairie3_chap06-ejb Java EE 6 EJB</name>
    <url>http://maven.apache.org</url>
    <dependencies>
 
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>
 
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.2</version>
            <scope>test</scope>
        </dependency>
 
    </dependencies>
 
    <repositories>
        <repository>
            <id>java.net2</id>
            <name>Java.Net Maven2 Repository, hosts the javaee-api dependency</name>
            <url>http://download.java.net/maven/2</url>
        </repository>
    </repositories>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.0.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <ejbVersion>3.1</ejbVersion>
                </configuration>
            </plugin>
        </plugins>
        <finalName>librairie3_chap06-ejb</finalName>
    </build>
    <profiles>
        <profile>
            <id>endorsed</id>
            <activation>
                <property>
                    <name>sun.boot.class.path</name>
                </property>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>2.0.2</version>
                        <configuration>
                            <!-- javaee6 contains upgrades of APIs contained within the JDK itself.
                                 As such these need to be placed on the bootclasspath, rather than classpath of the
                                 compiler.
                                 If you don't make use of these new updated API, you can delete the profile.
                                 On non-SUN jdk, you will need to create a similar profile for your jdk, with the similar property as sun.boot.class.path in Sun's JDK.-->
                            <compilerArguments>
                                <bootclasspath>${settings.localRepository}/javax/javaee-endorsed-api/6.0/javaee-endorsed-api-6.0.jar${path.separator}${sun.boot.class.path}</bootclasspath>
                            </compilerArguments>
                        </configuration>
                        <dependencies>
                            <dependency>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>6.0</version>
                            </dependency>
                        </dependencies>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
    <properties>
        <netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
    </properties>
</project>
Quand je déploie l'assembly, les tables en base sont bien crées mais rien n'est mis dedans.

voici les résultats d'une commande "exécuter" :

fenêtre d'affichage de glassfish :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
15 août 2010 13:54:07 com.sun.enterprise.glassfish.bootstrap.ASMain main
INFO: Launching GlassFish on Felix platform
Welcome to Felix
================
INFO: Perform lazy SSL initialization for the listener 'http-listener-2'
INFO: Starting Grizzly Framework 1.9.18-o - Sun Aug 15 13:54:12 CEST 2010
INFO: Grizzly Framework 1.9.18-o started in: 51ms listening on port 4848
INFO: Grizzly Framework 1.9.18-o started in: 64ms listening on port 8181
INFO: Grizzly Framework 1.9.18-o started in: 35ms listening on port 3700
INFO: Grizzly Framework 1.9.18-o started in: 119ms listening on port 8080
INFO: Starting Grizzly Framework 1.9.18-o - Sun Aug 15 13:54:12 CEST 2010
INFO: Grizzly Framework 1.9.18-o started in: 3ms listening on port 7676
INFO: The Admin Console is already installed, but not yet loaded.
INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
INFO: SEC1002: Security Manager is OFF.
INFO: Security startup service called
INFO: SEC1143: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
INFO: Realm admin-realm of classtype com.sun.enterprise.security.auth.realm.file.FileRealm successfully created.
INFO: Realm file of classtype com.sun.enterprise.security.auth.realm.file.FileRealm successfully created.
INFO: Realm certificate of classtype com.sun.enterprise.security.auth.realm.certificate.CertificateRealm successfully created.
INFO: Security service(s) started successfully....
INFO: Hibernate Validator bean-validator-3.0-JBoss-4.0.2
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: JTS5014: Recoverable JTS instance, serverId = [3700]
INFO: jpa.Book2 actually got transformed
INFO: Portable JNDI names for EJB BookEJB : [java:global/lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT/librairie3_chap06-ejb-1.0-SNAPSHOT/BookEJB!ejb.BookEJBRemote, java:global/lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT/librairie3_chap06-ejb-1.0-SNAPSHOT/BookEJB]
INFO: Glassfish-specific (Non-portable) JNDI names for EJB BookEJB : [ejb.BookEJBRemote#ejb.BookEJBRemote, ejb.BookEJBRemote]
INFO: Loading lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT Application done is 9397 ms
INFO: GlassFish Server Open Source Edition 3.0.1 (22) startup time : Felix(3948ms) startup services(10659ms) total(14607ms)
INFO: Binding RMI port to *:8686
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: JMXStartupService: Started JMXConnector, JMXService URL = service:jmx:rmi://192.168.1.72:8686/jndi/rmi://192.168.1.72:8686/jmxrmi
INFO: Grizzly Framework 1.9.18-o started in: 5ms listening on port 8080
INFO: [Thread[GlassFish Kernel Main Thread,5,main]] started
INFO: {felix.fileinstall.poll (ms) = 5000, felix.fileinstall.dir = /Applications/NetBeans/glassfish-3.0.1/glassfish/domains/domain1/autodeploy/bundles, felix.fileinstall.debug = 1, felix.fileinstall.bundles.new.start = true, felix.fileinstall.tmpdir = /var/folders/Ta/TatJtUu8F3mZ3JmPBa8fv++++TI/-Tmp-/fileinstall-2875472489092023868, felix.fileinstall.filter = null}
INFO: {felix.fileinstall.poll (ms) = 5000, felix.fileinstall.dir = /Applications/NetBeans/glassfish-3.0.1/glassfish/modules/autostart, felix.fileinstall.debug = 1, felix.fileinstall.bundles.new.start = true, felix.fileinstall.tmpdir = /var/folders/Ta/TatJtUu8F3mZ3JmPBa8fv++++TI/-Tmp-/fileinstall-4502932700265827982, felix.fileinstall.filter = null}
INFO: Started bundle: file:/Applications/NetBeans/glassfish-3.0.1/glassfish/modules/autostart/org.apache.felix.scr.jar
INFO: Started bundle: file:/Applications/NetBeans/glassfish-3.0.1/glassfish/modules/autostart/osgi-web-container.jar
INFO: Perform lazy SSL initialization for the listener 'http-listener-2'
INFO: Grizzly Framework 1.9.18-o started in: 12ms listening on port 8181
INFO: jpa.Book2 actually got transformed
INFO: Portable JNDI names for EJB BookEJB : [java:global/lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT/librairie3_chap06-ejb-1.0-SNAPSHOT/BookEJB!ejb.BookEJBRemote, java:global/lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT/librairie3_chap06-ejb-1.0-SNAPSHOT/BookEJB]
INFO: Glassfish-specific (Non-portable) JNDI names for EJB BookEJB : [ejb.BookEJBRemote#ejb.BookEJBRemote, ejb.BookEJBRemote]
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: EclipseLink, version: Eclipse Persistence Services - 2.0.1.v20100213-r6600
INFO: file:/Users/lolveley/NetBeansProjects/librairie3_chap06/librairie3_chap06-ear/target/gfdeploy/lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT/librairie3_chap06-ejb-1.0-SNAPSHOT_jar/_lorry1 login successful
ATTENTION: Got SQLException executing statement "CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(38), PRIMARY KEY (SEQ_NAME))": com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'SEQUENCE' already exists
INFO: lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT was successfully deployed in 1*296 milliseconds.
INFO: Updating configuration from org.apache.felix.fileinstall-autodeploy-bundles.cfg
INFO: Installed /Applications/NetBeans/glassfish-3.0.1/glassfish/modules/autostart/org.apache.felix.fileinstall-autodeploy-bundles.cfg
INFO: {felix.fileinstall.poll (ms) = 5000, felix.fileinstall.dir = /Applications/NetBeans/glassfish-3.0.1/glassfish/domains/domain1/autodeploy/bundles, felix.fileinstall.debug = 1, felix.fileinstall.bundles.new.start = true, felix.fileinstall.tmpdir = /var/folders/Ta/TatJtUu8F3mZ3JmPBa8fv++++TI/-Tmp-/fileinstall--7172791434366927223, felix.fileinstall.filter = null}
INFO: file:/Users/lolveley/NetBeansProjects/librairie3_chap06/librairie3_chap06-ear/target/gfdeploy/lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT/librairie3_chap06-ejb-1.0-SNAPSHOT_jar/_lorry1 logout successful
INFO: jpa.Book2 actually got transformed
INFO: Portable JNDI names for EJB BookEJB : [java:global/lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT/librairie3_chap06-ejb-1.0-SNAPSHOT/BookEJB!ejb.BookEJBRemote, java:global/lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT/librairie3_chap06-ejb-1.0-SNAPSHOT/BookEJB]
INFO: Glassfish-specific (Non-portable) JNDI names for EJB BookEJB : [ejb.BookEJBRemote#ejb.BookEJBRemote, ejb.BookEJBRemote]
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: EclipseLink, version: Eclipse Persistence Services - 2.0.1.v20100213-r6600
INFO: file:/Users/lolveley/NetBeansProjects/librairie3_chap06/librairie3_chap06-ear/target/gfdeploy/lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT/librairie3_chap06-ejb-1.0-SNAPSHOT_jar/_lorry1 login successful
ATTENTION: Got SQLException executing statement "CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50) NOT NULL, SEQ_COUNT DECIMAL(38), PRIMARY KEY (SEQ_NAME))": com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'SEQUENCE' already exists
INFO: lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT was successfully deployed in 474 milliseconds.
et la fenêtre "du projet" (à côté de la précédente) :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
NetBeans: Executing 'mvn -Dnetbeans.deploy=true -Dnetbeans.execution=true install'
NetBeans:      JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
Scanning for projects...
------------------------------------------------------------------------
Building librairie3_chap06-ear JavaEE6 Assembly
   task-segment: [install]
------------------------------------------------------------------------
[ear:generate]
Generating application.xml
[resources:resources]
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
skip non existing resourceDirectory /Users/lolveley/NetBeansProjects/librairie3_chap06/librairie3_chap06-ear/src/main/resources
[ear:ear]
Copy ear sources to /Users/lolveley/NetBeansProjects/librairie3_chap06/librairie3_chap06-ear/target/librairie3_chap06-ear
Including custom manifest file[/Users/lolveley/NetBeansProjects/librairie3_chap06/librairie3_chap06-ear/target/librairie3_chap06-ear/META-INF/MANIFEST.MF]
Building jar: /Users/lolveley/NetBeansProjects/librairie3_chap06/librairie3_chap06-ear/target/librairie3_chap06-ear.ear
[install:install]
Installing /Users/lolveley/NetBeansProjects/librairie3_chap06/librairie3_chap06-ear/target/librairie3_chap06-ear.ear to /Users/lolveley/.m2/repository/lorry/12082010/librairie3_chap06-ear/1.0-SNAPSHOT/librairie3_chap06-ear-1.0-SNAPSHOT.ear
------------------------------------------------------------------------
BUILD SUCCESSFUL
------------------------------------------------------------------------
Total time: 2 seconds
Finished at: Sun Aug 15 19:57:38 CEST 2010
Final Memory: 12M/81M
------------------------------------------------------------------------
NetBeans: Deploying on GlassFish Server 3
    profile mode: false
    debug mode: false
    force redeploy: true
Undeploying ...
Initial deploying librairie3_chap06-ear to /Users/lolveley/NetBeansProjects/librairie3_chap06/librairie3_chap06-ear/target/gfdeploy/lorry.12082010_librairie3_chap06-ear_ear_1.0-SNAPSHOT
Completed initial distribution of librairie3_chap06-ear
Initializing...
pour l'action "run project" j'ai placé le "goal" : "install", je ne sais pas si c'est important...

olivier.