How do I add EJB capabilities to an Eclipse dynamic web project? - java

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!

Related

How to debug issues with deploying to tomcat from eclipse?

I've inherited a Spring web app. It's a gradle web app project that I've imported into Eclipse. We're using Eclipse 4.7.3, Tomcat 7.0.47 and JDK 1.8.0.151.
The problem is that when I deploy the project to Tomcat from Eclipse, some of the dependency jars are not copied to the project lib directory. When TC tries to start the web app, there are ClassNotFoundException errors.
I'm new to Java web apps, so what I need is some tips for verifying my project import/build/deploy.
Here's what I've done so far:
Install Tomcat 7.0.47 (don't start it after install) Install Eclipse
4.7.3 JavaEE flavor (which comes with Buildship Gradle integration 2.0 installed)
Import my project as a Gradle project (File -> Import -> Gradle ->
Existing Gradle Project). I point at the project root, choose the
web project for deployment, and use the default settings.
Add a server to the project (from Server view click Add -> choose
Tomcat 7.0 -> point to TC root)
Right click the web target and select Run As -> Run As Server and
choose the TC 7 server I added.
At this point the project builds and deploys. The console shows the TC log. TC starts but the shows an error when it attempts to start the web app (for example):
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
I could copy jars but it's my impression Gradle should be grabbing the dependency jars during deployment. I can verify that some are copied, but others are missing. How can I debug this issue?
Here's part of my build.gradle file
buildscript {
repositories {
maven {
url projectDownloadUrl
}
}
dependencies {
classpath lib_license_gradle_plugin
}
}
The web app is deployed to ...eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core\tmp0. The lib directory here contains some of the deployed dependency jars. The gradle.properties file contains a list of dependencies, for example
lib_apache_tomee=org.apache.openejb:apache-tomee:1.7.1
This is apparently not the place to ask and answer Gradle/Tomcat questions. I figured out the issue shortly after posting, and not wanting to disappoint the 40 people who've come here for help since then, thought I should finally answer my own question.
First, I was on the right track on how to debug deployment of a gradle/maven app in Eclipse. After it deploys you can check which jars are in the deployment directory. Eclipse deploys locally to a place similar to c:\users\\eclipse-workspace.metadata.plugins\org.eclipse.wst.server.core.
Second, the immediate problem I was having was due to using Tomcat instead of Tomcat EE. The answer to this was right in the question:
lib_apache_tomee=org.apache.openejb:apache-tomee:1.7.1
Tomee is Tomcat + Java Enterprise Edition, which includes some extra logging and other jars, the ones I was missing.

Glassfish 3.1.2 doesn't contain javax.persistence jar

I'm trying to work with Eclipse Mars 2 and Glassfish 3.1.2, but when I use EclipseLink 2.1 to create the entitites from tables, javax.persistence is not found in the buildpath.
Is this the normal behaviour?
I created the Oracle db connection with eclipse
I installed JEE 6 SDK with Glassfish 3
I started the glassfish server and configured the data source and connection pool.
I created a JPA project and created the entities from the db connection tables.
Something I find curious is that the jee.jar that is inside glassfish/lib only contains a pom.xml
Isn't Glassfish supposed to contain all the jars needed to develop with the jee standard?
Is my project meant to be a Maven project in order to automatically download this jars? Could I fix this by configuring my project as a Maven project?
Isn't Glassfish supposed to contain all the jars needed to develop with the jee standard?
Yes, and it contains all the jars needed but in an indirect way. Even though it is a single jar file with only one file, namely, MANIFEST.MF and a directory maven which contains the pom file you mentioned.
But if you open the MANIFEST.MF file you'll see that it is pointing to a lot of jar files in the Class-Path: entry which you need to be able develop JavaEE applications.
So everything is there and you only need to add this file into your dependency to be able to compile your JavaEE (Servlets, JSF, EJB, JPA, ...) classes and deploy on the server. But this (javaee.jar) must be a compile time dependency, i.e., should not be packaged with your application as the jars are already contained in the server.
Is my project meant to be a Maven project in order to automatically download this jars?
No. Your project can be but should not be a maven project. Let us say, for example, you have an Eclipse project where you want to develop an EJB application. Just right click on the project
go to the Properties -> Build Path page and change to Libraries tab
click on Add External Jars ...
go to the Glassfish lib directory and add the javaee.jar, and you are done.
now you can use all the JavaEE annotations and classes.

Myeclipse deployment issue for web module dependent java jars

I am using WAS 8, in the deployment folder, I just need to get the dependent java jar projects under the x.war-> web-inf-> lib, .
This can be done easily in RAD using j2ee module dependencies-> web library tab. How to do this in Myeclipse?
I disabled the deployment assembly mapping and tried many options in Myeclipse but seems like all have same result..
Eclipse indigo some how deploys the dependent java jar projects under the x.war-> web-inf-> lib.
Please help.
Dependent projects are deployed in the manner specified in the project properties (or the workspace preferences). Select the project, right click then go to Properties->MyEclipse->Web and select the Deployment tab. You can specify here how dependent projects are deployed and how exported jars from dependent projects are deployed, among other things.

Netbeans does not package class library jar to ear file when deploying Enterprise Application

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.

How to start/stop/redeploy maven web app using cargo start inside Eclipse

I have Maven2 war project built, I'm using the cargo start plugin, and it works great for deploying the web app. To run the maven command, I use a .bat file in my workspace, and I have en external run config to run the the bat file. I can't seem to stop the server from the Eclipse console, or re-deploy.
Does anyone have any advice on how quickly start/stop/re-deploy to Tomcat locally while developing.
Did you try JavaEE tools and m2eclipse? As far as I can see it should work well in most common situations. What m2eclipse does for you is to exactly map the maven configuration to an eclipse projects with the necessary facets set. Also, if the Dynamic Web Application facet is set for your project, you will be able to deploy it to a Tomcat server that you set up in the Server view of JavaEE tools. This configuration allows hot redeploy.
More information on JavaEE tools:
http://eclipse.org/home/categories/index.php?category=enterprise
There is a full Eclipse distribution with the EE tools available on their download site:
http://www.eclipse.org/downloads/
m2eclipse is freely available from Sonatype:
http://m2eclipse.sonatype.org/
At work we use the mentioned software as well. Additionally we use the JBoss tools that provide a feature called Project Archives that let you individually build your web application archive (ear/war/...).
To get startet you should perhaps start a fresh workspace and import the existing maven project (via the import existing maven project wizard). If everything went fine you can set up your tomcat in the server view. Maybe switch to the Java EE perspective. Right click on the newly added server and select Add to add the dynamic web project you just imported. If it doesn't show up in the list try to update the project configuration via the project's maven context menu.
Well, you could use cargo:redeploy to Undeploy and deploy again a deployable (that's a shortcut to cargo:deployer-redeploy). But I personally don't use Cargo this way, I use it mostly for integration testing (i.e. during the build) and use Eclipse WTP during development (this works whether you're using the maven eclipse plugin or m2eclipse).

Categories