java EE project encountered NoClassDefFoundError - servlets

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.

Related

Deploying Spring MVC from SBT

I'm having trouble deploying my Spring MVC Webapp with the xsbt-web-plugin. When i'm using container:start everything works just fine, but when i'm trying to run the packaged .war file inside a tomcat instance the webapp isn't loaded. It is just starting a plain tomcat instance.
I had an error in my path that slipped through. I've overlooked this for days. Sorry.

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.

Looking up EJBs on JBoss 7

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.

existing Spring MVC project into RAD + WAS

I have a question about RAD & WAS Spring MVC development. So that we have a project in SVN that was created by me in STS (eclipse), but some of our team members can't retrieve & run this Spring MVC project on their RAD (ibm tool) IDE on WebSphere Application Server 7. It requires to create an EAR to run it on WAS, but in this case there're 2 projects in project explorer; EAR project & the normal one... the normal is almost an empty project, but everything from SVN is kept under EAR project. But they can't simply access index.jsp file from WebContent folder when they try to run EAR project on WAS, it says "Failed to find resource /index.jsp".
Any suggestions?
When work Spring projects over RAD we do the following approach:
We create a Dynamic Web project that contains all our Java Classes, JSP's, Spring files and some libraries that are inherent to the project. This project can be exported to a WAR and executed in containers like Apache Tomcat with no problem.
The we create an Enterprise Application Project that contains a Web Module reference to our Spring project, so we can run our application over IBM WAS as an EAR (although, WAS can work with WAR's too). This project only contains some configurations files and upper-level libraries.
Your Spring project should be imported in RAD's workspace as a Dynamic Web Project, and the EAR project must be created by the guys that uses RAD for development (an uploaded to SVN if you need it). If your "normal" -i.e Dynamic Web Project- is empty, you should check that the uploaded files are OK and the checkout process was normal.
Can you access the other resources besides index.jsp?
You got to narrow down things?
What is the context root for your web application? Is it "/"?
Post in additional information before folks can assist you
HTH
Manglu

Deploying remote EJB and Web application

I have successfully deployed an EJB 3 module and a JSF WEB app which calls the EJB module's beans using netbeans IDE locally. Now when I try to deploy this in staging environment, i get the following error:
root cause
javax.servlet.ServletException: com.sun.enterprise.InjectionException: Exception attempting to inject Unresolved Ejb-Ref com.store.managedbeans.CustomerManagedBean/customerService#jndi: com.store.service.CustomerRemote#null#com.store.service.CustomerRemote#Session#null into class com.store.managedbeans.CustomerManagedBean
root cause
javax.naming.NameNotFoundException: com.store.service.CustomerRemote#com.store.service.CustomerRemote not found
I have deployed the EJB module and Web application in glassfish v2 (in the staging environment).The jar of the EJB Module is inside WEB-INF/lib folder of web application. It looks like the web app cannot find the EJB module. The classes are annotated with #Remote. And I am calling interfaces and not the bean by using #EJB. And of course, this worked find when I deployed it under Netbeans.
From the comments:
The EJB Module was referencing a JMS Queue Connection Factory. The resource hadn't been created in the staging glassfish server. Although the EJB module was allowed to be deployed, the JNDI Log from the console reveals that none of the EJBs were bound to any names because of a problem in deploying the module.

Resources