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.
Related
I need to create a java ee 6 project which contains:
JSF
EJB
JPA
The Web-things should be compiled to a .war file, the ejb to the ejb-jar and overall into an ear file. The application will be deployed to a Glassfish v3.
I was looking for a maven archetype which I can use and integrate into Eclipse. However I haven't found one. Can you help me?
I consider Andy Gibson's Knappsack Archetype as a good starting point for what you are looking for. It gives you certain levels of working projects from a very basic setup to one filled with examples.
Alternatively, Adam Bien's Weblog is always a good place for finding simple solutions as for example a minimal project setup.
The Java EE MVC Security Archetype is a quickstart for websites that want user self registration and security configuration.
You can try it out on Openshift, though sometimes you have to wait a couple of minutes for openshift to load and start the application.
The archetype includes the following technologies:
Java EE MVC web application for Wildly 9 environment
JSF 2.2 and Bootstrap
JPA 2.1
H2DB (H2 Development Database)
JUnit/Arquillian/Drone/Graphene for testing
Java EE SecuritySupported by JBoss/Wildfly Database Module
Please note: This post is self-promotional.
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 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.
My team is taking over an existing web product that is made up of 3 Maven projects: one for a WAR, one for a couple of EJBs, and one that contains a few JBoss config files and builds an EAR that contains the WAR and EJB-JAR from the other two projects. We use Eclipse Helios and are currently building the projects individually with maven install and copying the resulting EAR to an instance of JBoss AS 6 for testing. While that process works, I am exploring the possibility of somehow streamlining that process; ideally a setup where small changes are automatically published to JBoss. Can anyone recommend a resource for configuring our projects/Eclipse to publish changes to JBoss automatically?
Get yourself "Eclipse IDE for Java EE Developers" and install JBoss Tools. The combination of the two will allow you to configure projects and server instances such that it is easy to deploy and test incremental changes.
Note that for this to work, your projects need to be WTP conformant. If you aren't using WTP already, take a look at the structure and metadata of projects created with Dynamic Web Project, EJB and Enterprise Application Project wizards. Either copy your source into new projects or copy the metadata files and fragments (very carefully).
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.