java ee - Class [com.mysql.jdbc.Driver] not found -


i having following project:

enter image description here

the file model.clienti "jpa entity", main.main pojo main method , it's client model.clienti file. main.main has following code:

package main;   import java.util.list; import javax.persistence.entitymanager; import javax.persistence.persistence; import model.clienti;  public class main {     public static void main(string[] args) {          entitymanager entitymanager = persistence.createentitymanagerfactory("jpatestejb").createentitymanager();         list<clienti> list = entitymanager.createquery("select c clienti c", clienti.class).getresultlist();          (clienti clienti : list) {             system.out.println(clienti.getnume());         }     }  } 

and works without problems, outputing have in database.

enter image description here

so 'locally' can use jpa file without problems, yet when try create ejb , ejb client same thing main.main file error.

the ejb located in pachet.employeesession (the interface)

package pachet;  import javax.ejb.remote;  @remote public interface employeesession {     public string getemplastname(integer empno);      public string test(); } 

and employeesessionbean

package pachet;  import java.util.list;  import javax.ejb.ejbexception; import javax.ejb.stateless; import javax.persistence.entitymanager; import javax.persistence.persistence;  import model.clienti;  @stateless public class employeesessionbean implements employeesession {      public string getemplastname(integer empno) {          try {             entitymanager em = persistence.createentitymanagerfactory("jpatestejb").createentitymanager();              list<clienti> list = em.createquery("select c clienti c", clienti.class).getresultlist();              (clienti clienti : list) {                 system.out.println(clienti.getnume());             }         } catch (ejbexception e) {             e.printstacktrace();         }         return "a mers";     }      public string test() {         return "works";     }   } 

for ejb i've created standalone client, in project. enter image description here

the client has 1 class, following:

import javax.naming.initialcontext;  import pachet.employeesession;  public class main {       public static void main(string[] args) {           try {             initialcontext ic = new initialcontext();             employeesession thing = (employeesession) ic.lookup("pachet.employeesession");             system.out.println(thing.test());             system.out.println("it seems runs: " + thing.getemplastname(1));         } catch (exception e) {             e.printstacktrace();         }     }  } 

yet when try run main (this 1 default package) following output enter image description here

as can seen there no problem connecting ejb since thing.test(); returns "works" definetly ran, there no problem regarding required libraries client think, after exception ocures.

enter image description here

the continuation can seen eclipselink doesn't find com.mysql.jdbc.driver.

so question is: how can possible main.main in ejb project run correctly , display info db, yet main ejb client doesn't.

more precisely problem in ejb employeesessionbean, if had following structure:

package pachet;  import java.util.list;  import javax.ejb.ejbexception; import javax.ejb.stateless; import javax.persistence.entitymanager; import javax.persistence.persistence;  import model.clienti;  @stateless public class employeesessionbean implements employeesession {      public string getemplastname(integer empno) {          try {            string b = "nothing";          } catch (ejbexception e) {             e.printstacktrace();         }         return "a mers";     }      public string test() {         return "works";     } 

has following output: (note removed jpa 'business' code) enter image description here }

and can seen both methods invocated client worked. means problem because ejb employeesessionbean can't make use of jpa same main.main file question why? they're definetly in same project , can seen have required libraries eclipselink , mysql-jdbc.

if 1 of them would've been wrong main.main wouldn't able connect well, right? ' time.

here's @ persistence.xml file though seems work ok. http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

    <class>model.clienti</class>     <properties>         <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/comenzi"/>         <property name="javax.persistence.jdbc.user" value="root"/>         <property name="javax.persistence.jdbc.password" value=""/>         <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.driver"/>     </properties>  </persistence-unit> 

you need have mysql jar deployed glassfish server. either deploy app, or put in applib directory on server.

normally in glassfish server datasource used instead of jdbc directly, may want try well.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -