Maven J2EE archetype in eclipse - java

Whenever I create a maven J2EE archetype in my eclipse IDE, I get the following weird project structure in my work-space where it treats each folder as it own independent folder.
Is the project structure suppose to turn out like that?
Inside the project folder, it looks more like how I expected it to look.

This is normal and is the way that Eclipse copes with nested projects.
There was a time when it could not do this at all and you had to structure your project with the parent pom in a directory adjacent to the others especially for Eclipse.
You will occasionally encounter old projects structured like this for that very reason.

I never tried J2EE archetype but consider J2EE is very old term (now J2EE term was replaced with Java EE, for your information J2EE was used until version 4 and Java EE start from version 5).
In J2EE is common practice to separate each project, you will have many jar for your EJB and war for your Web project and then you will need EAR to bundle all of your module project.
But now with Java EE you just need war for everything. It's more simple rather than using EAR. So, if you want to build Java EE project I suggest you to see this minimalist Java EE maven archetype

Related

Eclipse+Java+Tomcat - How to setup dynamic web project to refer other java projects

I'm creating a web app, for which I have created a dynamic web project in Eclipse. I have also created two java projects, which serve different business purposes. I want my dynamic web project to use these projects as well.
Below are the projects i've created
myapp-core (Java project that has all my core components)
myapp-db (All classes related to DB calls go here)
myappWeb (Dynamic web project which will have only presentation logic)
The point is, I've created all these projects and the classes within them. I have also added myapp-core and myapp-db projects to my myaddWeb's classpath, and am now free of any compilation errors.
However, when I deploy this on Tomcat, I get java.lang.ClassNotFoundException for org.slf4j.LoggerFactory
Now, all three projects have logging, for which I have added slf4j and logback related jars to the build paths of each project (separately).
All my projects are referencing common libraries, like guava, apache poi, etc., which I have associated with each project separately.
Am I missing anything here? Can anyone guide me what is the exact setup that needs to be done for such a framework?
Thanks
Sriram
Please follow below mentioned steps for all 3 projects :
1. Right Click on your Project
2. Go to "Java EE Module Dependencies" option.
3. Select all jars and Apply changes.
If "Java EE Module Dependencies" is not there, try "Web Deployment Assembly" which does the same thing.

why doesn't eclipse Helios web project find dependent project classes at runtime?

My problem is almost exactly the same as the one described here, but that post is a couple years old and eclipse helios (which I am using) doesn't appear to use the J2EE project labels that were discussed in that question.
I have a dynamic web project which references another 'utility' project. The utility project contains services, daos, etc. Compile time is fine. But when I start the web project in tomcat, I get a bunch of org.springframework.beans.factory.CannotLoadBeanClassException. I know this ClassNotFound problem is not related to a single bean or it not being spelled right, because I tried commenting out the original non-critical bean that was not being found and got the same ClassNotFound errors with a bunch of other beans in the utility project.
I'm using Tomcat 6.0.
The utility project has the Java and Utility Module facets. The web project has the facets Dynamic Web Module and Java. The utility project is on the build path of the web project. I've also tried having the utility project checked in the 'Project References' property of the web project, but I don't know what the difference is between 'Project References' and having a project on the build path.
You need to open the web project's Deployment Assembly Property Page (Project->Properties) and indicate the utility project needs to be deployed. And unless you have something requiring you to stay on Helios, update to Indigo. Helios is nearly two years old.

How to use Maven to make a Java EE 6 project

I have used Eclipse to make a EJB project, Dynamic Web project and then I have combined these to in a EAR project. Now I am learning Maven and I wonder how you manage how you do this?
If I use an archetype that generates a javaee6-webapp then after what I understand you get a WAR archive....but that can only use the subset of the JavaEE6 specifiaction. I want to use the whole. So do I need to use one archetype for javaee6-ejb and one for javaee6-webapp, and then combine these in some way?
If this is the case or there are other better approaces I would be happy to learn about it.
Or are the EJBs in a webapp project generated by an archetype compiled and packed as a library and added to the WEB-INF/lib folder? If so, does it have access to the full JavaEE6 API if deployed in a full profile app server?
This article by Adam Bien might be interesting for you.
Also, if I understand it correctly, you can use all the goods of Java EE 6 specification using WAR deployment. You can use timers, remote interfaces, asynchronous invocation etc. in your WAR.
It just depends if you use Full vs Web Profile.
There are few differences between EAR and WAR packaging but, in my opinion, the biggest added value of EAR is the separation of concerns and modules (business logic from web).
To start quickly you can also use a maven archetype like this http://seam-archetype.sourceforge.net/jbosscc-seam-archetype/1.4/javaee.html
You have the right idea.
Create all of your maven projects such as ejb-javaee6, webapp-javaee6, etc.
Then IF you want, create an maven ear-javaee6 project to bundle them all together. This EAR would reference your ejb and webapp.
Updated link:
Eclipse has a plugin for maven that makes your life easier

How to properly set a JavaEE project classpath in Eclipse?

I'm developing a JavaEE system with several applications on a Weblogic AS (10.3.5) using Eclipse indigo with OEPE plugin. I turned my computer off, turned it back on, started the eclipse, and all of a sudden I get class-path errors all over the place (didn't change a thing).
Now let me get this straight:
1. Say I have an application with one EAR project that contains an EJB project and an EJBClient project (both in the deployment assembly).
2. I have written a new regular Java project, and I want to use it in both the EJB and EJBClient projects (it needs to be visible to them).
3. As far as I know, I can simply add this Java project to the EAR project's deployment assembly, and it will be visible to the EJB and EJBClient projects.
4. This has been working for me so far, but now I get class-path errors and I have to add this Java project to the build path of each project.
How should I set the class-path when using JavaEE technology in Eclipse?
After some tweaking I managed to solve the errors:
First I removed the library named 'EAR libraries' from the build path of each of my regular Java projects (I have no clue why Eclipse added them, they shouldn't be there).
Then, for each EAR project, I deleted and re-added every project or jar that was not part of the EAR (regular Java projects, other EJBClient projects, etc).
This solved the issue of not finding classes which aren't included in the EAR, but then I had a 'circular dependency' error.
I narrowed that error down to the projects that caused it - It was a regular Java project that was using an EJBClient project of some application in its build path, and the EJBClient project was also using the Java project in its build path.
Sounds trivial, then why havn't I seen it in the first place? Well, I looked into the EAR project of the application, and it didn't have the java project in the deployment assembly, and the EJBClient didn't have Java project as a 'required project'. So where was it?
The java project was in the 'EAR libraries' library of the EJBClient project, which, according to Eclipse, is automatically generated according to the 'MANIFEST.MF' file (which was empty, btw).
So I simply deleted and re-added the 'EAR libraries' library from the build path of the EJBClient project, and it solved the problem, and everything now works.
In conclusion, it seems like the OEPE plugin for Eclipse have some bugs that needs to be fixed.

How to share code between a Java Web app and a normal Java app

I have smallish personal project consisting of the following Eclipse workspace.
+
+-MyApp // this is just a vanilla Java Application
+-MyWebApp // this Dynamic Java Web Application (Tomcat)
+-MyCommonStuff // these are common classes
// Ex. Database access code & business classes
This is all well and good when I'm running on eclipse coz I can use Eclipse build properties to make the two apps reference the common project.
I am now thinking of how to deploy my app to a linux server and I'm wondering how to do it.
Can eclipse be used to build appropriate targets which can then reference the common stuff when running in a live environment?
Or do I have to learn how to use builders like Ant or Maven.
Thanks
You just need to add the common projects to the build path of the webapp project and to add them as web library dependency.
In the properties of your webapp project, go to Java Build Path > Projects and select the the common projects from your workspace to add them to the build path. Then, in the Java EE Module Dependencies select the projects which needs to be exposed in the WEB-INF/lib. That should be it.
You don't have to learn to use maven, but there are compelling reasons for doing so.
One of which is, maven can set up your Eclipse's build path up for you (And the next guy who has to work on your code, and the next guy...)
One simple 'mvn eclipse:eclipse' and all your build path setup is done!

Categories