ClassNotFoundException on Maven Dependency Class org.apache.http.client - java

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.

Related

maven dependency - which dependency is using unwanted jar?

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.

Travis build with scope provided (java websockets)

I am setting up websockets with my Java j2ee servlet application. I was able to write the entire code and got the websockets working using following maven configuration -
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
My implementation does not work without <scope>provided</scope> and gives handshake exception: 404 not found.
Now, when I deploy my application on dev machines using travis, it gives exception while creating a build, and throws Java exception that ServerEndpoint class not found. I am assuming that it is because since scope is provided, Travis is not downloading the required jars while building a build on travis.
How do I avoid this, and ensure that we are able to work on local as well as deploy our builds via travis.

ERROR: Unable to process Jar entry - Selenium/Maven

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.)

eclipse jetty plugin Cross origin support Class not found

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

Tomcat can't find JSF API in a JSF webapp built by Maven with javaee-api dependency

I have searched many similar posts, however I cannot find a definitive answer on the correct way to build and deploy JSF applications, therefore I'm hoping someone can help...
Currently I am using Eclipse with Maven to build a simple JSF application and deploy it onto Tomcat 7, with one dependency in the POM.xml of:
<dependency>
<groupid>javax</groupid>
<artifactid>javaee-api</artifactid>
<version>6.0</version>
</dependency>
When I deploy onto the server I get:
java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
I cant figure out where this is coming from? I have no listeners defined in web.xml.
If I then change my dependency to:
<dependency>
<groupid>javax</groupid>
<artifactid>javaee-api</artifactid>
<version>6.0</version>
<scope>provided</provided>
</dependency>
And attempt to run the application on the server I get:
java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet
Which I can understand because I am now using scope as provided and thus it expects Tomcat to have the implementation and it cannot find it.
Finally if I drop javax.faces.2.1.13.jar into tomcat install dir/lib folder it works fine.
The javaee-api-6.0.jar imported using the Maven dependencies seems to contain the same javax.faces.* classes as the javax.faces.2.1.13.jar, therefore can anyone tell me why this doesn't work when I try and run the application on the server without scope as provided?
Although it works when having the javax.faces.2.1.13.jar in the tomcat install dir/lib folder, is this the correct way to deploy a faces application?

Categories

Resources