ERROR: Unable to process Jar entry - Selenium/Maven - java

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

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.

What is the equivalent of adding a jar to deployment assembly in maven

I am working with a maven project in eclipse which I have been testing using the built-in "run on server" tomcat option. When I try to do this, I get errors stating certain dependencies are unmet from an external jar I reference in the POM. However I have found if I add the jar via the DeploymentAssembly Tab I can run in eclipse without issues:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.company.user.server.UserDetailsAuthoritiesMapper#0'
The issue comes when I try to deploy on an actual tomcat instance. The Maven build runs fine, but when I start the servlet I get the same unmet dependency errors. This to me is indicating that the external jar is not being properly packaged into the war. What is the maven equivalent of adding the package via the DeploymentAssembly tab in eclipse? The entry in the POM.xml:
<dependency>
<groupId>com.company.webapp</groupId>
<artifactId>webapp-user</artifactId>
<version>106</version>
</dependency>
Thanks
You need to locate the maven info for the external jar. If you google the name of the jar and maven you often find a direct link to the block you need. For example if I want version 1.58 of the Bouncy castle jar Google "Maven BouncyCastle" you can find the artifact info. Add that info to your pom.xml as a new dependency in your block.
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.58</version>
</dependency>
After you rebuild, refresh maven in your IDE 1st after doing a clean, this will tell maven to pull down the jar and added it to your build.
You can also go to the repo directly and search:
Maven Repo: https://mvnrepository.com/

java.lang.NoClassDefFoundError: org/apache/spark/streaming/api/java/JavaStreamingContext [duplicate]

I am getting ClassNotFoundException and NoClassDefFoundError exceptions when I attempt to run my application using a maven defined dependency.
I added my maven dependency for the jar in question to my pom.xml file with the following declaration:
<dependency>
<groupId>spy</groupId>
<artifactId>spymemcached</artifactId>
<version>2.8.4</version>
<scope>provided</scope>
</dependency>
This added the relevant JAR file to my Maven Dependencies folder in Eclipse. I can access the classes in code but I get the mentioned exceptions once I run the application.
The jar is referenced in my Java build path under Maven dependencies:
My local maven repository is added to my classpath:
When I attempt to run the application, I get the following two exceptions:
java.lang.NoClassDefFoundError: Lnet/spy/memcached/MemcachedClient;
java.lang.ClassNotFoundException: net.spy.memcached.MemcachedClient
Can anyone point me in the right direction?
Change provided to compile
Provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
<scope>provided</scope>
"Provided" scope implies that the dependencies should be available only during compile phase and they will be available elsewhere during runtime and Maven shouldn't package them with the rest of the jars and classes of the current application.
Your dependency doesn't seem to be of "provided" scope. Remove that scope from your dependency definition and the jars will be present in your packaged jar/war/ear.
I was facing the same issue but i didn't have the tag defined on my POM, it was always working fine until one day all of a sudden started giving me that error in my local machine for no reason, the dependency was correctly set up in the POM and the jar was present in the local maven repository.
I tried cleaning the project and updating maven project but nothing, none of the other solutions suggested on other posts worked for me either.
I was finally able to solve it by going to the servers tab -> right click on Tomcat v8.0 -> browse deployment location
this should lead you to a temp folder like
.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps
then you browse to your project folder -> WEB-INF -> lib -> here i found out that the jar from the library that was giving the error was missing, so i just copied it from .m2\repository
Restarted the server and it started working as usual again.
I hope this helps some body facing the same issue.
Answer somewhat related to your problem, but still can help others.
Adding <scope>compile</scope> to the dependency was not enough in my case. I also had to add <packaging>jar</packaging> to the target module's pom.
I was also facing the same problem, after trying various solutions the issue was resolved by following steps...
click on server >open launch configurations >Arguments (copy
"LocalPath\temp0\wtpwebapps" path).
go to "LocalPath\temp0\wtpwebapps\ProjectName\WEB-INF\lib".
copy the JAR (which was causing ClassNotFoundException) from .m2 and place it in "LocalPath\temp0\wtpwebapps\ProjectName\WEB-INF\lib" path.

Spring boot The project cannot be built until build path errors are resolved

We have 100% working project.
It works perfectly on 2 Windows computers, but when I clone it from repo to Mac - OS El Capitan, Eclipse with STS plugin - I can not built it, I get this error:
Archive for required library: '/Users/{username}/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.47/bcprov-jdk15on-1.47.jar' in project '{project name}' cannot be read or is not a valid ZIP file {project name}
In Maven pom.xml I have added required dependency, but it still doesn't solve the problem:
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.47</version>
</dependency>
Any advice will be appreciated!
Delete /Users/{username}/.m2/repository/org/bouncycastle/bcprov-jdk15on/1.47/bcprov-jdk15on-1.47.jar, and download "bcprov-jdk15on-1.47.jar" (and verify that it downloaded correctly) then place it there manually.

Java ClassNotFoundException with maven dependency

I am getting ClassNotFoundException and NoClassDefFoundError exceptions when I attempt to run my application using a maven defined dependency.
I added my maven dependency for the jar in question to my pom.xml file with the following declaration:
<dependency>
<groupId>spy</groupId>
<artifactId>spymemcached</artifactId>
<version>2.8.4</version>
<scope>provided</scope>
</dependency>
This added the relevant JAR file to my Maven Dependencies folder in Eclipse. I can access the classes in code but I get the mentioned exceptions once I run the application.
The jar is referenced in my Java build path under Maven dependencies:
My local maven repository is added to my classpath:
When I attempt to run the application, I get the following two exceptions:
java.lang.NoClassDefFoundError: Lnet/spy/memcached/MemcachedClient;
java.lang.ClassNotFoundException: net.spy.memcached.MemcachedClient
Can anyone point me in the right direction?
Change provided to compile
Provided
This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.
<scope>provided</scope>
"Provided" scope implies that the dependencies should be available only during compile phase and they will be available elsewhere during runtime and Maven shouldn't package them with the rest of the jars and classes of the current application.
Your dependency doesn't seem to be of "provided" scope. Remove that scope from your dependency definition and the jars will be present in your packaged jar/war/ear.
I was facing the same issue but i didn't have the tag defined on my POM, it was always working fine until one day all of a sudden started giving me that error in my local machine for no reason, the dependency was correctly set up in the POM and the jar was present in the local maven repository.
I tried cleaning the project and updating maven project but nothing, none of the other solutions suggested on other posts worked for me either.
I was finally able to solve it by going to the servers tab -> right click on Tomcat v8.0 -> browse deployment location
this should lead you to a temp folder like
.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps
then you browse to your project folder -> WEB-INF -> lib -> here i found out that the jar from the library that was giving the error was missing, so i just copied it from .m2\repository
Restarted the server and it started working as usual again.
I hope this helps some body facing the same issue.
Answer somewhat related to your problem, but still can help others.
Adding <scope>compile</scope> to the dependency was not enough in my case. I also had to add <packaging>jar</packaging> to the target module's pom.
I was also facing the same problem, after trying various solutions the issue was resolved by following steps...
click on server >open launch configurations >Arguments (copy
"LocalPath\temp0\wtpwebapps" path).
go to "LocalPath\temp0\wtpwebapps\ProjectName\WEB-INF\lib".
copy the JAR (which was causing ClassNotFoundException) from .m2 and place it in "LocalPath\temp0\wtpwebapps\ProjectName\WEB-INF\lib" path.

Categories

Resources