Jar hell - force load one version - maven

Is there a way to force a java application to load a particular version of a jar, and not include the other version in the classpath?
Many other users here have noted that Elasticsearch unit tests throw jar hell errors. I have tried all the suggestions, and nothing has worked. I have set up tons and tons of 'exclusions' in my pom.xml, and this has not helped. How exactly is this jar being loaded?
java.lang.RuntimeException: found jar hell in test classpath
..
Caused by: java.lang.IllegalStateException: jar hell!
class: javax.servlet.annotation.WebFilter
jar1: /Users/xx/.m2/repository/org/jboss/spec/javax/servlet/jboss-servlet-api_3.0_spec/1.0.1.Final/jboss-servlet-api_3.0_spec-1.0.1.Final.jar
jar2: /Users/xx/.m2/repository/org/jboss/spec/javax/servlet/jboss-servlet-api_3.1_spec/1.0.0.Final/jboss-servlet-api_3.1_spec-1.0.0.Final.jar
How to find which jar is linked to jboss-servlet-api_3.0_spec-1.0.1.Final.jar? I have tried using tattletale(this did not generate reports) and maven-duplicate-finder(this did not find anything). I could hack it to set the jar-check option to false, but then I get shadowing errors.
These jars do not show up in my maven dependency tree.
I tried deleting the two versions from my .m2 directory, but they just popup again when I am running the app - is there a way to find out where it is being loaded from?

Related

JNI Error followed by Java Error when opening exectuable-jar

Good evening,
I encountered a problem while building an executable jar with Intellij. Before I never encountered Problems with it, but this time there is JNI Error occured and a Java Error occured message. I already tried the tips I found in Stackoverflow. It won't work with Maven Assembly Plugin or Maven Dependency Plugin. Moreover I tried creating the MANIFEST in main/java and main/resources. When I create it in main/java nothing happens when i open the jar with the second method the error mentioned earlier occures.
The only way it works is using this option in Artifacts
But using this option all of the libraries are in the file Path individually and the jar size is 75 kb. My goal was to create ONE fat executable jar. Btw another maven project I created works finde after creating the jar. Thanks in advance.

Spark can't find Guava Classes

I'm running Spark's example called JavaPageRank, but it's a copy that I compiled separately using maven in a new jar. I keep getting this error:
ERROR SparkUncaughtExceptionHandler: Uncaught exception in thread Thread[Executor task launch worker-0,5,main]
java.lang.NoClassDefFoundError: com/google/common/collect/Iterables
Despite the fact that guava is listed as one of Spark's dependencies. I'm running compiled Spark 1.6 that I downloaded pre-compiled from the apache website.
Thanks!
The error means that the jar containing com.google.common.collect.Iterables class is not in the classpath. So your application is not able to find the required class in runtime.
If you are using maven/gradle , try to clean, build and refresh the project. Then check your classes folder and make sure the guava jar is in the lib folder.
Hope this will help.
Good luck!

Intellij: How to add module compile output to web-inf/classes in stead of web-inf/lib?

I'm using maven to set up a war project in IntelliJ and run in it GlassFish. The war project depends on several other modules. When I run the project in debug mode, hot deploying codechanges of the changes results in NoClassDefFound exceptions. I found out that IntelliJ tries to redeploy the module jar but GlassFish keeps a lock on it so it fails. All the classes in that module are now unavailable, causing these NoClassDefFound exceptions.
IntelliJ generates the artifacts this way: the dependent modules are all added as jar dependencies as if they were external dependencies:
Now, when I remove the jar dependencies, IntelliJ tells me it found some missing dependencies and proposes a fix to add the missing dependencies.
Fixing those dependencies will add the module compile output to the WEB-INF\classes folder.
Once deployed, IntelliJ has no problem anymore hot-deploying changed classes to GlassFish since there's no jar to keep a lock on.
Problem
Every time I make a change to any pom.xml, IntelliJ refreshes the artifacts automatically, which is fine: I definitely want to see those changes appear in the artifact. However, all modules are added as jar dependencies again.
Question
How can I make sure that IntelliJ adds the compile output of project modules to WEB-INF\classes and not to WEB-INF\lib?
I found this question but it has two problems:
There are many module dependencies so if possible I'd like to avoid specifying them all one by one in the unpack goal
IntelliJ seems to ignore this. When I add that configuration and while it works perfectly in a maven commandline build, IntelliJ still refuses to add the module compile output to the WEB-INF\classes dir
I found a bugreport that asks about the same thing but for me it's hard to believe there's no way to solve this problem. Other webapp developers using IntelliJ must have this same issue, making it difficult to hot-deploy code changes, unless I did something wrong in my pom configuration.

Intellij trying to treat pom.xml as jar file

While trying to run test (on a maven project) from Intellij , I am constantly getting below mentioned error
[my-module] Exception in parsing jar file for extract from jar: /path/to/pom.xml java.util.zip.ZipException: The JAR/ZIP file (/path/to/pom.xml) seems corrupted, error: error in opening zip file
However all maven cycles run well when run from the command line.
Has anyone faced this issue before ?
I have already tried all these things
Invalidated Intellij Idea
Deleted my .m2 repo and recreated the project
ok , finally fixed.The osgi facets apparently were responsible.The issue was resolved once the facet was removed.Do not know the exact reason but the intellij osgi facet is known to be unstable. More info here
Even in 2020 this IntelliJ (Ultimate 2019.2) plugin tries to open a pom.xml file as a jar file. Disabling the OSGI plugin helped in my case:

IntelliJ: Including jars in a jar artifact

Developing on the Mac with IntelliJ 9.0.2 Community Edition.
I have a program which depends on two library jars. I have figured out how to get IntelliJ to make me a jar of my source (with the Artifact tab), and even to include the two jars in it.
However, if I get a listing of the jar file it produces, it looks like this:
com/acme/MyClass1.class
com/acme/MyClass2.class
...
mylib1.jar
myLib2.jar
And, no surprises, if I double-click the jar file, it gets a NoClassDefFoundError the first time it tries to access a class in one or other library jar.
It seems I need to tell IntelliJ to "inline" the library jars -- but this menu option is always greyed out!
Does anyone have any idea how to get jars inlined in a jar artifact?
IDEA doesn't support it yet, you can use Ant integration to package your jar (either by unpacking all the jars into the temp folder and then packaging the project output plus this temp folder into the single jar or by using some Ant task like jarjar).
If you want this feature to appear in the future IDEA versions, please vote for the request.
Having the dependency JARs included in your JAR should allow yoru code to run successfully. You probably don't have the JARs on your classpath.
I will use Maven Assembly plugin. Its simple and will give you a neat little jar file..

Resources