What are the recommended JSF dependencies with TomEE1.7.x? - maven

I've been developing a JSF2.0 (I'm not really sure about the JSF version) application on TomEE 1.7.3 (JavaEE6 based).
In my Maven pom.xml, I had too many dependencies which I've copied from many examples, but I reduced them to minimum requirements. Bellow is the "dependencies" part of my pom.xml:
<dependencies>
<!-- JavaEE6 -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>
<!-- /JavaEE6 -->
<!-- OmniFaces for JSF, #Eager, postback same request parameters, etc. -->
<dependency>
<groupId>org.omnifaces</groupId>
<artifactId>omnifaces</artifactId>
<version>1.8.3</version>
</dependency>
<!-- /OmniFaces -->
<!-- glassfish faces (is it called mojarra??) -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.12</version>
<scope>runtime</scope>
</dependency>
<!-- /glassfish faces -->
<!-- some mysql connector -->
<!-- some aws sdks, s3, ec2, etc -->
<!-- some apache commons, StringUtils. etc -->
<!-- some apache velocity -->
</dependencies>
The org.glassfish#javax.faces#2.2.12 dependency can be removed as well,
but it causes html layout problem (with the bootstrap css).
Downgrading it to version 2.0.x, causes the same layout problem.
I know I can fix it, but it takes couple of hours.
What I want to ask is:
Is it good or bad idea to use glassfish faces 2.2.x within TomEE1.7.x? TomEE's description says that it only supports up to JSF 2.0, but so far, it is working almost fine (I have few problems but those do not seem relevant to this version).
Is it better to remove glassfish faces dependency and use the default MyFaces instead?
Is it even better if I choose glassfish server, instead of TomEE, in my case?
BTW, I asked another question yesterday:
JSF2.0 Some facesmessages not sent to redirected page on error handling
and I recognized that I have to clean up my project first, so it might help reduce my problems.
Thank you.

As you already said yourself, TomEE is a Java EE 6 container (and not a barebones JSP/Servlet container like Tomcat). So it has already (nearly) everything from Java EE 6 provided out the box, including JSF 2.0/2.1. Nearly, because it's actually a Java EE web profile container. So you should actually use javaee-web-api artifact ID.
Only this should be sufficient:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
As an Apache product, its bundled JSF implementation is actually MyFaces, not Mojarra.
In case you intend to use JSF 2.2, which is part of Java EE 7, you should be using TomEE 7 instead and change the version in pom.
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
A milestone was released just this month, see the downloads page. Alternatives to TomEE 7 are WildFly 8+ or Payara 4+.
See also:
Our JSF wiki page - also contains JSF installation instructions and Maven coordinates (and many more useful information to get started).

Related

Should I include the dependency spring-boot-starter into my custom spring boot starter?

If I create a custom spring boot starter module, Do I need to include the dependency spring-boot-starter ?
In the spring boot's github :
some starters add the dependency spring-boot-starter to its pom.xml (spring-boot-starter-web, spring-boot-starter-thymeleaf)
some others starters doesn't (spring-boot-starter-log4j2, spring-boot-starter-undertow, spring-boot-starter-tomcat).
Is there a reason to no adding it into the dependencies ?
If your starter depends on spring-boot-starter, any application that depends only on your starter will have all the dependencies that it needs to be a Spring Boot application. Generally speaking, this is how you want a starter to behave.
spring-boot-stater-log4j2, spring-boot-starter-undertow, and spring-boot-starter-tomcat are slightly different as they are not intended to be used on their own. The Spring Boot documentation calls them technical starters. They are intended to be used alongside an existing starter to change the underlying technology that's used. For example, if you are building a web application, you would depend on spring-boot-starter-web. This starter uses Tomcat as the embedded container by default. If you want to swap to Undertow, you'd exclude spring-boot-starter-tomcat and add a dependency on spring-boot-starter-undertow alongside your spring-boot-starter-web dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<!-- Exclude the Tomcat dependency -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Use Undertow instead -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>

Combining a spring REST Service with a JSF Page

ive tried the spring REST tutorial and i also got a simple JSF application (running on glassfish), both projects are maven based and i would like to "combine" them.
Meaning, putting the REST project jar into the JSF project.
Does that make sense?
The JSF page should send a request to the microservice REST project when it starts and display the result.
the REST project uses spring-boot and therefore tomcat.
this pom.xml is supposed to use glassfish instead of tomcat, at least thats what the author tells on a spring blog.
Theres a part in it:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
That says to "exclude" tomcat - which is fine, but how does maven or spring know to use glassfish instead?
Is there maybe a better way to combine these two projects?
I would like to keep the projects seperate because of the dependencys in the pom.xml.
Answer #1 in this question solves the confusion:
Using JSF as view technology of Spring MVC
spring mvc and jsf are rivals.

Which version is compatible with which? Spring and JSTL

I am new to Maven. Now, in my POM, I declared I need Spring 3.0.5.RELEASE. After I started my server and tried to access a page, the server threw a java.lang.ClassNotFoundException: javax.servlet.jsp.jstl.core.Config error.
Now after researching online, I found that I need to include a JSTL dependency like so:
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
I have faced this question multiple times. How do I know which version of jstl is comptabile with Spring 3.0.5.RELEASE
I know this might be a basic question but it will help everyone
You could also try generating a Spring Boot Maven project via http://start.spring.io/ rather then manually setting one up.

spring-boot-starter-tomcat vs spring-boot-starter-web

I'm trying to learn Spring boot and I notice there are two options.
spring-boot-starter-web - which according to the docs gives support for full-stack web development, including Tomcat and web-mvc
spring-boot-starter-tomcat
Since #1 supports Tomcat why would one want to use #2?
What are the differences?
Thanks
Since #1 supports Tomcat why would one want to use #2?
spring-boot-starter-web contains spring-boot-starter-tomcat. spring-boot-starter-tomcat could potentially be used on its own if spring mvc isn't needed (contained in spring-boot-starter-web).
Here is the dependency hierarchy of spring-boot-starter-web:
What are the differences?
spring-boot-starter-web contains spring web dependencies (including spring-boot-starter-tomcat):
spring-boot-starter
jackson
spring-core
spring-mvc
spring-boot-starter-tomcat
spring-boot-starter-tomcat contains everything related to an embdedded tomcat server:
core
el
logging
websocket
What if you want to use spring mvc without the embedded tomcat server?
Just exclude it from the dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
Well a simple answer is that not all web applications are SpringMVC applications. For example if you wish to use JaxRS instead perhaps you have client applications that use RestTemplate and you like how they interact it doesn't mean you can't use spring boot or embedded tomcat
Here is an example application that uses spring-boot-starter-tomcat but not spring-boot-starter-web
Simple Jersey application in spring boot using spring-boot-starter-tomcat
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-jersey
It's also important to remember that tomcat is not the only option for an embedded servlet container in spring boot. It's also easy to get started using jetty. And having spring-boot-starter-tomcat makes it easy to exclude all as one module while if they were all just part of spring-web it would be more work to exclude the tomcat libraries to bring in spring-boot-starter-jersey instead
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
I copied this code from another SO question here.
How to configure Jetty in spring-boot (easily?)

Issue while adding commons validator dependency in pom.xml of Spring 3.1 project

In my project, which is being developed in Spring 3.1, I am trying to perform both client side and server side validations by making use of Apache Commons Validator. But just by adding the below mentioned code is causing some xml exception.
added dependency in pom.xml: -
<dependency>
<groupId>org.springmodules</groupId>
<artifactId>spring-modules-validation</artifactId>
<version>0.8</version>
</dependency>
compile time exception in servlet-context.xml --> Resource Path Location Type Referenced file contains errors (jar:file:/C:/Users/shift/.m2/repository/org/springframework/spring-beans/3.1.0.RELEASE/spring-beans-3.1.0.RELEASE.jar!/org/springframework/beans/factory/xml/spring-beans-3.0.xsd).
I read somewhere that the jars of Spring 3.1 might be colliding with Spring 2.x (which is added in maven repository as [i]spring-modules-validation[/i] brings it with it). After that I added an exclusion as mentioned below: -
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
After which the exception disappeared but inbuilt classes like InternalResourceViewResolver, DataSourceTransactionManager, etc. are not found by the compiler.
Is there something else which I have missed, or any other way apart from Commons Validator to perform client and server side validations in Spring 3.1 ?

Resources