javax/inject/Inject.class in lib/javax.inject-1.jar is hidden by lib/javax.inject-2.5.0-b42.jar on onejar executable

老子叫甜甜 提交于 2019-12-13 02:37:00

问题


I am attempting to create an atomic executable jar (i.e. no dependencies outside of the jar).

To do this I have added a com.jolira:onejar-maven-plugin in my pom.xml. This seems to do the job, but when I execute the jar I get the warnings: JarClassLoader: Warning: Null manifest from input stream associated with: lib/javax.inject-1.jar JarClassLoader: Warning: javax/inject/Inject.class in lib/javax.inject-1.jar is hidden by lib/javax.inject-2.5.0-b42.jar (with different bytecode) JarClassLoader: Warning: javax/inject/Named.class in lib/javax.inject-1.jar is hidden by lib/javax.inject-2.5.0-b42.jar (with different bytecode)

It seems that my dependencies are pulling in both javax.inject-1.jar and javax.inject-2.5.0-b42.jar. To verify this I checked and both have/are being downloaded from the repository. I certainly don't have both listed in the dependencies, so there must be some implied dependency AFAICS.

Anyone know if there is a way to exclude just one jar from a maven dependency, or alternately to prevent onejar-maven-plugin from including it in the executable jar?

Is there a better way to create an atomic (or some call them fat) jar where the java loader can actually load from an embedded jar. I've tried all day with various different recipes and onejar was the only one that actually got the loaded to work.


回答1:


After some playing I found Alex's solution to be correct, just that I had put the exclude in the wrong place. The solution is to put it here:

<dependency>
  <groupId>org.glassfish.jersey.inject</groupId>
  <artifactId>jersey-hk2</artifactId>
  <version>2.26</version>
  <exclusions> <!--  exclude exclude javax.inject-1.jar -->
    <exclusion>
      <groupId>javax.inject</groupId>
      <artifactId>javax.inject</artifactId>
    </exclusion>
  </exclusions>
</dependency>



回答2:


Just putting this here for future. I solved the problem in this way: (It's for project's dependency which has javax.inject in its own dependencies)

<exclusion>
    <groupId>javax.inject</groupId>
    <artifactId>javax.inject</artifactId>
</exclusion>


来源:https://stackoverflow.com/questions/47802885/javax-inject-inject-class-in-lib-javax-inject-1-jar-is-hidden-by-lib-javax-injec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!