nullPointerException when deploy webLogic 12c application - deployment

when i deploy my first web app on webLogic i get this error:
weblogic.application.ModuleException: java.lang.NullPointerException
at weblogic.application.internal.ExtensibleModuleWrapper.prepare(ExtensibleModuleWrapper.java:114)
at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:100)
at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:172)
at weblogic.application.internal.flow.ModuleStateDriver$1.next(ModuleStateDriver.java:167)
at weblogic.application.utils.StateMachineDriver$ParallelChange.run(StateMachineDriver.java:80)
Truncated. see log file for complete stacktrace
Caused By: java.lang.NullPointerException
at weblogic.servlet.internal.WebAnnotationProcessor.processMultipartConfigAnnotation(WebAnnotationProcessor.java:286)
at weblogic.servlet.internal.AnnotationProcessingManager.processAnnotationForClasses(AnnotationProcessingManager.java:169)
at weblogic.servlet.internal.AnnotationProcessingManager.processAnnotations(AnnotationProcessingManager.java:114)
at weblogic.servlet.internal.AnnotationProcessingManager.processAnnotationsOutsideWebFragment(AnnotationProcessingManager.java:141)
at weblogic.servlet.internal.AnnotationProcessingManager.processAnnotations(AnnotationProcessingManager.java:102)
Truncated. see log file for complete stacktrace

I had this problem and resolved it by removing JSF 2.2 Mojarra 2.2.0 from the application libraries. It only needs to be in the classpath.
In Eclipse, edit properties for the project, go to Project Facets-->Java Server Faces and uncheck "Include libraries with this application" and Apply change.

I deploy from Eclipse (OEPE), same problem here without JSF. Here is what solved my problem:
Quit Eclipse
Delete the workspace's .metadata folder
Launch Eclipse

The same solution worked on NetBeans8. From projects, go to your war project, right click over Libraries > JSF2.2 and click Remove. Rebuild the project and deploy. Remember to deploy as shared library the JSF on WLS.

This seems to be a duplicate of Maven generated ear file fails during deploying weblogic server. Some details about the solution can be found in this post https://roundwheeltech.wordpress.com/2016/06/15/deploying-a-jsf-2-2-to-weblogic-12-1-3/.
Because WebLogic 12.1.3 ships with JSF 2.1, the required JSF jars have to be bundles within the WAR file (specified as dependencies in pom.xml). WebLogic must also be instructed to use the libraries packaged in the WAR file instead of the ones that are provided by the container.

I had the exact same NPE. It was started by an instantiation of an factory that went wrong. I had to remote debug in to find this. An exception in the initialisation of the factory is swallowed and we don't get the real exception.
In my case the problem was antlr.Token and antlr.CommonToken not arriving from the same source. This gave me an ClassCastException. I solved it by moving all libraries from the ear to war to get more control over them.

Edit the file web.xml and put:
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>

Related

How to exclude Eclipse plugin library jars from Tomcat classpath

I have a Spring MVC project that uses Maven imported into Eclipse Kepler SR1 JEE and deployed to Tomcat 7 within Eclipse. Everything was fine until I recently added elasticsearch as a dependency to the Maven pom file and now when I start Tomcat I get an exception
java.lang.ClassCastException: org.springframework.web.servlet.DispatcherServlet cannot be cast to javax.servlet.Servlet
Launching the server in verbose mode, I see that its because the servlet API is now being loaded from 2 places:
the Tomcat installation folder where it normally comes from
Loaded javax.servlet.Servlet from file:/C:/ProgramFiles/apache-tomcat-7.0.33/lib/servlet-api.jar
but also from one of the Eclipse plugins (Groovy) I have installed
Loaded javax.servlet.Servlet from file:/C:/ProgramFiles/eclipse/plugins/org.codehaus.groovy_1.8.6.xx-20130703-1600-e43-RELEASE/lib/servlet-api-2.4.jar
I can't figure out why this is happening. If I rename the servlet jar file in the plugin's lib folder (i.e. change the extension from .jar to something else so that its not recognized), Tomcat starts up without an exception but that's a hack and so I'd like to know what the cause is and if I'm missing some configuration to exclude plugin library jars from the Tomcat classpath.
Thanks.

Spring context:component-scan fails to find components in another Eclipse project dependency referenced in POM

I am working on a GWT web application split across two Eclipse Projects (myclient & myservice).
The myclient project references the myservice project via a dependency in the POM.
<dependency>
<groupId>com.myproject</groupId>
<artifactId>myservices</artifactId>
<version>1.0.0</version>
</dependency>
The myclient project has a WAR directory src/main/webapp. The output folder for the myclient project is src/main/webapp/WEB-INF/classes.
The myclient project has a Spring descriptor application-context.xml with the following
<context:component-scan base-package="com.myproject.myclient, com.myproject.myservices"/>
and the web.xml
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/application-context.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
...
</web-app>
I have several files in the myservices project annotated as spring #Component, #Service, #Configuration but these are not picked up by the component scan when I run the GWT application in Eclipse. As a test I experimented with placing an #Component in the myclient project and this was successfully created.
I believe the following log entry during application startup indicates the source of the problem
org.springframework.core.io.support.PathMatchingResourcePatternResolver - Resolved location pattern [classpath*:com/myproject/myservices/**/*.class] to resources []
the location pattern for the myclient project resolves to all the resources on the classpath but for myservices no resources are found.
I experimented with building the myservices project JAR and placing this JAR into the src/main/webapp/WEB-INF/lib folder of the myclient project. When I do this the component scanning works. However for development I don't want to have to build and copy a JAR everytime I make changes to the myservices project. I imagine that the component scanning should work on a project referenced through the POM without having to the build that project but after much experimenting I have been unable to get this working.
Be sure that in the deployment assembly (right click your web project and select "deployment assembly" of your myclient project it is configured to deploy the jar that is outputted by the myservices project. If you are using maven, the m2e, m2e-wtp project configurators should do this deployment assembly setup automatically.
Once you have deployment assembly settings properly configured, now when you deploy a project to your server using the Eclispe server adapter publish mechanism, everything should get deployed and the myservices jar would get placed in the right spot for your myclient project.
But make sure you the latest version of m2e-wtp installed. This way your configuration in your pom.xml and deployment assembly will get correctly configured.
Try splitting your application-context.xml into 2 separate files:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:service-context.xml,classpath:client-context.xml</param-value>
</context-param>
myservices/src/main/resources/service-context.xml:
<context:component-scan base-package="com.myproject.myservices"/>
myclient/src/main/resources/client-context.xml:
<context:component-scan base-package="com.myproject.myclient"/>
Try this :
<context:component-scan base-package="com.myproject"/>
Please check the following things:
Is your serviceproject present "only" as jar or is the whole project available via workspace resolution. This can be checked via maven-context-menue (Disable/Enable Workspaceresolution)
The layout of the webapp under src/main/webapp is okay. BUT do i get you right that all classes are copied there? If so, you should make sure everything is under target directory. So please check whether a maven call "clean package" generates a webappstructure under the target folder and all required libs (e.g. myservice) exist under target\$your-webarchivename\WEB-INF\lib
Check that packaging in myservice pom.xml is set to jar (you probably have this, right?)
it's obvious that your service jar is not included in your client project's build path. this is the only root cause.
Make sure 3 points:
you have run mvn clean install under your service project which has correct pom.xml.
you have run mvn eclipse:eclipse under your client project. this will pull out all your dependency project.
check your client eclipse project's build path dialog. is there your service jar in the list? Make sure this
You better once look this tutorial
http://fusesource.com/docs/framework/2.2/deploy_guide/CXFServletDeploySpring.html

Eclipse Maven Web Project Servlet Mappings

I have set up my maven project using the m2e plugin in eclipse indigo, and transformed it to an eclipse dynamic web project using mvn eclipse:eclipse -Dwtpversion=1.5. I have managed to get the project up and running in tomcat7, except for my servlets, for which I cannot create the servlet mappings.
I have tried modifying the web.xml file but it throws a ClassNotFoundException. Directory Structure and web.xml :
(ROOT)
+src
+main
+resources
+DrawInitialMap.java
+webapp
(WebContent here)
<web-app>
<servlet>
<servlet-name>DrawInitialMap</servlet-name>
<servlet-class>(groupId).(artifactId).src.main.resources.DrawInitialMap</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DrawInitialMap</servlet-name>
<url-pattern>/drawInitialMap.do</url-pattern>
</servlet-mapping>
(...)
</web-app>
While the #WebServlet annotation also fails to map the servlet :
#WebServlet(name="drawInitialMap", description="visualizes ttrp on html5 canvas", urlPatterns={"/drawInitialMap.do"})
Thank you in advance, and notify if you need any more of the code.
PS : Keep in mind that the servlet worked perfectly in Dynamic Web Project mode, without Maven
There are several issues.
You should stop using eclipse:eclipse. Instead, install WTP integration for M2E from Eclipse Marketplace
In Maven project, your DrawInitialMap should be in /src/main/classes folder. So, it will be compiled as per default Maven project conventions
The servlet-class element in web.xml requires full class name, i.e. no things like (groupId).(artifactId).src.main.resources.

How to deploy a library with Java EE 6 / Glassfish 3.x

I have got an EAR with two plain libraries. One of them being scala-library. If I deploy the EAR with Netbeans it works as expected. While this is OK for development the final product should be deployable via the command line. For this I use:
asadmin --user … deploy --upload ./target/…-ear.ear
which fails with:
org.glassfish.api.admin.CommandException: remote failure: Error occurred during deployment: Exception while deploying the app […-ear] : C:\Work\Workspa
ces\…\Glassfish\…\applications\scala-library-2.8.0.jar. Please see server.log for more details.
Befehl deploy fehlgeschlagen.
Searching the net I found out that handling libraries have become more strict with Java EE 6 / Glassfish 3.x and that it is not enough to add them to the lib folder inside the ear any more. Only the author neglected to mention what is needed now.
I found new <module><java> entries for the META-INF\application.xml — but that did not help either:
<module>
<java>scala-library-2.8.0.jar</java>
</module>
So the question: Does anybody know what you have to do to add libraries to an EAR file for Java EE 6 / Glassfish 3.x?
PS: I use Maven to build - if that makes any difference.
Well it seems I found the solution myself (again). After adding a library-directory entry to the end of the META-INF\application.xml the deployment runs thou:
<library-directory>lib</library-directory>
</application>
The strange thing is that lib the default for library-directory. So I guess it must be a bug in Glassfish itself not handling the default correctly. If you use Maven make sure to use bundleDir in your pom.xml so that the libs are place in the right place:
<jarModule>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<bundleDir>lib</bundleDir>
</jarModule>

Why Jetty has not found CometServerServlet from Rocket package?

I have a common GWT application that is using (trying to) Rocket-Framework to implement a CometServerServlet.
After I have registered my servlet in web.xml and my app.gwt.xml, like this:
App.gwt.xml:
<servlet path="/server" class="myapp.server.MyCometServlet"/>
web.xml
<servlet>
<servlet-name>myCometServlet</servlet-name>
<servlet-class>myapp.server.MyCometServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myCometServlet</servlet-name>
<url-pattern>/myapp/server</url-pattern>
</servlet-mapping>
Jetty apparently doesn't find the CometServerServlet from which my MyCometServlet extends:
WARNING: Error starting handlers
java.lang.NoClassDefFoundError:
rocket/remoting/server/comet/CometServerServlet
Caused by:
java.lang.ClassNotFoundException:
rocket.remoting.server.comet.CometServerServlet
That is strange, because I've added the Rocket jar to my project.
Could someone explain why this error happened?
I could understand if I "registered" the servlet in a wrong way or something, but at what point Jetty (or who?) looks for the CometServerServlet and fails at finding it?
Adding the jar to your project (e.g. in some IDE) will remove compilation errors, because the jar can be found at compile time.
But Jetty needs the library at runtime, and the usual way to provide it, is by putting it in the WEB-INF/lib folder of your project.
Of course, make sure to redeploy the app afterwards (e.g. if you're using Dev Mode, click refresh in the "Development Mode" view).