Understanding the Eclipse classpath declarations
Asked Answered
M

2

11

I'm trying to understand the Eclipse classpath file, in particular, I want to know this:

  1. How is the JRE using it (i.e. is the JVM reading this xml file directly, or is eclipse somehow feeding it into its internal compiler)?

  2. How are the complex entries (like the ivy path below) parsed and incorporated into the JVM ClassLoader when I run my classes from my IDE?

Context: I have a strange bug which is that eclipse is using the "wrong" version of a class, whereas my ivy / ant build is using the correct version, and I thus want to tool Eclipse to better mimick the classloader used in my pure build. In order to do this, I'm thinking I will have to look at the Eclipse project/classpath files.

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="src" path="test"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="lib" path="conf"/>
    <classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?ivyXmlPath=ivy.xml&amp;confs=*"/>
    <classpathentry kind="output" path="build"/>
</classpath>
Mohock answered 14/2, 2012 at 11:56 Comment(1)
I don't believe the JVM knows anything about the Eclipse classpath file. You can knock up a test class with a main block which just prints out System.getProperty("java.class.path") - that will show you that all your complex references are just resolved to jar file locations on the disk, which are then fed into a normal JRE classpath. If you have an obscure bug with the Ivy stuff then you might want to raise it with the developers of the Ivy Eclipse plugin? Good luck resolving your issueAtalayah
T
12

Two different things:

1) Project classpath is used to compile your code using Eclipse Java Compiler (ejc), so the file information is passed to the EJC.

2) When you create a launch configuration, you are actually declaring the classpath to run your application, which, by default, is based on your project classpath. This classpath is passed as an argument to the JVM like you would do it manually (java -cp ${classpathentries} yourmainclass). If you want to find out what is precisely the classpath of your launch configuration, launch your app/classes in debug mode, and in the Debug view, select your process and click on Properties where you will see the full classpath (all the jars/directories that are passed as argument to the JVM)

NB: I cannot see your ivy path stuff.

Transonic answered 14/2, 2012 at 12:10 Comment(2)
Thanks to point out the "debug, properties", this is what I'm looking for.Marquis
Is there any way to change the classpath manually in the launch configuration? Some of our dependency maven projects have testing resources under src/test/resources source folder. The eclipse run command will include the target/test-classes folder into the final classpath, which is not what We wanted.Aforethought
M
0

The problem could be :

It means in your eclipse classpath, you should be having two different version of the same class (two different jar files of different version). If thats the case, then try remove one. Also in your eclipse build path there is something called "Build Order" where you can specify the order of the classpath jar try changing that.

Mcclain answered 14/2, 2012 at 12:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.