|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Feb 2006
Messaggi: 958
|
[Java] Problema JEE
Sto facendo un progetto in JEE per l'università. Non ho mai usato JEE prima e quindi stavo facendo qualche prova. Uso eclipse for JEE developer e JBoss. questo è il piccolo pezzo di codice che ho scritto per il client.
Codice:
import java.util.Properties; import com.AgriNet.controlli.*; import javax.naming.*; public class Main { public static Context getInitialContext() throws javax.naming.NamingException { System.out.println("2"); Properties properties = new Properties(); properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory"); properties.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces"); properties.put("java.naming.provider.url","localhost"); return new javax.naming.InitialContext(properties); } public static void main(String[] args) { try { System.out.println("1"); Context jndiContext = getInitialContext(); Object ref = jndiContext.lookup("ProvaRemote"); System.out.println("3"); ProvaRemote pr=(ProvaRemote) ref; System.out.println("4"); pr.prova(); System.out.println("6"); } catch(Exception e){e.printStackTrace();} } } Codice:
import javax.ejb.*; import javax.persistence.*; import com.AgriNet.entità.*; import org.jboss.annotation.ejb.RemoteBinding; @Stateless @RemoteBinding(jndiBinding="ProvaRemote") public class ProvaBean implements ProvaRemote{ @PersistenceContext(unitName="agrinet") private EntityManager manager; public void prova(){ Cliente cl=new Cliente(); cl.setId(10); cl.setNome("mario"); manager.persist(cl); System.out.println("5"); } } Codice:
import javax.ejb.*; @Remote public interface ProvaRemote { public void prova(); } Codice:
javax.naming.NameNotFoundException: ProvaRemote not bound at org.jnp.server.NamingServer.getBinding(NamingServer.java:529) at org.jnp.server.NamingServer.getBinding(NamingServer.java:537) at org.jnp.server.NamingServer.getObject(NamingServer.java:543) at org.jnp.server.NamingServer.lookup(NamingServer.java:296) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source) at sun.rmi.transport.Transport$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Unknown Source) at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source) at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source) at sun.rmi.server.UnicastRef.invoke(Unknown Source) at org.jnp.server.NamingServer_Stub.lookup(Unknown Source) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:667) at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627) at javax.naming.InitialContext.lookup(Unknown Source) at com.AgriNet.interfacce.Main.main(Main.java:21) grazie |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Feb 2006
Messaggi: 958
|
up
|
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Feb 2006
Messaggi: 958
|
già che ci sono vi posto i file persistence.xml e il file per configurare il data source
persistence.xml (contenuto nella cartella ejb-module\meta-inf del progetto del server) Codice:
<?xml version="1.0" encoding="UTF-8" ?> <persistence> <persistence-unit name="agrinet"> <jta-data-source>java:/MySqlDS</jta-data-source> <properties> <property name="hibernate.hbm2ddl.auto" value="create-drop" /> </properties> </persistence-unit> </persistence> Codice:
<?xml version="1.0" encoding="UTF-8" ?> <datasources> <local-tx-datasource> <jndi-name>MySqlDS</jndi-name> <connection-url>jdbc:mysql://localhost:3306/agrinetdb</connection-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <user-name>root</user-name> <password>agrinetpass</password> <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name> <metadata> <type-mapping>mySQL</type-mapping> </metadata> </local-tx-datasource> </datasources> |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Feb 2006
Messaggi: 958
|
per finire posto il log di JBoss (la parte interessante dovrebbe essere in fondo, sembra proprio che ci sia qualcosa che non va ma non capisco cosa)
Codice:
09:23:29,127 INFO [Server] Starting JBoss (MX MicroKernel)... 09:23:29,127 INFO [Server] Release ID: JBoss [Trinity] 4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181439) 09:23:29,128 INFO [Server] Home Dir: C:\Program Files (x86)\jboss-4.2.3.GA 09:23:29,129 INFO [Server] Home URL: file:/C:/Program Files (x86)/jboss-4.2.3.GA/ 09:23:29,129 INFO [Server] Patch URL: null 09:23:29,129 INFO [Server] Server Name: default 09:23:29,129 INFO [Server] Server Home Dir: C:\Program Files (x86)\jboss-4.2.3.GA\server\default 09:23:29,129 INFO [Server] Server Home URL: file:/C:/Program Files (x86)/jboss-4.2.3.GA/server/default/ 09:23:29,130 INFO [Server] Server Log Dir: C:\Program Files (x86)\jboss-4.2.3.GA\server\default\log 09:23:29,130 INFO [Server] Server Temp Dir: C:\Program Files (x86)\jboss-4.2.3.GA\server\default\tmp 09:23:29,130 INFO [Server] Root Deployment Filename: jboss-service.xml 09:23:29,350 INFO [ServerInfo] Java version: 1.6.0_13,Sun Microsystems Inc. 09:23:29,351 INFO [ServerInfo] Java VM: Java HotSpot(TM) Client VM 11.3-b02,Sun Microsystems Inc. 09:23:29,351 INFO [ServerInfo] OS-System: Windows Vista 6.0,x86 09:23:29,640 INFO [Server] Core system initialized 09:23:31,122 INFO [WebService] Using RMI server codebase: http://127.0.0.1:8083/ 09:23:31,124 INFO [Log4jService$URLWatchTimerTask] Configuring from URL: resource:jboss-log4j.xml 09:23:31,444 INFO [TransactionManagerService] JBossTS Transaction Service (JTA version) - JBoss Inc. 09:23:31,445 INFO [TransactionManagerService] Setting up property manager MBean and JMX layer 09:23:31,575 INFO [TransactionManagerService] Starting recovery manager 09:23:31,640 INFO [TransactionManagerService] Recovery manager started 09:23:31,640 INFO [TransactionManagerService] Binding TransactionManager JNDI Reference 09:23:33,431 INFO [EJB3Deployer] Starting java:comp multiplexer 09:23:35,181 INFO [NativeServerConfig] JBoss Web Services - Native 09:23:35,181 INFO [NativeServerConfig] jbossws-3.0.1-native-2.0.4.GA (build=200803312044) 09:23:35,882 INFO [Embedded] Catalina naming disabled 09:23:36,006 INFO [AprLifecycleListener] The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre6/bin/client;C:/Program Files (x86)/Java/jre6/bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\TortoiseSVN\bin 09:23:36,047 INFO [Http11Protocol] Initializing Coyote HTTP/1.1 on http-127.0.0.1-8080 09:23:36,050 INFO [AjpProtocol] Initializing Coyote AJP/1.3 on ajp-127.0.0.1-8009 09:23:36,050 INFO [Catalina] Initialization processed in 168 ms 09:23:36,050 INFO [StandardService] Starting service jboss.web 09:23:36,051 INFO [StandardEngine] Starting Servlet Engine: JBossWeb/2.0.1.GA 09:23:36,089 INFO [Catalina] Server startup in 39 ms 09:23:36,172 INFO [TomcatDeployer] deploy, ctxPath=/, warUrl=.../deploy/jboss-web.deployer/ROOT.war/ 09:23:36,746 INFO [TomcatDeployer] deploy, ctxPath=/invoker, warUrl=.../deploy/http-invoker.sar/invoker.war/ 09:23:36,850 INFO [TomcatDeployer] deploy, ctxPath=/jbossws, warUrl=.../deploy/jbossws.sar/jbossws-context.war/ 09:23:36,922 INFO [TomcatDeployer] deploy, ctxPath=/jbossmq-httpil, warUrl=.../deploy/jms/jbossmq-httpil.sar/jbossmq-httpil.war/ 09:23:37,391 INFO [TomcatDeployer] deploy, ctxPath=/web-console, warUrl=.../deploy/management/console-mgr.sar/web-console.war/ 09:23:37,699 INFO [MailService] Mail Service bound to java:/Mail 09:23:37,819 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-ha-local-jdbc.rar 09:23:37,848 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-ha-xa-jdbc.rar 09:23:37,874 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-local-jdbc.rar 09:23:37,901 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jboss-xa-jdbc.rar 09:23:37,954 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/jms/jms-ra.rar 09:23:37,980 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/mail-ra.rar 09:23:38,014 INFO [RARDeployment] Required license terms exist, view META-INF/ra.xml in .../deploy/quartz-ra.rar 09:23:38,022 INFO [QuartzResourceAdapter] start quartz!!! 09:23:38,073 INFO [SimpleThreadPool] Job execution threads will use class loader of thread: main 09:23:38,089 INFO [QuartzScheduler] Quartz Scheduler v.1.5.2 created. 09:23:38,091 INFO [RAMJobStore] RAMJobStore initialized. 09:23:38,091 INFO [StdSchedulerFactory] Quartz scheduler 'DefaultQuartzScheduler' initialized from default resource file in Quartz package: 'quartz.properties' 09:23:38,092 INFO [StdSchedulerFactory] Quartz scheduler version: 1.5.2 09:23:38,092 INFO [QuartzScheduler] Scheduler DefaultQuartzScheduler_$_NON_CLUSTERED started. 09:23:38,220 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MySqlDS' to JNDI name 'java:MySqlDS' 09:23:38,796 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS' 09:23:39,001 INFO [A] Bound to JNDI name: queue/A 09:23:39,002 INFO [b] Bound to JNDI name: queue/B 09:23:39,003 INFO [C] Bound to JNDI name: queue/C 09:23:39,004 INFO [D] Bound to JNDI name: queue/D 09:23:39,005 INFO [ex] Bound to JNDI name: queue/ex 09:23:39,018 INFO [testTopic] Bound to JNDI name: topic/testTopic 09:23:39,019 INFO [securedTopic] Bound to JNDI name: topic/securedTopic 09:23:39,020 INFO [testDurableTopic] Bound to JNDI name: topic/testDurableTopic 09:23:39,022 INFO [testQueue] Bound to JNDI name: queue/testQueue 09:23:39,049 INFO [UILServerILService] JBossMQ UIL service available at : /127.0.0.1:8093 09:23:39,072 INFO [DLQ] Bound to JNDI name: queue/DLQ 09:23:39,156 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=JmsXA' to JNDI name 'java:JmsXA' 09:23:39,420 INFO [JmxKernelAbstraction] creating wrapper delegate for: org.jboss.ejb3.stateless.StatelessContainer 09:23:39,425 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:jar=AgriNetServer.jar,name=ProvaBean,service=EJB3 with dependencies: 09:23:39,425 INFO [JmxKernelAbstraction] persistence.units:unitName=agrinet 09:23:39,426 INFO [EJB3Deployer] Deployed: file:/C:/Program Files (x86)/jboss-4.2.3.GA/server/default/deploy/AgriNetServer.jar 09:23:39,641 INFO [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/ 09:23:39,727 ERROR [URLDeploymentScanner] Incomplete Deployment listing: --- MBeans waiting for other MBeans --- ObjectName: jboss.j2ee:jar=AgriNetServer.jar,name=ProvaBean,service=EJB3 State: NOTYETINSTALLED I Depend On: persistence.units:unitName=agrinet --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM --- ObjectName: persistence.units:unitName=agrinet State: NOTYETINSTALLED Depends On Me: jboss.j2ee:jar=AgriNetServer.jar,name=ProvaBean,service=EJB3 09:23:39,785 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080 09:23:39,797 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009 09:23:39,804 INFO [Server] JBoss (MX MicroKernel) [4.2.3.GA (build: SVNTag=JBoss_4_2_3_GA date=200807181439)] Started in 10s:673ms |
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Feb 2006
Messaggi: 958
|
ho provato anche rifare da zero l'installazione e la configurazione di jboss e la creazione del progetto ma il problema rimane identico
|
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: Feb 2006
Messaggi: 958
|
ah dimenticavo la classe Cliente è un entity bean con il seguente codice
Codice:
import java.io.Serializable; import javax.persistence.*; import java.util.Date; @Entity @Table (name="clienti") public class Cliente implements Serializable{ private static final long serialVersionUID = 1L; private int id; private String nome; private String cognome; private Date dataNascita; @Id @Column(name="id") public int getId() { return id; } public void setId(int id) { this.id = id; } @Column(name="nome") public String getNome() { return nome; } public void setNome(String nome) { this.nome = nome; } @Column(name="cognome") public String getCognome() { return cognome; } public void setCognome(String cognome) { this.cognome = cognome; } @Column(name="data_nascita") public Date getDataNascita() { return dataNascita; } public void setDataNascita(Date dataNascita) { this.dataNascita = dataNascita; } } |
![]() |
![]() |
![]() |
#7 |
Senior Member
Iscritto dal: Feb 2006
Messaggi: 958
|
eheh questa discussione è più che altro un monologo. cmq ho risolto e ovviamente era problema stupido. semplicemente il file persistence.xml era fatto nel modo giusto e messo nella cartella giusta ma andava anche importato nel progetto in eclipse. io pensavo che lo trovasse in automatico
![]() |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 01:25.