I want deploy a Stateful EJB Bean in my standalone JavaFx Client without an application server. The EJB Class has a entitymanager reference and makes transactions against db. The Project is a maven archetype and i added the EJB class in a package.
From my main method i make a JNDI lookup like this
Properties props = new Properties();
props.put(EJBContainer.APP_NAME, "testejb");
props.put(EJBContainer.MODULES, new File("target/classes"));
EJBContainer ec = EJBContainer.createEJBContainer(props);
Context ctx = ec.getContext();
myEjbClass = (MyEjbClass) ctx.lookup("java:global/testejb/MyEjbClass");
I become exception javax.ejb.EJBException: No EJBContainer provider available: no provider names had been found. I have added the javaee-7 and glassfish-embedded-shell to my pom.xml.Why?
Have you configured and started the embedded Glassfish in your program?
This can be done by doing this:
BootstrapProperties bootstrapProperties = new BootstrapProperties();
bootstrapProperties.setInstallRoot("C:\\applicationserverdir");
GlassFishRuntime glassfishRuntime = GlassFishRuntime.bootstrap(bootstrapProperties);
GlassFishProperties glassfishProperties = new GlassFishProperties();
glassfishProperties.setInstanceRoot("C:\\applicationserverdir\\domains\\myJavaFXAppDomain");
glassfishProperties.setPort("http-listener", 8080);
glassfishProperties.setPort("https-listener", 8181);
GlassFish glassfish = glassfishRuntime.newGlassFish(glassfishProperties);
glassfish.start();
More information on setup embedded Glassfish here: http://docs.oracle.com/cd/E18930_01/html/821-2424/giijw.html#scrolltoc
Also, which Maven archetype are you using?
Related
I have this exception when I lookup jndi datasource from weblogic from spring boot application...only after one successful deployment...I mean from the second deployment on.If I restart the container, it will work fine for the first deployment only.
Caused by: javax.naming.NameNotFoundException: Unable to resolve 'jdbc.payment'. Resolved 'jdbc'; remaining name 'payment'
the datasource with the same name and attached to the admin server.
I use docker image : store/oracle/weblogic:12.2.1.4-dev with environment variable PRODUCTION_MODE=dev
update : if I deattach the data source from the server then reattche it again then start the war, It runs successfully for one time againŲ²
update : switched to local installation of weblogic not dockerized any more and the behavior still happens
It's a spring issue...has nothing to do with weblogic.
In the war shutdown, Spring remove the data source form the server JNDI tree, however the data source still up and running on the server.
The action of recreating or even reattaching the data source to target server, add it again to the JNDI tree.
The workaround to solve this behavior is to prevent spring from calling the destroy method of the data source bean
#Primary
#Bean(name = "dataSource",destroyMethod = "")
#Profile("weblogic")
public DataSource dataSourceWeblogic() throws NamingException {
JndiTemplate jndiTemplate = new JndiTemplate();
InitialContext ctx = (InitialContext) jndiTemplate.getContext();
return (javax.sql.DataSource) ctx.lookup(jndi);
}
I am following this fundamentals of JEE tutorial which provides instruction to create a minimal EJB deployment.
I have gone through the steps in the tutorials but made changes to the following command line invocations
>set CLASSPATH=.;E:\wildfly-10.1.0\wildfly-10.1.0.Final\bin\client\jboss-client.jar; (Changed from the long list in the tutorial)
>jar -cvf SimpleSessionApp.ear beans*.java (Changed file extention to .ear from .ejb3)
copy SimpleSessionApp.ear E:\wildfly-10.1.0\wildfly-10.1.0.Final\standalone\deployments (Copied to the wildfly deployment directory)
I started the server and I did not get any errors. However, I did not get set of standard names the server log outputs when a bean is deployed.
I ran the client application using the following command as in tutorial
>java -D java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory -D java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces -D java.naming.provider.url=localhost client.SimpleSessionClient Now is the time for all good men
I get the following error as the output
Error: Could not find or load main class java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
I know the tutorial caters for an older version of Java and JBoss. However, I modified the old references to point to the newer environment as mentioned above. So I assume versioning is not a issue here? BTW I'm just starting to learn EJB. Any insights would be great.
My Environment
Java 1.8.0.212
Wildfly 10.1.0.Final
Notepad
You should look at the reference documentation https://docs.wildfly.org/17/Developer_Guide.html#JNDI_Remote_Reference as it seems your are passing wrong configuration parameters.
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
// the property below is required ONLY if there is no ejb client configuration loaded (such as a
// jboss-ejb-client.properties in the class path) and the context will be used to lookup EJBs
env.put("jboss.naming.client.ejb.context", true);
InitialContext remoteContext = new InitialContext(env);
RemoteCalculator ejb = (RemoteCalculator) remoteContext.lookup("wildfly-http-remoting-ejb/CalculatorBean!"
+ RemoteCalculator.class.getName());
All,
I am trying to invoke an EJB from remote standalone program. EJB is properly deployed on JBOSS 7.0. I am using the below code to do the lookup:
Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
jndiProps.put(Context.SECURITY_PRINCIPAL, "user1");
jndiProps.put(Context.SECURITY_CREDENTIALS, "password#123?");
jndiProps.put("jboss.naming.client.ejb.context", true);
try {
Context ctx = new InitialContext(jndiProps);
HelloWorld d= (HelloWorld) ctx.lookup("HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld");
// String s=d.sayHello();
// System.out.println(s);
}
catch(Exception ne) {
ne.printStackTrace();
}
But I am getting the below exception and unable to proceed further. Can anyone let me know what I am missing:
Failed to connect to any server. Servers tried: [http-remoting://localhost:8080]
javax.naming.NamingException: Failed to connect to any server. Servers tried: [http-remoting://localhost:8080]
My Server is up and running and I am using standalone-full.xml file
I think http-remoting: protocol is not available in your version of JBoss (AS 7).
Change your provider URL from
jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
to
jndiProps.put(Context.PROVIDER_URL, "remote://localhost:4447");
Also, make sure you have all the necessary JBoss EJB remoting project libraries in your classpath of your client.
I have an java web-project where ejb's (3.1) are configured. When I add (add projects) the ear-project to the local websphere aplication server v8.0 (in eclipse) and start the server I receive the following error:
Error while processing references for EJB-in-WAR: com.ibm.ejs.container.EJBConfigurationException: The bean class "nl.xx.xx.xx.xx.xx.GebruikerFacade" for EJB "xx-xx-ear#xx-xx-web.war#GebruikerFacade" is not found.
Because I couldn't find the problem I deployed the ear-file to the websphere application server via the admin console (new application). The ear-file I created using mvn clean install package.
Then when starting the application from within de admin console the error is not given.
In stead it is reporting that the remote interface of the GebruikerFacade is binded.
What can be the cause of the error when starting the application server where the ear-project is added using add project.
Extra info: Added 20141211
The reason why the bean class cannot be found is the fact that when the ear is deployed to the webspere application server via add project the business interface is empty within the deployed ear.
This is a property in Enterprise Java Bean properties/Bind EJB Business of an Enterprise bean.
The module, bean and uri property are set but the business interface which has to be the full path to the Remote interface class is not.
When de ear is deployed on the application server via new application the business interface contains the Remote interface Class.
Console-output in new answer below.
The first error in the console-output when the ear-project is deployed to the server using "right click server - add/remove project":
[11-12-14 8:14:39:832 CET] 00000030 ComponentData E CWMDF0012E: The bean class nl.company.rvl.facade.GebruikerFacade for EJB
rvl-ear#rvl-web.war#GebruikerFacade is not found.
Somehow the "Starting EJB jar" proces is not initiated at that point.
If the ear-file is added as a new application within the admin console and this application is started that proces is taking place giving the
following output:
[11-12-14 9:01:16:381 CET] 00000047 AbstractEJBRu I WSVR0037I: Starting EJB jar: rvl-web-2015.2.10.00-SNAPSHOT.war
[11-12-14 9:01:16:881 CET] 00000047 EJBContainerI I CNTR0167I: The server is binding the nl.company.rvl.facade.GebruikerFacadeRemote interface of the GebruikerFacade enterprise bean in the rvl-web-2015.2.10.00-SNAPSHOT.war module of the rvl-ear application. The binding location is: ejb/gebruikerFacade-bnd
[11-12-14 9:01:16:897 CET] 00000047 AbstractEJBRu I CNTR0167I: The server is binding the nl.company.rvl.facade.GebruikerFacadeRemote interface of the GebruikerFacade enterprise bean in the rvl-web-2015.2.10.00-SNAPSHOT.war module of the rvl-ear application. The binding location is: java:global/rvl-ear/rvl-web-2015.2.10.00-SNAPSHOT/GegevenspartnerFacade!nl.company.rvl.facade.GebruikerFacadeRemote
[11-12-14 9:01:16:897 CET] 00000047 EJBContainerI I CNTR0167I: The server is binding the nl.company.rvl.facade.GebruikerFacade interface of the GebruikerFacade enterprise bean in the rvl-web-2015.2.10.00-SNAPSHOT.war module of the rvl-ear application. The binding location is: ejblocal:ejb/gebruikerFacade-bnd
[11-12-14 9:01:16:897 CET] 00000047 AbstractEJBRu I CNTR0167I: The server is binding the nl.company.rvl.facade.GebruikerFacade interface of the GebruikerFacade enterprise bean in the rvl-web-2015.2.10.00-SNAPSHOT.war module of the rvl-ear application. The binding location is: java:global/rvl-ear/rvl-web-2015.2.10.00-SNAPSHOT/GebruikerFacade!nl.company.rvl.facade.GebruikerFacade
[11-12-14 9:01:16:912 CET] 00000047 AbstractEJBRu I WSVR0057I: EJB jar started: rvl-web-2015.2.10.00-SNAPSHOT.war
In the tab of Servers, make a full publish of your project. Even if you save it, you have to publish it into your server. It's a bit annoying the fact of having to publish everytime you make a small change, but is the way to deploy the .war into the server.
If that doesn't work, try to delete the server and configure a new one.
Have a nice code!
I have a standalone client that I do not want to deploy on my Glassfish server. With the client I want to post message via the Point to Point communication pattern. I found this great tutorial, which uses annotations I cannot use because I have a standalone client. I found the following solution on stackoverflow:
Context jndiContext;
private ConnectionFactory connectionFactory;
private static Queue queue;
public TweetSender() throws NamingException{
jndiContext = new InitialContext();
connectionFactory = (ConnectionFactory) jndiContext.lookup("JMS/KwetterConnectionFactory");
queue = (Queue) jndiContext.lookup("JMS/KwetterQueue");
}
I also found out that I had to import some libraries from the glassfish directory. So I did:
I get the following error:
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.impl.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.impl.SerialInitContextFactory]
What am I doing wrong?
EDIT
I found a temporary solution for the problem though I feel it's not the right one (I think I might get problems when I want to migrate the project. I removed the libraries which I retrieved from the Glassfish lib folder and added them using the "Absolute path".
A solution can be packing your standalone client application in a jar file, eg: myclient.jar.
And run it as an application client using appclient utility of GlassFish:
applcient -client myclient.jar
The appclient utility can be found here: [glassfish home dir]/glassfish/bin.