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

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.

Related

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

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

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

Is there any way to have a fully portable Java EE 6 deployment?

Is it possible to make a Java EE 6 application deployable on any Java EE 6 Container (like JBoss or GlassFish, etc) without using their modules / libraries?
If for example I want Hibernate or Weld then add these in my Maven pom.
In other words, is there any "vanilla" container or can JBoss or GlassFish be made "vanilla"?
I´m sorry... but to be honest I don´t understand your question.
Java EE applications are in most cases deployable an all containers - as long as they are not using packages or configurations which are specific to the chosen container.
Even if you add libraries in your POM and the applications are packaged as WAR or EAR this should work.
Weld is not needed because the API is part of Java EE 6. If you want to use JPA you also don´t need hibernate.

Problems deploying Java EE 6 application from netbeans to JBoss 6

I have a Java EE 6 application developed on Netbeans 7 and try to deploy it on a JBoss 6 instance. The application makes use of JAX-RS but I am not using any Jersey specific aspects, just standard JAX-RS features.
Deployments as a WAR fails because of some missing Jersey classes and deployment as an EAR fails due to org.jboss.deployers.spi.DeploymentException: Only one JAX-RS Application Class allowed
Any idea what the cause of this might be?
What I do not want to do is disable RESTEasy in JBoss, I'd rather produce an application that runs on any Java EE 6 container without tweaks.
Glassfish silently adds Jersey JAX-RS packages to the build. If you uncheck the 'Package' checkbox in the project's lib configuration, the application is packaged without Jersey.
This makes sense, because after all, the target of the deployment might be a non-Java EE 6 container such as Tomcat.

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