I am trying to use Cross Origin Filter support for my web application. I am using eclipse jetty plugin to debug it from eclipse. When I run the class through console, using mvn jetty:run, I always get correct response. But when I run it using my jetty eclipse plugin, I get Class not found exception.
java.lang.ClassNotFoundException: org.eclipse.jetty.servlets.CrossOriginFilter
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:421)
at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:383)
at org.eclipse.jetty.util.Loader.loadClass(Loader.java:100)
I have the following dependency in my pom.xml :
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>9.2.5.v20141112</version>
</dependency>
When I check the classpath configurations of my jetty project in eclipse, I see this dependency present as maven dependencies. Still I am not sure why the jetty plugin is not able to find org.eclipse.jetty.servlets.CrossOriginFilter as a part of classpath. Kindly help me with this.
edit:
Looks like it is not only for the CORS. Even other classes present in web.xml throws error for class not found. I checked in the jetty classpath of that debug configuration and able to find these jars in there. Not sure why this is happening.
That can't be part of your webapps WEB-INF/lib directory (not supported that way, as it cant access the internal server components it needs).
Enable the servlets module in your ${jetty.base}/start.ini instead
--module=servlets
Although I am not sure that the following is the best solution possible, however it does work:
First of all I added
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>${jetty-maven.version}</version>
<scope>test</scope>
</dependency>
Notice that I used the test score here in order to avoid leaking the dependencies used solely for the Maven Jetty plugin into the production artifact.
In order for the Maven Jetty plugin to be able to use this dependency (since it doesn't by default use the test scope), you need to enable
<useTestScope>true</useTestScope> in the configuration part of the plugin
Related
I'm trying to build a simple API client, which uses org.apache.httpfor connecting to the API server. Locally everything works fine. I'm successfully connecting to the server and receive the data I want.
But, when I deploy my application to the server. I'm getting following exception:
Caused by: java.lang.ClassNotFoundException: org.apache.http.client.ClientProtocolException from [Module "deployment.adobe-livecycle-jboss.ear:main" from Service Module Loader]
I tried multiple different variants of versions of my depencies. Right now im using the following:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.1</version>
<scope>compile</scope>
</dependency>
Both of the JARs appear in my Java Build Path, also the class which is "missing" is found in there.
Even when I build the project and search the JAR files libs folder, I can find the class...
I know there are some solutions to find online but none of them helped me.
This is probably caused by a faulty maven local repository. Try looking for your maven local repository (It's generally a hidden folder like named.m2\repository), delete the folder org\apache\httpcomponents then clean compile your project.
Edit:
After further explanation of the problem, it seems that this is a deployment issue not a build one.
If it's the first time that you use this package in your build, then this package's jar must be defined somewhere in the deployment server, it seems that you are deploying in an Adobe environment which seems to be based on JBoss because of that line of log that you provided
[Module "deployment.adobe-livecycle-jboss.ear:main" from Service Module Loader]
Make sure to read the documentation of that environment on how to configure and define external modules.
I am working on upgrading a complex maven project, with numerous pom files. The code is built using openjdk and it runs on jboss6.*
On starting up Jboss, I'm getting the following exception:
NoSuchMethodError:
org.apache.http.conn.ssl.SSLConnectionSocketFactory.(Ljavax/net/ssl/SSLContext;Ljavax/net/ssl/HostnameVerifier;)V
Initially, it looked like I was not importing the right maven dependency.
I looked at the pom file for the project where the exception is thrown and I found the following dependency:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
However, when adding the following line
LOGGER.debug(org.apache.http.conn.ssl.SSLConnectionSocketFactory.class.getProtectionDomain().getCodeSource().getLocation().getPath());
I get the following output:
11:54:37,037 DEBUG [packageobsucated.httpclient.HttpClientConfigUtil]
(ServerService Thread Pool --
69) file:/server/modules/system/layers/base/org/apache/httpcomponents/main/httpclient-4.3.6.redhat-1.jar!/
How can I find out which maven dependency is using httpclient-4.3.6.redhat-1.jar?
I have called mvn dependency:tree on the parent pom.xml file but I'm afraid I cannot find anything with that exact description.
Thanks in advance,
I am not jboss expert, but I guess that this dependency is loaded from a module inside jboss, i.e. not from your war.
So I guess you need to look for the order of class loading in your jboss if you want to use a different version of httpclient.
I am trying to deploy my Maven project on Tomcat within Eclipse, but since I just added a new Selenium dependency I am now getting this error every time I start the server:
SEVERE: Unable to process Jar entry [module-info.class] from Jar [jar:file:/Users/ash/eclipse-workspace/my-project/target/my-project-0.0.1-SNAPSHOT/WEB-INF/lib/selenium-api-3.14.0.jar!/] for annotations
This is the dependency:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.14.0</version>
</dependency>
I have tried following advice given on related questions, as it seems people have had this issue with a variety of different dependencies. The advice included using the latest version of the dependency, or deleting the dependency and jar files from the lib folder, and then re-adding them and rebuilding Maven before I deploy the project, but I had no luck. Has anyone got an idea of how I can fix this? I need to use Selenium to test my web app.
(I'm using the tomcat7-maven-plugin if that makes any difference.)
We have a maven project which successfully builds when we do it from CLI.
Unfortunately when we try to add the project on weblogic through eclipse the following exception is thrown:
18-05-23 10:27:35 ERROR digester.Digester - Digester.getParser:
org.xml.sax.SAXNotRecognizedException:
http://apache.org/xml/features/validation/dynamic at
oracle.xml.jaxp.JXSAXParserFactory.setFeature(JXSAXParserFactory.java:128)
at
org.apache.commons.digester.parser.XercesParser.configureXerces(XercesParser.java:185)
at
org.apache.commons.digester.parser.XercesParser.newSAXParser(XercesParser.java:138)
at
org.apache.commons.digester.ParserFeatureSetterFactory.newSAXParser(ParserFeatureSetterFactory.java:71)
We have the following as a dependency:
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.9.1</version>
</dependency>
Any suggestion on how to overcome this problem?
If it successfully builds from Maven, but does not work in Eclipse, it must be a difference in the JDK being used or the classpath.
My guess is that you have more than one XML library on your classpath and, due to the ordering of the classpath, a different one is taking precedence in each case.
To list the classpath in Maven:
mvn dependency:build-classpath -Dmdep.outputFile=cp.txt
Manually compare the ordering with the Eclipse one (in the .classpath file), paying particular attention to any JARs that may contain XML libraries. If any JARs are missing or in a different order, adjust them to match the Maven classpath.
Please help me to solve the issue. I built a WAR (uising Maven) but when I tried to deploy it in Tomcat I got an Exception:
org.apache.jasper.JasperException: Unable to compile class for JSP:
The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory
I found the cause of the problem on stackoverflow - the issue is in inconsistency of the Servlet API in project's classpath and relevant libraries used by current version of servlet container. The provided solution is to avoid adding any Servlet API relevant libraries (servlet-api.jar, jstl.jar, jsp-api.jar, etc.) to lib - folder. I also found a solution for Eclipse ([How do I import the javax.servlet API in my Eclipse project?). But I develop in IntellijIDEA and it differs from Eclipse. In my case there is no possibility to not add servlet-api.jar and jstl-${version}.jar to classpath. If I don't add them I can't compile a project. If anyone can assist me in the issue I would thankful a lot.
When using maven, you can exclude dependencies from the war using the provided scope, like this:
<dependencies>
<dependency>
<groupId>some.group.id</groupId>
<artifactId>some-artifact-id</artifactId>
<version>x.y.z</version>
<scope>provided</scope>
</dependency>
</dependencies>
You need to do that for all the dependencies provided by tomcat.
Intellij Idea also provide a similar scope mechanism, see the documentation here.