I have many CXF WS to deploy (13 wars) and sometimes one of them give me this error:
java.lang.NoClassDefFoundError: org/apache/cxf/transport/servlet/BaseUrlHelper
org.apache.cxf.transport.servlet.ServletController.getBaseURL(ServletController.java:74)
org.apache.cxf.transport.servlet.ServletController.updateDestination(ServletController.java:83)
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:196)
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:149)
org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:171)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:290)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:209)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:265)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52
The jar containing this class is in every lib application: cxf-rt-transports-http-3.0.2.jar.
When I reload the one who's not working by the tomcat manager, I don't have the problem anymore and it reappears (on another war randomly) when I restart the server. The missing class is always the same.
I use Cxf version 3.0.2.
It appears it was a problem with the number of file opened by process. The tomcat's classloader has opened too many files because each application/war had numerous libraries in his repertory WEB-INF/lib.
When the ClassLoader can't open a java class file because of this limit, it doesn't throw any Exception: it just doesn't load the class... So when I called my application, the first class which was called and not loaded was BaseUrlHelper...
I've put some libraries in the tomcat/lib (and I have deleted them from the repertory WEB-INF/lib) and the applications have worked fine.
If you have admin access in your unix system, i saw there is also a thing with the command ulimit ..
You can also put you application in more tomcats.
Related
I am currently working on a weblogic 10 application server that has several installed ears. I got a request to change the application name of some aps as they appear in
Home >Summary of Deployments
I went to the appropiate Plan.xml and changed the with the appropriate name, restarted the domain but the name did not change.
Any ideas?
You can do that easily by modifying config.xml file in
DOMAIN_NAME/config
You can just modify the name and restart the server.
<app-deployment>
<name>jms-rename</name>
<target>DefaultServer</target>
<module-type>ear</module-type>
<source-path>C:\JMSTest\application\jms\target\jms-0.0.1-SNAPSHOT.ear</source-path>
<security-dd-model>DDOnly</security-dd-model>
</app-deployment>
The answer was very simple in the end. I added inside the EAR's manifest file the following entry
Weblogic-Application-Version: x.y.z
In this way I didn't have to mess up with any of the Weblogics configuration files.
I`m developing client that uses library Overthere 2.3.1. With local machine client works perfectly. But when I try to call same code included to EJB 3.0, I've got exception that not all required classes have been loaded.
I`ve looked over the source and found that the class contains Protocol annotation scanner (https://github.com/hierynomus/scannit) with hardcoded class name:
Scannit scannit = new Scannit(Configuration.config()
.scan("com.xebialabs")
.with(new AbstractScanner[] { new TypeAnnotationScanner() }));
The command
Thread.currentThread().getContextClassLoader().getResources("com/xebialabs")
returns null.
Looks like EJB runs in a separate classloader which does not have access to all the jars.
The EJB is packed to EAR with following structure:
EAR
--META-INF
----sda-dd.xml
----SAP_MANIFEST.MF
----MANIFEST.MF
----application-j2ee-engine.xml
--ejb.jar
--extlibs.jars
The MANIFEST.MF file don`t contain any referenses to external libs in CLASS-PATH. The EAR project is deployed to Application server successfully.
The EJB.jar also contains META-INF/MANIFEST.MF with value "Class-Path: ." by default.
I`ve already tried playing around with CLASS-PATH in manifest files, but have no luck.
Could anyone help me, how to build project with all external libs to be loaded while EJB runs? What have I missed with resources and classloaders?
I am in the process of creating a REST web service in Java Spring. I've successfully loaded STS and the example detailed at :
"This guide walks you through the process of creating a "hello world" RESTful web service with Spring."
http://spring.io/guides/gs/rest-service/
However that tutorial only goes so far.. I want to create a WAR file instead of a self running jar containing a servlet, and deploy that WAR file. I then found this tutorial, and attempted to just modify the first tutorials build.gradle file.
"Converting a Spring Boot JAR Application to a WAR"
http://spring.io/guides/gs/convert-jar-to-war/
It seemed to build just fine into a .war file.. the service is running in my TOMCAT instance's manager.. but I get 404's once I attempt to use the service.
URL 404'd
http://localhost:8080/gs-rest-service-0.1.0/dbgreeting?name=MyName
Do I need to modify the mapping?
DataBaseController.java
#RequestMapping("/dbgreeting")
public #ResponseBody DataBaseGreeter dbgreeting(
#RequestParam(value="name", required=false, defaultValue="World") String name) {
return new DataBaseGreeter(counter.incrementAndGet(),String.format(template, name));
}
Now I have the .war file created according to a blending of things.. and worried I perhaps missed something.
I've since discovered XAMPP on OSX doesn't contain a webapp/ folder, which has forced me to load Bitnami's Tomcat stack instead. Do people generally switch between XAMPP and other stacks based on this? or did I miss something to get webapp folder created in XAMPP?
A WAR is just a JAR with special properites. It needs to have a WEB-INF, under which you need a web.xml to describe your deployment, any app server dependentXML configuration files, and usually a lib, classes, and other odds and ends.
The easiest way would be to use Maven to create your WAR. I think you should be able to simply change the project type in the pom.xml from JAR to WAR. The tutorial you followed seems to use Gradle, which in turn uses Maven I believe, so you should have one there somewhere. Other than that, google for tutorials on how to construct a WAR. I don't believe that Tomcat requires any special deployment descriptors, so you should only need the web
.xml.
(Answer from OP moved from question to here)
Boy I feel really dumb.. Found there was more to the tutorial after changing the gradle instructions.. including the very needed Auto Configuration that supercedes/replaces the need for a web.xml
Solution
Initialize the servlet
Previously, the application contained a public static void main() method which the spring-boot-gradle-plugin was configured to run when using the java -jar command.
By converting this into a WAR file with no XML files, you need a different signal to the servlet container on how to launch the application.
src/main/java/hello/HelloWebXml.java
package hello;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.SpringBootServletInitializer;
public class HelloWebXml extends SpringBootServletInitializer {
#Override
protected void configure(SpringApplicationBuilder application) {
application.sources(Application.class);
}
}
Will give credit to the first answer, but you both were correct that the web.xml (or what Spring-Boot uses to replace it) was needed.
I would expect to see some INFO output when a spring boot application starts so some ideas are:
Try a regular tomcat instance
Download and extract the zip distribution.
Start tomcat with bin/startup.sh
Copy your war to the webapps directory
Check the logs... hope to see some evidence of spring starting up
Manually inspect the war file
Unzip your war file
Expect to see WEB-INF/web.xml
I have a very simple java web-application which is deployed to Tomcat.
In this application I have some code which goes like this:
package com.mywebapp.hello;
import javax.servlet.http.*;
import java.io.*;
public class PdfTwoServlet extends HttpServlet {
public void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException {
httpServletResponse.setContentType("application/pdf");
InputStream is = PdfTwoServlet.class.getResourceAsStream("/two.pdf");
When I compile my code and deploy it to tomcat, the directory structure goes like this:
This is under say C:\Tomcat\webapps\myApplication :
So
PdfTwoServlet.class.getResourceAsStream("/two.pdf");
works fine and finds the file two.pdf which is under classes folder, but I have no idea how this works.
Accessing properties file in a JSF application programmatically here BalusC says:
The Class#getResourceAsStream() can take a path which is relative to
the location of the Class which you're using there as starting point.
If you use /foo/filename.properties, then it will actually load
foo/filename.properties from the classpath root.
I have 2 questions:
1) Why is the classpath root is WEB-INF\classes folder? Where is it determined? ( As far as I understand, it should be because code is working fine as I said. )
According to this: http://docs.oracle.com/javase/tutorial/essential/environment/paths.html , I do not have a classpath set in my local machine. So maybe when I start tomcat, it sets the classpath? But there are few web-apps deployed, are there few classpaths?
2) Is there a better way to make this work instead of: PdfTwoServlet.class.getResourceAsStream ? Something like getClassPath().getResourceAsStrem ?
Edit: Maybe someone more experienced and with better English can edit the title of this question. I am not sure if it is good enough.
For 1) The classpath root in a servlet application is by specification the WEB-INF\classes folder of the jar, plus the root of all the jars in WEB-INF/lib of that WAR. Anything in those locations will be seen as the root of the classpath.
For the question on how classpaths in tomcat work, when tomcat deploys it set's the classpath in the following way: each WAR corresponds to a separate class loader which has access to WEB-INF/classes and all the jars in WEB-INF/lib.
By default if the resource searched is not found here, it will be searched for in the tomcat/lib directory. If it's not found there, it will ask the parent class loader, and so on, the explanation can be found here
If there are several web-apps deployed, each WAR will have it's own class loader pointing to it's own WEB-INF/classes and WEB-INF/lib jars.
For 2) there is not method like getClasspath(), ServletContext.getResourceAsStream() is the advised way in servlet applications for getting resources from inside the WAR. The WAR might be zipped or exploded, and this works for both, see this answer.
Is it possible for a web application to access its own deployed folder. I am using JSF 1.2 framework and i need to access some of the files which i have it in the deployed directory.
Does JSF has any in built method to give us the deployed folder and the files in it?
Use ExternalContext.getResourcePaths("/"). In a servlet container, this will delegate to ServletContext.getResoucePaths(String). As the documentation notes:
For example, for a web application
containing:
/welcome.html
/catalog/index.html
/catalog/products.html
/catalog/offers/books.html
/catalog/offers/music.html
/customer/login.jsp
/WEB-INF/web.xml
/WEB-INF/classes/com.acme.OrderServlet.class
/WEB-INF/lib/catalog.jar!/META-INF/resources/catalog/moreOffers/books.html
getResourcePaths("/") would return
{"/welcome.html", "/catalog/",
"/customer/", "/WEB-INF/"}, and
getResourcePaths("/catalog/") would
return {"/catalog/index.html",
"/catalog/products.html",
"/catalog/offers/",
"/catalog/moreOffers/"}.
For portable code, do not assume you can access resources via the file system:
This method (getResource(String)) allows the servlet container to make a resource available to servlets from any source. Resources can be located on a local or remote file system, in a database, or in a .war file.
You can get access to resources in the classpath, but the servlet API does not guarantee their physical representation. In other words, if you deploy a WAR file, the container may explode the WAR file or keep it as is, or do something completely different depending on its needs.
In this particular context it mean that you introduce a subtle container dependency by assuming that a web application is deployed to a folder, which you should be very careful about.
If all you need, however, is to get some items you have in the classpath you should have a look at this question: Getting the inputstream from a classpath resource (XML file)
FacesContext.getCurrentInstance().getExternalContext().getResource("/").toString();
you will get the path to your WEB-INF/classes dir traverse using parent(); method from File class to get the location