How to deploy EJB 3.0 application in Wildfly 8 application server - java

I am migrating EJB 3.0 application from jboss AS 6 to wildfly AS 8.
Is it possible to deploy EJB 3.0 application to wildfly as ease in wildfly? After updating the EJB spec as per wildfly EJB modules in pom.xml, I am getting compilation error that below symbols are not found as the related APIs are not available in wildfly.
org.jboss.ejb3.annotation.LocalBinding;
org.jboss.ejb3.annotation.Depends;
org.jboss.ejb3.annotation.Management;
org.jboss.ejb3.annotation.Service;
The above annotations are found in jboss-ejb3-ext-api.jar and it is a part of jBoss 6 AS.
javax.annotation.security.PermitAll
The above annotations are found in jboss-annotations-api_1.1_spec.jar and it is a part of jBoss 6 AS.
From the documentation, I understood that wildfly support EJB3.2 and EJB3.2 does not support #LocalBinding / #RemoteBinding.So how will I do the same in wildfly using standalone.xml / ejb-jar.xml / any other configuration.
I tried following the blog: JBoss: Binding values into JNDI in JBoss EAP 6 similar to JNDIBindingServiceMgr
but could not link where I tried to lookup EJB bean based on jndi name but did not work.
Please help. Many Thanks.

Annotate you bean interface with #Remote and or #Local.
Annotate you bean implementation with #Stateless.
Build the project with maven to generate EJB JAR and the client JAR (exclude your server implementation if it is used outside of your EAR).
<build>
<plugins>
<!-- maven-ejb-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ejb-plugin</artifactId>
<configuration>
<clientExcludes>
<clientExclude>**/ejb/*</clientExclude>
</clientExcludes>
</configuration>
</plugin>
</plugins>
</build>
Package the EJB in a EAR. (This is optional, but I deploy the web module as one .ear file).
To be able to know the JNDI Name of you EJB, Wildfly follow the standard naming convention.
`java:global///
For example ear has the name my-ear, ejb name my-ejbs and the bean interface a.b.c.MyBeanRemote and the implementation a.b.c.ejb.MyBean : Remote JNDI path will be java:global/my-ear/my-ejbs/MyBean or more verbose java:global/my-ear/my-ejbs/MyBean!a.b.c.MyBeanRemote.
To generate this structure of deployment I use the following configuration in my ear project:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<configuration>
<version>7</version>
<applicationId>my-ear</applicationId>
<applicationName>my-ear</applicationName>
<defaultLibBundleDir>/lib</defaultLibBundleDir>
<jboss>
<version>5</version>
<unauthenticated-principal>guest</unauthenticated-principal>
<security-domain>ABC</security-domain>
</jboss>
<modules>
<webModule>
<groupId>a.b.c.my-group</groupId>
<artifactId>my-web-app</artifactId>
<uri>my-web-app.war</uri>
<contextRoot>/my-web-app</contextRoot>
</webModule>
<ejbModule>
<groupId>a.b.c.my-group</groupId>
<artifactId>my-ejbs</artifactId>
<uri>my-ejbs.jar</uri>
</ejbModule>
</modules>
</configuration>
</plugin>
</plugins>
</build>
<applicationName>my-ear</applicationName> will set the right name used by my application EAR (without the version).
<uri>my-ejbs.jar</uri> will remove the version of my ejb module, so it is not reflected in the JNDI path.
Hints: The JNDI name of your bean is printed in the log file when the EAR is deployed.
If you want to access the bean from outside the application server, you must use the JNDI path that begin with java:jboss/exported

Related

How to deploy a module in an Alfresco deployed in Tomcat

I have successfully deployed alfresco community 4.2.f in a Tomcat 7.0.59 with a database MySQL5.6 and jdk1.8.0_141
No problems thus far, now, I got a module developed by our company which I need to be deployed in alfresco. This module invokes a WS which will send a PDF to some place.
I got this module in a jar compiled with jdk1.8.0_141
I tried to put it inside the alfresco.war before deployment in Tomcat in WEB-INF/lib but when I do that and deploy with startup.bat from Tomcat it pops in the console
instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/codehaus/xfire/XFireRuntimeException
I understand this exception is caused by putting the jar inside the war.
I was told that the jar was compiled also in jdk8.
Also, tell you that if instead of this jar I put inside the alfresco.war in WEB-INF/classes a properties file to get our database in deployment it works fine.
The problem is when I try to deploy the module.
I saw there are quite tutorials pointing to do something like:
java -jar bin/alfresco-mmt.jar
I can't do that because this is done installing alfresco with its wizard I assume. I did it deploying alfresco in a fresh tomcat installation.
Does anyone know how to deploy our module with the way we deployed alfresco? Thank you.
You have two ways to install your amp :
The first traditional one :
This is the one installed with the apply amp procédure (alfresco-mmt).
To me, this is not true that it is not compatible with your installation. You can easily find the bin folder (containing the alfresco-mmt.jar file) here in the alfresco packaging : https://download.alfresco.com/release/community/4.2.f-build-00012/alfresco-community-4.2.f.zip
When you have it, you can follow the documentation : http://docs.alfresco.com/4.2/tasks/amp-install.html
And apply your amp for example following this way :
java -jar alfresco-mmt.jar install <AMPFileLocation> <WARFileLocation>
The second one :
You can recreate the war with the alfresco sdk and include in the build the module you created.
If you follow this documentation : http://docs.alfresco.com/4.2/tasks/dev-extensions-maven-sdk-tutorials-all-in-one-archetype.html
the war produced in the target folder of the repo part will contain your module, since the pom of this module will contains a dependency to the amp module :
...
<dependencies>
<dependency>
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco</artifactId>
<type>war</type>
</dependency>
<!-- Demonstrating the dependency on the repo AMP developed in the 'amp'
module -->
<dependency>
<groupId>x.y.z</groupId>
<artifactId>my-amp</artifactId>
<version>${my-amp.version}</version>
<type>amp</type>
</dependency>
</dependencies>
...
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<!-- Here is can control the order of overlay of your (WAR, AMP, etc.)
dependencies | NOTE: At least one WAR dependency must be uncompressed first
| NOTE: In order to have a dependency effectively added to the WAR you need
to | explicitly mention it in the overlay section. | NOTE: First-win resource
strategy is used by the WAR plugin -->
<overlays>
<!-- Current project customizations -->
<overlay />
<!-- The Alfresco WAR -->
<overlay>
<groupId>${alfresco.groupId}</groupId>
<artifactId>alfresco</artifactId>
<type>war</type>
<!-- To allow inclusion of META-INF -->
<excludes />
</overlay>
<!-- Add / order your AMPs here -
<overlay>
<groupId>x.y.z</groupId>
<artifactId>my-amp</artifactId>
<type>amp</type>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>

Share Classloader between multiple in Jetty Maven Plugin

I'm try to configure maven jetty plugin to start my war application, but it has some complications like as follow descriptions:
1º - It has dependencies with a ejb jar;
2º - It has dependencies with war (tag jstl:import context="nscl");
3º - The classloader between wars must be shareded.
So, I need some help to resolve the third problem. Looks my jetty plugin configuration in pom.xml:
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.1.v20170120</version>
<configuration>
<useProvidedScope>true</useProvidedScope>
<useTestScope>true</useTestScope>
<webApp>
<contextPath>/nscl/cntr</contextPath>
</webApp>
<contextHandlers>
<contextHandler implementation="org.eclipse.jetty.maven.plugin.JettyWebAppContext">
<war>${contexto.war.path}</war>
<contextPath>/nscl</contextPath>
</contextHandler>
</contextHandlers>
<systemProperties>
<systemProperty>
<name>spring.profiles.active</name>
<value>test</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
The problem is, when jetty is starting the second war (context-path = nscl), I receive problems saying the classes used to start first war not exist to second, a sample is classes of spring framework.
Thanks !!!!
You are hitting Standard Servlet Spec behavior.
Your WebApp's cannot share the same ClassLoader.
That is a fundamental part of being a Servlet Spec WebApp, the ClassLoader isolation.
Attempting to force it will just create mysterious problems with the ClassLoader hierarchy (InvalidClassChange errors, memory leaks, GC failures, etc)
Perhaps you can detail why you think you need this.
As there's likely already a standard way to accomplish it using the features of the Servlet spec (and not fighting it).

weblogic 12c deployment failure

I'm migrating from Weblogic 11g to 12c, during the deployment process it fails and shows the following error:
Caused by: weblogic.application.naming.ReferenceResolutionException: [J2EE:160199]Error resolving ejb-ref "ejb/BizRuleFacade" from module "BizAgi-ejb.jar" of application "BizAgi-ear-Weblogic". The ejb-ref does not have an ejb-link and the JNDI name of the target bean has not been specified. Attempts to automatically link the ejb-ref to its target bean failed because multiple EJBs in the application were found to implement the "BizAgi.bpm.rules.entities.BizRuleFacade" interface, including BizAgi-war.war/BizRuleFacadeBean, BizAgi-ejb.jar/BizRuleFacadeBean. Specify a qualified ejb-link for this ejb-ref to indicate which EJB is the target of this ejb-ref.
My web.xml file looks like this:
<ejb-local-ref>
<ejb-ref-name>ejb/BAScopeLogFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>BizAgi.PAL.historylog.entities.BAScopeLogFacade</local>
<ejb-link>BizAgi-ejb.jar#BAScopeLogFacadeBean</ejb-link>
</ejb-local-ref>
The BizAgi-ejb.jar is a module inside the ear (BizAgi-ear-Weblogic.ear).
How can i properly deploy my application?
Thank you so much everybody, I've finally found the solution, it is to simply delete/remove the META-INF/MANIFEST.MF file from the .war file. That way the EJBs aren't double referenced.
1.Add below dependency in Ear Pom.xml
<dependency>
<groupId>com.example</groupId>
<artifactId>ejbModel</artifactId>
<version>1.0-SNAPSHOT</version>
<type>ejb</type>
</dependency>
2.In Ear pom.xml in modules add ejb module
<modules>
<ejbModule>
<groupId>com.example</groupId>
<artifactId>ejbModel</artifactId>
<bundleFileName>ejbModel-1.0-SNAPSHOT.jar</bundleFileName>
</ejbModule>
.......
</modules>
3.Change scope of ejbmodel dependency to provided in application pom.xml
<dependency>
<groupId>com.example</groupId>
<artifactId>ejbModel</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
4.add persistence.xml of ejbmodel application to resource folder
Make sure that the same EJBs are not loaded multiple times in your deployment. You can check this by using the weblogic console (AdminServer) and checking the EJBs of the deployment (by clicking the little "+" sign next to the deployment that is failing int the deployments overview).
In my case I had to fix the maven dependencies (by setting one dependency of one project to "provided") so that it did not load the same EJB twice.
ERROR:
weblogic.management.DeploymentException: weblogic.application.naming.ReferenceResolutionException: [J2EE:160199]Error resolving ejb-ref "com.xxx.xxx.xxx.xxx.xxx.xxx.XXXX/xxxRemote" from module
"XXX-X.X.X.war" of application "XXX-X.X.X". The ejb-ref does not have an ejb-link and the JNDI name of the target Bean has not been specified.
SOLUTION:
1 SOLUTION: pom.xml (Web Project)
<dependencies>
<dependency>
<groupId>co.xx.cxxxx</groupId>
<artifactId>xxxxx-ejb</artifactId>
<version>1.0</version>
<type>ejb</type>
<scope>provided</scope>
</dependency>
<dependencies>
2 SOLUTION: Delete xxxxx-ejb.jar
xxxx.ear > xxxx.war > WEB-INF > lib > xxx-ejb.jar [remove]
3 Conclusion:
This is because there is a double reference to the ejb.jar, therefore the best way to control this is by saying in pom (web) that the is of type EJB, in order to take the (ejb.jar ) from the parent (EAR, where the ejb module is added).
I hope to be of help

War context root change is not reflected in WebSphere made through Maven and deployed using MyEclipse

I am using WebSphere 7 and trying to deploy war from MyEclipse (Server > WebSphere 7 > right click > Add Deployment).
I am using below maven war plug-in:
<groupId>com.xxx.my.app</groupId>
<artifactId>my-app</artifactId>
<packaging>war</packaging>
<name>my-app</name>
<build>
<finalName>my-app-context-root</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
</plugin>
</plugins>
</build>
To change context root of my war I tried below options:
First option:
<properties>
<m2eclipse.wtp.contextRoot>my-app-context-root</m2eclipse.wtp.contextRoot>
</properties>
Second Option:
<finalName>my-app-context-root</finalName>
But no Luck so for with these options. Whenever I deploy my application/war from MyEclipse and check context root in WebSphere server, WebSphere still shows the context root as 'my-app' (which is mentioned in name tag) not 'my-app-context-root'.
One approach could be changing the war file [ my-app tag] to context root name. This way it will deploy the application with desired context root name.
deploy your war file or application in myeclipse tomcat server and right click on the project folder, select properties and go to web option from the MyEclipse menu. there you can change the context-root of an application. The below link may helpful to you.
Change application context-root in myeclipse
For the direct deployment by MyEclipse, MyEclipse generates some special configuration files like the ibm-web-bnd.xml. These files contain the root path. If you want to specify the context root you have to either get those to work WAS specific files to work or pack your war file into a ear file and deploy the ear.

Attempting to setup/use mysql datasource with glassfish (using Cargo and Maven). How to deploy mysql connector?

Good evening!
Using Cargo via Maven, I've configured my pom.xml to create an instance of glassfish and then deploy my project to it, before running integration tests. I'm most of the way there, in that I've got my code deployed, I've setup a datasource and a JNDI resource for it, but when I attempt to actually use the resource, I get the following exception:
Wrong class name or classpath for Datasource Object
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
On a regular installation of glassfish, I can easily install the connector, but the installation of glassfish in this case is automated and a new instance is created each time I run the tests.
Is there any way that I can provide the mysql connector, either on a classpath that glassfish can read, or by installing it in the new instance of glassfish that's created each build?
Thanks!
Scouring the docs a little more, I found out that I can do this by providing maven dependencies in the container configuration, like so:
<configuration>
<container>
<containerId>glassfish3x</containerId>
<artifactInstaller>
<groupId>org.glassfish.main.distributions</groupId>
<artifactId>glassfish</artifactId>
<version>${glassfish.version}</version>
</artifactInstaller>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
</container>
<configuration>
<properties>
<cargo.datasource.datasource.mysql>
cargo.datasource.jndi=jdbc/MysqlPool|
cargo.datasource.driver=com.mysql.jdbc.Driver|
cargo.datasource.url=jdbc:mysql://localhost/databasename|
cargo.datasource.transactionsupport=LOCAL_TRANSACTION|
cargo.datasource.username=username|
cargo.datasource.password=password
</cargo.datasource.datasource.mysql>
</properties>
</configuration>
</configuration>
Take note of the mysql dependency. It needs to reference a dependency already defined in my project (which, for my project has a scope of "provided"). This works as expected. :)

Categories

Resources