Reputation: 982
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:
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!
Upvotes: 5
Views: 4405
Reputation: 982
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
).
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.
Upvotes: 2