Looking up EJBs on JBoss 7 - servlets

I developed very simple Hello World EJB (3.x) which I deployed on JBoss 7.1.
I can successfully call this EJB from within a standalone application.
When trying to call it from a servlet I find the EJB.
I have package the EJB in a JAR and the servlet in a WAR.
It seems that this is the reason for the servlet not able to access the EJB.
Might that be true?
Once I package both, the EJB JAR and the servlet WAR into the same EAR it works.
As that the supposed behavior or can I make this work even without using EARs?
Maybe someone can shed some light into this.
I am pretty sure that I did not need to do these things on earlier JBoss version.

According to Java EE spec, deployed applications should be isolated, unless they are in the same EAR archive. So the behaviour you see is correct.
This is different from JBoss 4 or JBoss 5 default configuration, which did not have archives isolation (that was essentially a bad thing, but often quite convinient...).
EAR packaging is sort of annoying, but can be done automatically by IDE or Maven.
In addition, in case of Java EE v. 6, you might pack EJB components with local interface into WAR archive, which simplifies deployment.

Related

java EE project encountered NoClassDefFoundError

I am working on a Java EE project with
jdk 1.8
wildfly 10.1.0 final
intellij idea 2016.3
The project has a web application module and an ejb module, and the structure is as follows:
And the two modules have already been deployed successfully
But when I tried to call the session bean, the ejb project went wrong and threw an error
Caused by: java.lang.NoClassDefFoundError: org/json/JSONArray
I use JSON in class DAOHelperImpl in the ejb module, and I've already add the dependency. I tried to put the jar in various packages such as /ejb/lib or /web/web/lib, but none of them are working.
What's wrong?
Move the jars libraries from /web/web/lib into
/web/web/WEB-INF/lib
By Convention the general folder for auto included jars is:
web-project-name/webContent/WEB-INF/lib
Read more here: https://blogs.oracle.com/alexismp/entry/web_inf_lib_jar_meta
I am not aware how IntelliJ handles Java EE projects.
In Eclipse the EAR and WAR are in separate projects and can be assigned to each other.
I think this error is raised due to my bad understanding of how this web application together with the ejb module works: I deploy the web module and the ejb module separately, and it seems that wildfly can only link to the lib of the web module.
The solution is to deploy only the web application to the server and add the ejb module to the web application.

example stand alone application using EJB-MDB, eclipse, jetty server?

how to develop one example application using EJB-MDB, eclipse, jetty server?
I have created two java class. and i have .jar file, where I have to deploy .jar file in jetty server? after that what I have to do?
Your requirement for EJB-MDB seems to demand a full blown server like Jboss, Glassfish, TomEE and others. If you need jetty with the equivalent of EJB MDB functionality probably you should look at Spring-Boot. On the other hand if you need EJB/MDB compatibility you should probably choose an Application server and each of these comes with a plethora of examples and quickstarts, but each one comes with it's own Servlet Container respectively Undertow, Tomcat, Grizzly, but not Jetty.

Spring web app deploys on Gradle's embedded Jetty but not in standalone Jetty

I have built a small web app using Gradle. Things seemed to be going well using the embedded Jetty server, but not so well when I tried to copy the WAR file to a standalone server.
I used the gradle war plugin to assemble the war.
Running gradle jettyRunWar works fine.
Copying the war to the Jetty webapps folder and running Jetty fails with this exception:
java.lang.IllegalStateException: No such servlet servlet_name
But this very same servlet is found and used without issue in the embedded Jetty server.
The same issue happens if I manually copy the exploded war to the webapps directory.
The Spring web and Spring mvc libs are copied and present in the WEB-INF/libs directory, so it isn't an issue of not finding Spring (or is it?)
I'm using Jetty 9.1, and my web.xml file is configured for Servlets v3.
I'm also using Spring 3.2. The web app I'm writing is a RESTful service, using the #Controller annotations to route requests.
This should be as simple as copying the war over, but it seems not to be. At a bit of a loss at what to do here, any thoughts?
Thanks!
Sometimes the answer is staring you in the face...after posting I realized that I had my servlet-mapping before my servlet declaration. While this did not present an issue for the Gradle Jetty (not sure why), it made Jetty unhappy. Not sure why I changed the order to begin with...
In short, Jetty seemed to not find the servlet because it had not been declared yet.

Deploy Spring MVC in WSO2 Application Server

I am trying to deploy my Spring MVC application on WSO2 Application Server by going to Main > Manage > Applications > Add > Web Applications and upload my Spring MVC's WAR file. The upload completed successfully, but I still can't run the web app itself. The error message just basically complaining it doesn't have org.springframework.
The same WAR file can be run on Apache Tomcat with no problem at all. All I did is dropping the same WAR file to \webapps, and it works.
Is there a special setting that needs to be configured to get Spring MVC run on WSO2 Application Server? I would assume WSO2 Application is also using Apache Tomcat, so why it won't run by just uploading the WAR file?
Thanks!
What is your WSO2 AS version ? please make sure to use latest AS 5.1.0 version. We have tested large number of Spring (including SpringMVC) based applications on AS 5.1.0, basically if something working on Tomcat it should be work on WSO2 AS too. If you still have issues on AS 5.1.0 please let me know.
I solved this issue by:
Upgrading WSO2 AS to latest version (5.1.0) as mentioned by Sagara Gunathunga. For some reasons, previous WSO2 AS doesn't take my JSTL templating (something like $ {blabla}). Only in 5.1.0 did the issue resolved. I start to wonder what this WSO2 is doing with its half-baked product.
Modify Maven POM file, specifically slf4j-api dependency. WSO2 has its own slf4j-api library and I have to set the scope of slf4j-api in my app to "provided" before deploying to WSO2. This solve the issue with unable to load all JavaScript files.
Downside for this is you will need the scope of slf4j-api to be "compiled" when you run this locally under regular Tomcat. Setting it to "provided" will not work under Tomcat. But in WSO2, the scope will need to be "provided" to run. So, there is manual work to change before deploying the application.
I did try to match the slf4j-api version to match what WSO2 and set the scope to "compile", but it still won't work. WSO2, for some bad reasons, can't use my app's compiled slf4j-api.
yes there is a separate workaround to deploy a spring service to wso2 appserver. Please follow [1] for instructions.
[1]. http://docs.wso2.org/wiki/display/AS510/Spring+Services
Thank you,
Dharshana
#stack247,
Well I'm from WSO2 and it's nice to hear that your JSTL issue is solved by now. But I completely disagree with " I start to wonder what this WSO2 is doing with its half-baked product" statement. You may know that spec like Servelt , JSP and JSTL having different versions and update it's version with time. Previous version of application server does not supported for latest JSP 2.0 and JSTL 1.2 specs hence you can't use application which depends on JSP 2.0 or JSTL 1.2 that was a known limitation but can't consider it as half-baked product due to that. This is very common nature with any software product and that's why we are actively developing, fixing issues, upgrading dependencies and frequently releasing new versions, also we are responding to community issues like this.
With Latest AS 5.1.0 release we officially support for Servelt 3.0, JSP 2.0 and JSTL 1.2 and any dependent applications too. When it come to logging case most of the application server having their own logging mechanisms and some cases it's required remove logging dependencies from applications.

How to package the project to war in play2?

In play1, we can package the project to a war, then put it in a tomcat:
play war
But how to do the same in play2? play war doesn't work, it reports war is not a valid task.
as pointed out by #Freewind, officialy, it's not supported, this is because they need the Servlet 3.1 specifications to support all the nice websocket and other advanced features that play2 provides.
However, if you do not use that, there is a plugin on github to provide play war and be able to deploy on some cloud servers, etc:
https://github.com/dlecan/play2-war-plugin/
It's not still supported, support won't be released until Play 2.1 (as per current plan)
PS: I know your comment says so, but it's better to have it as an answer for people finding this page.
WAR Plugin for Play framework 2.0 bring this feature.
This project is a module for Play framework 2 to package your apps into standard WAR packages. It can be used with Servlet 3.0 and 2.5 containers (Tomcat 6/7, Jetty 7/8/9, JBoss 5/6/7, ...)
offered by the official site, if you just want to publish your website, there may be some alternative ways to achieve the goal.
Creating a standalone version of your application
Or, you can use with lighttpd or nginx, here is the configuration doc:
Set-up a front-end HTTP server
If you plan to host several applications in the same server or load balance several instances of your application for scalability or fault tolerance, you can use a front-end HTTP server.

Resources