I am following the tutorial at this link: http://programming.manessinger.com/tutorials/an-eclipse-glassfish-java-ee-6-tutorial/, but instead using JBoss instead of GlassFish. I am basically trying to learn Java EE concepts like EJB, Hibernate and JPA.
However, I am stuck on the part for creating an EJB Project in Eclipse. I am supposed to add this to the EAR project, but I cannot find the EJB Project as a selection for new project. I went through the entire list, and it simply is not there. All I see are options for creating EJB Message and Session beans.
Any help is appreciated.
The EJB project must not be created inside the EAR project. Eclipse doesn't have the notiopon of projects inside a project. You create a new top-level EJB project (File - New - EJB - EJB Project), and in its settings, you declare it's part of the other EAR project.
Related
I just finished a tutorial which was done in NetBeans. The tutorial created only 1 project which was a Web Application Project under Java Web category. The tutorial has 1 entity using JPA annotations, 1 Stateless Session EJB using JPA annotations, 1 Servlet calling the EJB, and 1 JSP calling the Servlet. So basically this 1 project has all 3 items: Web & JPA & EJB.
How can I have such a project in Eclipse?
When I work on Eclipse I get confused about how many projects I would need for a web application which uses JPA and EJB.
Should I create 3 projects 1 each for Web & JPA & EJB? OR
Should I create 2 projects 1 each for Web & EJB and include JPA in both?
Just create the "Dynamic Web Project" right away with a minimum version of 3.0.
Since Java EE 6 ("Web Profile") you indeed don't necessarily need to create a separate project for EJBs. You can then use a subset of the EJB API in the WAR, also known as "EJB Lite". You can then easily create a single no-interface EJB class with just a state annotation (Stateless, #Stateful or #Singleton) and you're already there.
You don't need the EJB facet for a "Dynamic Web Project". EJB Lite is basically already covered by the "Dynamic Web Project". There's not much IDE magic (wizards, code generators, etc) needed for EJBs anyway. You only need to make sure that the version is set to a minimum of 3.0 (from Servlet 3.0; part of Java EE 6), and that you set the target runtime to a real Java EE application server (even if it's only "Web Profile"), such as WildFly, TomEE, GlassFish, Liberty, etc and thus not a barebones servlet container like Tomcat or Jetty. This way the EJB annotations will be readily available in the project.
You don't even necessarily need to enable the JPA facet. You'll only miss the JPA-related wizards and code-generators under the project options. But you can just write all JPA-related code all by yourself and still get it to deploy. After all, an IDE is just like notepad, but then with millions of features trying to make you more comfortable while writing code. The project facets basically enable/disable the available project options/wizards/code-generators.
I am new to Java EE. I use Eclipse, jBoss/WildFly and Maven. I have a multi module Maven project:
parent Maven project (pom)
web application (war)
EJB project (jar)
Currently, the EJB jar project is packaged inside the web application and the entire solution is deployed as one war file.
I want to change it: I need to deploy the war and the jar projects to the application server independently (as two independent applications). Then the web project could access the EJBs via their remote interfaces.
The problem:
I can deploy the war project in Eclipse with the Run As > Run On Server context menu, however when I attempt to deploy the jar project in the same way, I get an error message saying that the project cannot be deployed.
How can I deploy my projects independently from Eclipse?
Should I wrap the jar project into an ear project? If so, can I convert my jar project into an ear project, or do I have to keep my jar project and create one more project to wrap it into an ear? (I would no like to introduce one more project).
Look at your packaging for your EJB project. You should have
<packaging>ejb</packaging>
This will allow you to run the EJB project on the server.
For the past years I have been working with Java EE 6 and simpler application structures, where only one ejb and one war project were present.
Now we have a more complex project, where I need to have additional modules:
- JPA package
- client interfaces for an automated tester application
So I have started creating the following projects in eclipse:
Client project
JPA project referencing the client project
EJB project referencing both client and JPA projects
WAR project, that should use services from the EJB project and pojo classes from JPA project
EAR project holding all of this
Packing the project together, I am facing different problems:
"A cycle was detected in the build path of project..." because multiple projects are referencing the client project, and it is packaged to the EAR
Error in annotation processing: {0}. java.lang.NoClassDefFoundError
I was trying to solve these problems. I have come up with solutions, but neither of them works.
Ex 1.: I have simplified the packing to only the JPA + Client + EAR, but this also gives me the cycle detected error. When I turn the error off, I get the 2nd error.
Ex 2.: Tried to simplify build path dependencies, but no luck.
I have also been thinking of merging the EJB + JPA projects, maybe that will work.
But my question is: using Eclipse for development, what is the desired (project and dependency) structure for an EAR app containing client interfaces, ejbs, jpa entities and a standalone tester app using only the client interfaces?
Thanks for your help!
First of all, for your components you won't need an EAR file, a WAR file is sufficient for Java EE 6 applications (see Java EE 6 tutorial on that topic).
Second, my recommendation is not using the project layout created by the eclipse wizard, but use a maven-based archetype (e.g. Knappsack Archetypes), which will give you an easier and standardized layout.
I am learning EJB3 from last few days. I have many questions regarding EJB, application servers and deployment of EJB.
To start with, I have created one simple helloworld stateless session bean but I don't know how to deploy it on server. It has single bean class, bean interface and one servlet client. I have used eclipse to develop this project.
None of the books that I read gives step by step details about how to put EJB on server and how to access those beans.
I have JBoss 6 server and I also have Java EE budle downloaded from sun website. Does this Java EE bundle contains Glassfish server? or do I need to download it separately?
Can anyone please give me step by step details of how to put my bean and its client on server (JBoss or Java EE)?
And why do we need to include bean interface class in EJB client code? I mean either we need to keep client and bean in same package or if we keep them in seperate packages we need to import bean interfaces in client code. Am I right?
With Java EE 6, you can package your Servlet and your EJB in a WAR (either package your EJB in a JAR and put it in WEB-INF/lib or simply put all classes in WEB-INF/classes). And to deploy this WAR, copy it to:
$GLASSFISH_HOME/domains/<domain1>/autodeploy for GlassFish v3*
$JBOSS_HOME/server/default/deploy for JBoss 6
With Java EE 5, you'll have to package your code in a EAR.
And if you want to deploy your application from Eclipse (using the Eclipse WTP), you'll have to install the appropriate server adapter. For Eclipse Galileo and GlassFish (there is currently no adapter for JBoss 6 AFAIK), right-click the server view, select New > Server, click on Download additional server adapters and select the GlassFish adapter. Finish to define your new GlassFish v3 Java EE 6 server and deploy your application on it (right-click on your application then Run As > Run on Server). For Eclipse Helios and GlassFish, you can follow the link given by #VonC (manual install) or check this answer (install via the Update Site).
You need to add GlassFish to your Eclipse installation (see GlassFish plugin for Eclipse).
The full process is described here (with the latest Eclipse Helios 3.6M6)
You should export as EJB into your jboss<version>\server/default/deploy folder and then add the build path for it on the servlet's web project. You can "Run on Server" and choose an application server just like you would in any project, no need to export the WAR although if you do that, you're gonna have to re-export your WAR every time you modify your code
AFAIK there's no Eclipse plugin for JBoss 6 but Eclipse provides one for 5.1
I have created a domain model using spring-roo, which makes heavy use of Spring and AspectJ. My model is deploying nicely as a OSGi bundle, and from the Spring STS (eclipse-based) IDE, I can call the entity classes, etc.
I need to access these domain classes from a Eclipse RCP/RAP application, and this project I keep in the normal Eclipse IDE for RCP/RAP development (i.e. it has all the PDE tools). I also added the STS and AspectJ plugins.
I added my domain bundle to the target platform, and made my Eclipse RAP app dependent on it. When I run the RAP application, I can see that my domain bundle is deployed in OSGi (i.e. it is ACTIVE). I also see that it exists in the PDE editor when I added the dependency.
However, when I try to import and use any of the domain classes, I get nothing. I can't even see the domain packages from my Java file editor.
I have tried to add a AspectJ and Spring nature to my RAP project, but still nothing.
Also, when running the Eclipse RAP application, everything deploys fine, except the RAP application, which throws the following exception:
Mar 2, 2010 2:44:58 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from URL [bundleentry://168.fwk1096264275/META-INF/spring/applicationContext.xml]
Exception in thread "SpringOsgiExtenderThread-2" java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:171)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.close(DependencyWaiterApplicationContextExecutor.java:345)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.fail(DependencyWaiterApplicationContextExecutor.java:401)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.stageOne(DependencyWaiterApplicationContextExecutor.java:287)
at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor.refresh(DependencyWaiterApplicationContextExecutor.java:175)
at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.refresh(AbstractDelegatedExecutionApplicationContext.java:175)
at org.springframework.osgi.extender.internal.activator.ContextLoaderListener$2.run(ContextLoaderListener.java:718)
at java.lang.Thread.run(Thread.java:637)
Any help would be highly appreciated.
Maybe you should try not to build Roo project to jar, but reference this project from your RCP project.