Can we have two different jsf version in same EAR - jsf

I am using JSF1.1 for my project. The workspace includes EAR, Dynamic web module and Java projects.
Now i want to have one more Dynamic web module with JSF2.1. it is possible?
and Is this a good practice to have two different versions of JSF in the same EAR.

Yes, it is possible. Each web module within the EAR can have it's own JSF version as long as the dependencies are packaged within each WAR. You will want to ensure a parent-last classloading approach as well.

Related

Purpose of jsf-api.jar and jsf-impl.jar [duplicate]

I have started studying JSF and I would like to know what is the JAR to include within our classpath to start using JSF. Is it jsf-api or jsf-impl? Or we have to include both? And if it is both then why they are not merged?
I'll assume that you're not using a real Java EE application server like WildFly, TomEE, Payara, etc, but a barebones JSP/Servlet container like Tomcat which indeed doesn't ship with JSF out the box and you thus had to manually install it. Otherwise, all this fuss with JARs is unnecessary.
Is it jsf-api or jsf-impl? Or we have to include both?
You need both. The jsf-api.jar contains the API, which exist of almost only abstract classes and interfaces. It are the javax.faces.* types which you are importing and using in your code. The jsf-impl.jar contains the implementation, which exist of the real hard working code. The implementation is internally loaded via factories in API. It are the com.sun.faces.* classes which you are not supposed to import and use directly in your code. If you do, then you wouldn't be able to switch to a different JSF implementation, such as MyFaces.
And if it is both then why they are not merged?
There exist a merged JAR, the javax.faces.jar. You can pick this one instead of the two loose JARs.
See also:
Our JSF wiki page
JSF implementations and component libraries
Difference between Mojarra and MyFaces
In simplest terms, what is a factory?
How to properly install and configure JSF libraries via Maven?

clarification about EAR project structure and maven

it's been a while now and still there are several things that are not clear to me.
Lets start with the basics: what I need to do.
I'm building a web application that manipulate some data, do some computation and give the user an output. There will be also a standalone version, with some simplifications.
So I thought this is the right time to use EAR packaging structure and EJB. I've created with netbeans a basic j2ee ear project with maven support:
All of them have their own pom.xml.
For what i understand, the first one is just a wrapper, the second one is the "real" project that doesn't contain source code, but encapsulate the other two.
In the web project I put all of the web stuff plus jsf backing beans. In the ejb one I was planning to put my data model with all the required annotations, and that comprehend also JPA and JAXB. There should be also some additional classes: a facade class, or session bean, that allow me basic data manipulation with the database, and some classes that contain my business logic strictly related to my data.
Question: is it correct to put all this things into an EJB project? Why not a simple project that the web module depends on?
Moving forward: the web project. First things is, netbeans doesn't put the EJB project dependency into its pom. So I can't see my beans from here. Is that correct or I have to manually add the SRA-ejb into the pom as a dependency?
Secondly, using some netbeans macro, like the ones that generate session beans from entity, or CRUD jsf pages from entities, it looks like he try to generate and put session beans here, in the web project. I think they fits better in the ejb one. What do you think?
One last question: in my stand alone application I was planning to use just the ejb module. But I think I have to carry with me an EJB container, am I right?
it's been a while now and still there are several things that are not
clear to me.
I know that feeling for sure :D
All of them have their own pom.xml. For what i understand, the first
one is just a wrapper, the second one is the "real" project that
doesn't contain source code, but encapsulate the other two.
Correct, it doesn't contain any sourcecode but can contain XML files for declarations and a common lib folder which contains shared libraries of the web and EJB projects.
In the web project I put all of the web stuff plus jsf backing beans.
In the ejb one I was planning to put my data model with all the
required annotations, and that comprehend also JPA and JAXB. There
should be also some additional classes: a facade class, or session
bean, that allow me basic data manipulation with the database, and
some classes that contain my business logic strictly related to my
data.
Question: is it correct to put all this things into an EJB project?
Why not a simple project that the web module depends on?
I don't know what you mean with a "simple project", if you mean just a plain JAR file with classes: an EJB module is nearly the same plus a deployment descriptor which invokes scanning of the annotations.
Moving forward: the web project. First things is, netbeans doesn't put
the EJB project dependency into its pom. So I can't see my beans from
here. Is that correct or I have to manually add the SRA-ejb into the
pom as a dependency?
Yes, in your case you need this dependency. You web project depends on your "service".
Secondly, using some netbeans macro, like the ones that generate
session beans from entity, or CRUD jsf pages from entities, it looks
like he try to generate and put session beans here, in the web
project. I think they fits better in the ejb one. What do you think?
I think it makes more sense to put them in the EJB project because they come from the javax.ejb.* package and belong to the EJB layer. You can put them in the we project, but then you don't really need an EAR and you can use a normal web project like you did before.
One last question: in my stand alone application I was planning to use
just the ejb module. But I think I have to carry with me an EJB
container, am I right?
No, you don't need an EJB container. You can lookup your EJBs via JNDI but you'll need an EJB with a remote interface and a copy of this interface in your standalone client.
You can find some tutorials about that here:
EJB invocations from a remote client using JNDI (JBoss)
How do I access a Remote EJB component from a stand-alone java client? (GlassFish)
GlassFish Project - Simple EJB 3.0 Stateless Session Bean Example
See also:
Maven2: Best practice for Enterprise Project (EAR file)
EAR package structure
Maven structure and Java EE applications

how to add ejb 2.1 into java ee 6

Is there a way to use ejb 2.x project as a jar into Java EE 6 project?
I am using Rational Application Developer as IDE. I can add ejb 2.x project as a Java EE Utility jar. And manually add a reference to application.xml after than when i deployed to server the ejb jar automatically started by server.
I want to create a new project compatible with Java EE 6 (without application.xml, without web.xml, using annotation). However I have to use ejb 2.x project as a jar. My question is that How I can accomplish this task.
Thank you in advance for your answers
You can use EJB 2.1 and 3.x in parallel, we also have that in an application which is quite some years old and still not completely migrated.
For the old parts, you still need the same setup with all the deployment descriptors, as #bkail pointed out.
But if possible, I would strongly recommend not to mix up things if you have the chance to create a modern JavaEE 6 based application. Better try to interface with the old parts which are still needed and keep it as a separate application and use old EJBs or introduce a temporary interface between old and new application until it is migrated.

Can a jetty 5 custom classloader exclude specific jar files in a war?

I've got a large code base that currently runs on JSF 1.1 on embedded Jetty 5.1.14 server (Servlet 2.4). I've managed to get a JSF 2.0.9 app running on this version of Jetty even though I'd expected to require servlet 2.5, and I add EL 2.1.2 & the JSF jar to WEB-INF/lib. This works on a jetty config that excludes JSF 1.1.
The production environment consists of a large number of war and jar files on a single server instance.
JSF 1.1 is currently in the server ext/lib folder, and in a single war file I'd like to include the JSF 2 jar in the WEB-INF/lib. This is not possible as the server JSF version will load first and cause classpath pollution.
However would it be possible to eliminate the JSF 1.1 jar loading in just the one war file with a custom classloader? The documentation seems to cater for the case of adding paths to the classpath rather than excluding things. I wasn't clear whether it's loaded in the context of the server as a whole or just the war.
A little more information: Another potential solution is to simply upgrade to Jetty 8 and JSF 2.1+. Apart from convincing management that this is a good idea, we use an old WebMethods7 version, this has a graphical layout tool that produces some XML that is translated by a Component Application Framework, which uses the JSF APIs to generate content (so only a very few JSPs). This would simply be a case of seeing if it works, and if not having a total rethink because of the need to keep supporting this WebMethods "code".
The main goal here is to ultimately run up to date software although not necessarily in one step.
Jetty5 is incredibly old at this point and I would recommend working on the update to jetty8, or waiting a couple of months and making the jump to jetty9 which we are currently releasing milestones for. Changes in the newer jvm's since then alone are enough reason to update your jetty container.
I don't know if this approach was supported in jetty5 or not, but in jetty6 we have ability on the webapp context to modify the classes that are exposed to the context via system and server classes. If those hooks exists then you should be able to tweak that specific context to not expose the classes in the jar in ext/lib.

Dynamic Web Project with Seam Faces

I tried to start a new dynamic Web Project with Seam-Faces(Eclipse). I created a new JSF-Facility and addeed all the jar-Files from the official Seam-Faces homepage. When i try to create a dynamic web project eclipse says that the following File ist not found:
javax.faces.FactoryFinder
What i am doing wrong ? Is ist possible to use Seam-Faces without the Seam-Framework ?
There is not a Seam Framework anymore. Seam 3 is a bunch of reusable CDI extensions that you could use. The best way to start with Seam3 modules is to use maven for library management. More info about how to configure seam-faces dependencies can be found here.
For the exception you're facing make sure there are no jsf jars in WEB-INF\lib in case you're using a Java EE server like JBoss AS or Glassfish. For more info look here.

Resources