I have a system consist of ear project and some related EJB and JSF projects. I was using glassfish3.1.2, the EJB projects were exported into EJB jar and added to the deployment assembly of the EAR project. Everything was ok until i tried to upgrade the application server into glassfish4. when i run the EAR project in glassfish 4 an error indicate that cannot create singleton session bean pop up from eclipse for every bean i have in the ejb jars . but if i add the EJB project instead of ejb jar to the deployment assembly of the EAR project the EAR will deploy normally.
so is there a problem of adding ejb .jar files to the deployment assembly of Ear projects in glassfish 4. note that my ear project run well in glassfish 3.1.2 but i need glassfish4 in order to use jpa 2.1 .
Related
I have an application which I am deploying on GlassFish. It has an EJB-tier with (JPA) Entites and EJBs to get access and write to the database and it has 3 (independent) web apps. Everything is built with Maven.
ServerApplication
|
+-ServerApplication-ear
+-ServerApplication-ejb
|
+-GrumpyCat (war)
+-HummingBird (war)
+-Koala (war)
All three war projects depend on the ejb project. When compiling/building the ear, it copies the war files to the ear project and then I can deploy the ear file on GlassFish.
This works fine, all 4 modules (the ejb, and the 3 war) get deployed without problems and I can access the 3 war projects like:
myServer.com/GrumpyCat
myServer.com/HummingBird
myServer.com/Koala
My problem is, that I can't deploy a single war project on its own. For example when I change something in the koala project, I would like to be able to build only the koala.war and deploy it on the server, without having to upload and deploy the complete ear file.
But when deploying, GlassFish tells me either :
there is already a project deployed on Koala (true, it was deployed together with the ear)
or (when I change the build-version) it doesn't "know" the ejbs and I get a number of ClassNotFound Exceptions.
Is there a way to deploy the modules of the application one by one?
Your second approach is the way to go if you really want to deploy them individually. However, you are seeing a ClassNotFound exception because the WARs are individual projects and as such don't have access to the EAR's class path.
To make that work, you have to add the public API of your application to your WAR's classpath. The public API consists of at least the EJB's remote interfaces of the EJBS that you would like to access from the WAR and any DTOs used in your API.
The easiest way is to create a separate package (such as com.example.api) and let a build tools such as ant or Maven bundle that api package together with your EJBs and your WARs, or you create a myapp-api.jar and include it in the respective class-paths.
Then you can remove the WARs from the EAR and deploy them as separate projects.
I have web application which has a servlet and an ejb. The ejb is annotated #Local. In my servlet I used #Inject to inject the ejb. It woekd fine.
Then I created an ear with an ejb module and a web module. I deployed the ear and I got exceptions. Then I learned that I cannot use #Inject. So I used #Resource(lookup = "jndiname") and then it worked.
Then I created an independent web application and used the #Resource annotation to inject the ejb in the ear into a servlet. The war failed to load. So I thought to place the ejb jar inside the lib directory of the app server so that all applications in the app server can use them. I am using jboss eap 6.0. I placed the jar under jbosshome/modules/com/ejb/beginner/main/. It did not work. I got exceptions. Then I placed the ejb jar in jbosshome/modules/com/ejb/beginner/api/main/. Still no luck.
I want to learn how to create #Local beans so that applications in the app server can use. Is it possible?
I figured it out. If I want to use modules from another ear in other deployments I have to declare the dependencies in the MANIFEST.MF file like this
Dependencies: deployments.appname.ear.appname.jar
The following links help me figure it out
https://community.jboss.org/message/604576
https://docs.jboss.org/author/display/AS71/Class+Loading+in+AS7
I am developing a simple application with EJB 3.0 using OpenEJB for deployment and Eclipse as an IDE.
I created the project as a 'dynamic web application' in Eclipse. When I tried creating the first stateless session bean, I realized that the #Remote annotation could not be resolved.
What is the right way to fix this problem ?
Delete the project and create a new 'enterprise application project' (this seems to be pretty heavy weight, so I am not sure I want to go in this direction) ?
Delete the project and create an EJB project (this does not seem to be right because I believe such a project will only let me bundle the EJB part of the application) ?
Add some libraries to my existing project (is there a library pack for EJB 3.x) ?
Add a facet to my existing project (I tried to see if I can add a facet, but I cannot see an EJB facet within the context of this project) ?
Thanks for helping.
Update:
I found the answer.
TomEE's installation has a directory containing all the jar files needed to compile and run EJB's 'apache-tomee-webprofile-1.0.0-beta-2/webapps/openejb/lib'
I created a User Library in Eclipse containing all the jars from the lib folder described above and added it to the build path.
The EJB interfaces now compile properly.
Create an new Enterprise Application Project (EAP)
Create an new EJB Project and add it to the EAP
Add to the EAP your existent WEB project
Now you can create EJBs in the EJB project and call them from the WEB project.
And you can deploy or debug your EAP on an Application Server (like JBoss) that supports Enterprise Application Projects.
The EAP is deployed as a unique file with .ear extension.
If you use Tomcat for example you cannot deploy the ear packages.
Here a page with a description about creating ear with Eclipse.
A simple way to add eclipse library support for TomEE or TomEE+ is the following:
Create a Tomcat 7 server in eclipse. (Change the name to reflect it's TomEE)
Point it to your tomEE install directory.
In your project goto: Properties -> Java Build Path -> Libraries.
Press "Add library".
Select "Server runtime", and press next.
Select the TomEE server profile you just created and click finish.
Click OK.
The tomEE libraries have been added to your eclipse project.
I'm using maven and get it work with the following simple steps:
Open Project -> Properties -> Deployment Assembly
Click 'Add...'
Choose 'Java Build Path Entries'
Choose 'Maven Dependencies'
That's it!
I build a java enteprise application in netbeans 7.1 which consists of two EJB modules. One of the EJB modules has a reference to another class library project, lets call it MyUtilities. When i deploy the application, its ear file does not contain MyUtilities.jar file. When i add to the other EJB module libraries MyUtilites project, although its not necessary, the ear file is built correctly and under its lib folder, MyUtilities.jar exists.
Anyone with the same issue?
Thanks
Did you check the setting of the checkbox "Package required JARs in EJB jar" in the Build | Packaing dialog?
This is a new option which I found after upgrading a NetBeans 6.5.1 EJBModule project which had also no longer the references JARs bundled in the EJB jar.
I have an Enterprise project with an EJB module and a Web module.
I am trying to deploy these modules separately on Glassfish server (local) on my machine.
If I right click and deploy these projects from Netbeans, they get deployed and run good.
But if I try to deploy them from the Glassfish AminConsole,
the ejb module gets deployed successfully without any problem.
but the web module deployment fails.
The ClassDefinitionNotFoundException is thrown for all the EJBs in the ejb module.
But the ejb module jar is in the war file (in the WEB-INF/lib folder).
I am using Netbeans7.0 and Glassfish 3.1.
What's the right way to handle this problem?
Thank you.
It was actually the Netbeans that did not include the ejb-jar inside my war when build the application as ear. And the fix was to build them (jar and war) individually.