How to use/connect a database, EJB with TomCat [duplicate] - eclipse

This question already has answers here:
How to deploy EJB based application on Tomcat
(4 answers)
Closed 6 years ago.
I created a simple project JAVA EE with GlassFish to implement a simple REST API. During this project, I created a jdbc pool connection (with the glassfish interface) with postgresql and use EJB and Jersey to store my data in the database. There is no problem but now I would like to do the same with Tomcat to deploy on bluemix but I don't really understand...
I created a web project dynamic with tomcat 8.5 on Eclipse, created a simple jsp file to test and deploy it on bluemix, that works ! But now I would like to connect a database to my tomcat application like before, I googled it but I don't understand if it is possible and how to do this...
Anybody can help me please ?
Thank in advance :)

You cannot deploy EJBs in Tomcat because it only implements the servlet and JSP specifications from Java EE.

You can use TomEE which is a full EE stack based on Tomcat but includes OpenEJB, OpenJpa etc. In their site you can find how to deploy TomEE as a war in a plain Tomcat in case that you want to use your existing Tomcat installation. Check the links below
TomEE Home
TomEE deployement as war
TomEE Datasource configuration

Related

I can't import Java EE annotations in eclipse,such as #EJB and #Stateless, instead eclipse recommends me to create them [duplicate]

This question already has answers here:
How to deploy EJB based application on Tomcat
(4 answers)
Which technologies does Tomcat support?
(5 answers)
What exactly is Java EE?
(6 answers)
Closed 3 years ago.
I can't import Java EE annotations in eclipse,such as #EJB and #Stateless, instead eclipse recommends me to create them.
Eclipse compiler error
Per se, you can't use the EJB specification with a plain Tomcat server. Tomcat is an open-source implementation of the Java Servlet, JavaServer Pages, Java Expression Language and WebSocket specification.
The EJB (Enterprise JavaBeans) specification is part of Java EE (now called Jakarta EE) and requires a Java EE application server: e.g. TomEE, Payara, Glassfish, Open Liberty, WildFly, etc. Tomcat is not a Java EE application server as it is just a servlet-container.
If you still want to run your application in a Tomcat-like environment, have a look at the TomEE application server: How to deploy EJB based application on Tomcat.

Tomcat restful web service database (JPA) with Netbeans does not work

I have been able to create Restful web services with JAX-RS for Tomcat. Using the Netbeans Restful web service from patterns wizard.
But I am not able to create Restfull web servicer from database with Netbeans wizard.
It miss some libraries. I add openJPA and Java EE web api 6 (over the added by the wizard). But it continues not working.
I added javaEE-TomEE 8.0 but did not work, either!
Does anybody know what have I to add to Tomcat to get JPA-Database Restful service working?
Moving to GlassFish is not an answer valid... I want to keep on Tomcat (adding the minimal)
I have made some advances...
With EclipseLink(JPA 2.0) I was able to connect MySQL in a desktop application...
Then I switched to Apache OpenJPA and I was no able to get an EntityManagerFactory...
So it seems I choose a library incomplete...
I imagine, in Tomcat, I have to choose other library than OpenJPA.

Maven archetype for java ee 6 and eclipse

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.

Netbeans wizard for JSF pages doesn't recognize TomEE 1.6 to have Web Profile support

I am creating a Java EE 6 application with the help of Netbeans 8.0 and TomEE 1.6. I have successfully added the server to netbeans and even generated some entity classes. I am currenlty trying to generate some JSF pages using the Netbeans wizard. However I get the following message
Cannot be generated for Java EE 6 sources wihtout server with complete Java EE 6 Web profile support (at least EJB Lite support).
I am using TomEE 1.6.0.2 plus
The problem is Netbeans 8 has a bug in which it fails to find the tomee-common-[version].jar in the [TomEE]/lib directory.
The solution is to simply rename the jar file to an older version.
For example, you have [TomEE]/lib/tomee-common-1.6.0.2.jar or [TomEE]/lib/tomee-common-1.7.1.jar. Rename these files to [TomEE]/lib/tomee-common-1.6.0.jar
This should sort you out :)
you can use tomcatEE 1.7.2 with a few small changes
you find here:
http://zarnisfd.blogspot.com/
I think this also applies to TomEE 1.6
According to the following sites:
http://forums.netbeans.org/ntopic48005.html
https://netbeans.org/bugzilla/show_bug.cgi?id=210835
Tomcat does not support EJB's therefor you would need to use an enterprise server that at least supports EJB Lite. One such server would be GlassFish

How to deploy EJB on server?

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