maven: exclude jar from JDK

testuser

So, I've been searching SO for hours and hours and I'm completely running into the brick wall here.

My problem's quite simply: I've got a (pretty big) project that I'd like being built with Maven (so I can automate it all a bit). Everything works fine so far except for one major problem.

I've got a dependency called "java-plugin" - I don't know exactly the origin or the author, but it was in the dependencies of a dependency of mine - I added it to our own Nexus third party repository with the name the original jar was given.

This plugin gets added from my Nexus without any problems, but it has the following structure:

- netscape
    -- javascript
        JSException.class
        JSObject.class
        JSUtil.class
    -- security
        ForbiddenTargetException.class
        ParameterizedTarget.class
        Principal.class
        Privilege.class
        PrivilegeManager.class
        PrivilegeTable.class
        Target.class
        UserDialogHelper.class
        UserTarget.class
- sun
    -- plugin
        ...
    -- plugin2
        ...
- com.sun.java.browser.plugin2
    ...

What's the problem? As long as I was working in an Eclipse based project, I placed my JDK as the "last" one on my classpath. Now it's Maven and apparently Maven places the JDK first. In my JDK I have the jfxrt.jar (part of Java FX). This one also contains a netscape.javascript.JSObject object (and also a netscape.javascript.JSException object). It doesn't contains a netscape.javascript.JSUtil object on the other hand. So Maven picks up the JSObject and the JSException from the JDK library, and the other classes he picks up from my own java-plugin dependency.

Of course both classes are not the same. Of course now I get compilation errors as the java-plugin dependency contains a 'getWindow' method in the JSObject class where the JDK library doesn't.

The ideal situation would be to exclude jfxrt.jar from Maven, but I have absolutely no idea on how to do that. Any other solution would do too, as long as I could get this one to build with Maven. Note: I'd rather not want to use the "endorse" mechanism in Java if possible, as that would require uploading this library to several different servers over and over again and would cause huge delays in deployment (as we'd always have to sent the file to our support team for yet another upload).

Thanks!


EDIT

So, my plugin dependency is something which is also in the JDK - even better! I don't need my java-plugin, I've got enough with my JDK which includes plugin.jar automatically (it's in my ${java.home}/lib/plugin.jar).

Now I have this situation:

Dependency problem in Maven

As you can see, the jfxrt.jar comes first, before the plugin.jar. I can see why Maven, or Java more generally, stops looking as soon as it finds the first netscape.javascript.JSObject (which is in jfxrt.jar). But I really need it to load the second JSObject class (which unfortunately happens to be in the same package and with the same name). How the hell am I supposed to do this? And why did this work without a charm in Eclipse, when I wasn't using Maven, and why doesn't it work in IntelliJ, together with Maven?

Thanks in advance!

testuser

Ok, so I figured it out. Apparently this was much more of an IntelliJ issue than it was of a classpath issue.

So IntelliJ automatically adds the full JDK (including all jars in /jre/lib) to the classpath - first, before all the Maven dependencies. So that caused my project to be going weird: I had a netscape.javascript.JSObject in jfxrt.jar, in plugin.jar and in my Maven plugin (these jars were added in this order). The first JSObject that was found was the one in jfxrt.jar, which caused the problem.

It worked in Eclipse as there, I could alter the classpath order and had added my Maven plugin BEFORE the JDK - so the order became java-plugin.jar (first one, correct JSObject class), jfxrt.jar, plugin.jar.

It would have worked when I'd use an older JDK - this jfxrt.jar was only added in JDK7.

It works on Jenkins, if I still have my java-plugin.jar from Maven, because Jenkins does not automatically add the JDK libraries (only the core). That was how I cleared it out:

  • I removed my own java.plugin.jar and replaced it by a dependency on plugin.jar.

    <dependency>
        <groupId>com.sun.jdk</groupId>
        <artifactId>plugin</artifactId>
        <version>${version.java-plugin}</version>
        <type>jar</type>
        <scope>system</scope>
        <systemPath>${java.home}/lib/plugin.jar</systemPath>
    </dependency>
    
  • I still had the problem in IntelliJ, but arrived to remove the jfxrt.jar from the imported JDK libraries in IntelliJ itself - which does change the .iml file but of course not anything that would be of use for Jenkins. (You can edit these settings by right clicking on the External Libraries > < 1.7> folder in the Project Browser, and then clicking Open Library Settings).

  • Once jfxrt.jar was removed, everything worked. I reasoned that this wouldn't change anything in Jenkins, but on the other hand, then the problem maybe wouldn't even exist on Jenkins. So I simply tried and commited my code to SVN to build it on Jenkins.

Magically, it works now on Jenkins too. I tried and removed my dependency on plugin.jar, then I get the classical "could not find symbol" compilation error on Jenkins - while I don't get that error in IntelliJ, due to the automatically importing of the JDK on the classpath.

Long story short: By editing my project settings in IntelliJ I got it working locally, by simply trusting Maven I got it working on Jenkins, the way it should.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to exclude a package from a jar (with maven)

From Dev

Maven - How to exclude dependencies from generated JAR

From Dev

Exclude META-INF/maven folder from the generated jar file

From Dev

How to use maven assembly plugin to exclude a package from dependency jar?

From Dev

Maven assembly or shade plugin - How to exclude sources from jar?

From Dev

Maven Create Jar and exclude Files

From Dev

How do I exclude java files from a jar in maven-jar-plugin?

From Dev

maven-dependency-plugin: exclude .jar files

From Dev

Exclude packages while generating sources jar in Maven

From Dev

How can I exclude some packages (within a JAR) from a Maven dependency?

From Dev

Exclude resources from dependency jar

From Dev

JDK9 and maven-jar-plugin

From Dev

Maven - exclude folder from build

From Dev

Gradle - Exclude file from being packaged with jar

From Dev

OpenEJB: How to exclude jar from module search?

From Dev

Gradle: How to exclude a particular package from a jar?

From Dev

Exclude .jar from compile in Android Studio with Gradle

From Dev

How to really & fully exclude a package from a jar?

From Dev

Exclude Jar from Ant Build using zipgroupfileset

From Dev

How to exclude modules or groups in a jar from Gradle?

From Dev

Exclude obfuscated jar from lib folder with ProGuard

From Dev

Gradle - Exclude file from being packaged with jar

From Dev

Maven: How to have jar-with-dependencies exclude "provided" dependencies?

From Dev

Create jar file from maven

From Dev

Exclude file from jar as built by jar-with-dependencies

From Dev

Maven: exclude dependency from shade plugin

From Dev

Maven - Exclude class files from war

From Dev

Conditionally exclude some resources in maven from war

From Dev

Maven - Exclude class files from war

Related Related

  1. 1

    How to exclude a package from a jar (with maven)

  2. 2

    Maven - How to exclude dependencies from generated JAR

  3. 3

    Exclude META-INF/maven folder from the generated jar file

  4. 4

    How to use maven assembly plugin to exclude a package from dependency jar?

  5. 5

    Maven assembly or shade plugin - How to exclude sources from jar?

  6. 6

    Maven Create Jar and exclude Files

  7. 7

    How do I exclude java files from a jar in maven-jar-plugin?

  8. 8

    maven-dependency-plugin: exclude .jar files

  9. 9

    Exclude packages while generating sources jar in Maven

  10. 10

    How can I exclude some packages (within a JAR) from a Maven dependency?

  11. 11

    Exclude resources from dependency jar

  12. 12

    JDK9 and maven-jar-plugin

  13. 13

    Maven - exclude folder from build

  14. 14

    Gradle - Exclude file from being packaged with jar

  15. 15

    OpenEJB: How to exclude jar from module search?

  16. 16

    Gradle: How to exclude a particular package from a jar?

  17. 17

    Exclude .jar from compile in Android Studio with Gradle

  18. 18

    How to really & fully exclude a package from a jar?

  19. 19

    Exclude Jar from Ant Build using zipgroupfileset

  20. 20

    How to exclude modules or groups in a jar from Gradle?

  21. 21

    Exclude obfuscated jar from lib folder with ProGuard

  22. 22

    Gradle - Exclude file from being packaged with jar

  23. 23

    Maven: How to have jar-with-dependencies exclude "provided" dependencies?

  24. 24

    Create jar file from maven

  25. 25

    Exclude file from jar as built by jar-with-dependencies

  26. 26

    Maven: exclude dependency from shade plugin

  27. 27

    Maven - Exclude class files from war

  28. 28

    Conditionally exclude some resources in maven from war

  29. 29

    Maven - Exclude class files from war

HotTag

Archive