Bug 126499 - launcher strips classpath
Summary: launcher strips classpath
Status: RESOLVED WONTFIX
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Framework (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: equinox.framework-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 95733 (view as bug list)
Depends on:
Blocks:
 
Reported: 2006-02-05 15:55 EST by Jeff McAffer CLA
Modified: 2007-03-29 11:22 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff McAffer CLA 2006-02-05 15:55:32 EST
from bug 125250c12

To demonstrate the overwriting of the classpath:

1. Make a Hello World RCP application via the New Project wizard.

2. Add the following lines to Application.java in the run method:

      // Get Properties
      String info = "";
      info += "\nProperty Information\n";
      String [] name = {
        "java.library.path",
        "java.class.path",
      };
      for(int i=0; i < name.length; i++) {
        String value = System.getProperty(name[i]);
        String line = name[i] + ": " + value + "\n";
        info += line;
      }
      System.out.print(info);

3. Make a Run configuration and put the following in the VM arguments:

-cp junk1 -Djava.library.path=junk2 -Djava.class.path=junk3

I get:

Property Information
java.library.path: junk2
java.class.path: c:\eclipse\startup.jar

It ignores the classpath. You can also try to specify the classpath
in your own way.  The classpath is ignored in any way I have tried.

If this is not sufficient, I can send the project, but it doesn't
seem necessary.  The above is the only change.  The problem is easy
to demonstrate.
Comment 1 Alex Blewitt CLA 2006-02-18 21:17:46 EST
This isn't a bug. The classpath doesn't get 'overwritten'. The startup.jar launches its own VM, which has these properties set, and then it fires up a *second* VM that handle the OSGI launching. The classpath is simply not part of this process, whether specified as an environment variable or a command line parameter. The fact is that you're specifying a classpath for VM1, and expecting it to get through to VM2.

You should also note that 'java.class.path' is not a settable property, so -Djava.class.path is not going to set any information. 

The launcher is almost certainly configured not to set the classpath in this way, and it's a misunderstanding of how the launcher VM and Eclipse VM work.

As an observation, this is why when Eclipse crashes, you get a dialog box up explaining that it's crashed. VM2 goes down, VM1 notices, and displays the box. It's also how when you restart Eclipse (say, after an update manager run) Eclipse can shutdown and reopen. It returns a code to VM1 saying 'please re-launch me' and VM1 obliges.

This should be closed 'not a bug'.
Comment 2 Kenneth Evans, Jr. CLA 2006-02-19 12:06:09 EST
Thank you for your response.

I don't understand VM1 and VM2.  This is what I see using Dependency
Walker on Windows:

The program in question is JProbe SWT RCP.exe

The test .ini file is JProbe SWT RCP.ini:
-name
Test Case
-vmargs
-Xms40m
-Xmx256m
-classpath
C:\Deploy\JProbe SWT RCP JNI Test\plugins\gov.anl.xrays.epics.jca_1.0.0\jca-2.1.6.jar

There are three processes:

1. Program Executable: c:\deploy\jprobe swt rcp jni test\JPROBE SWT RCP.EXE
Program Arguments: 
Starting Directory: C:\Deploy\JProbe SWT RCP JNI Test\

2. Program Executable: c:\windows\system32\JAVAW.EXE
Program Arguments: -Xms40m -Xmx256m -classpath "C:\Deploy\JProbe SWT RCP JNI Test\plugins\gov.anl.xrays.epics.jca_1.0.0\jca-2.1.6.jar" -jar "c:\deploy\jprobe swt rcp jni test\startup.jar" -os win32 -ws win32 -arch x86 -launcher "c:\deploy\jprobe swt rcp jni test\JPROBE SWT RCP.EXE" -name "Test Case" -showsplash 600 -exitdata ffc_4c -vm C:\Windows\system32\javaw.exe -vmargs -Xms40m -Xmx256m -classpath "C:\Deploy\JProbe SWT RCP JNI Test\plugins\gov.anl.xrays.epics.jca_1.0.0\jca-2.1.6.jar" -jar "c:\deploy\jprobe swt rcp jni test\startup.jar" 

3. Program Executable: c:\deploy\jprobe swt rcp jni test\JPROBE SWT RCP.EXE
Program Arguments: -name "Test Case" -showsplash 600 "c:\Deploy\JProbe SWT RCP JNI Test\configuration\org.eclipse.osgi\splash.bmp"
Starting Directory: C:\Deploy\JProbe SWT RCP JNI Test\

(These lines were copied from the Dependency Walker output.)  Process
3. is the splash screen and would not be there if the .ini file had
-nosplash.  It is not part of the issue and can be ignored.

Notice that the classpath from the .ini file did get passed to Javaw.
Thus it *does* get overwritten (by startup.jar).  I see no other
virtual machine being started.  It is all happening in javaw, as far
as I can see.

>> You should also note that 'java.class.path' is not a settable
>> property, so -Djava.class.path is not going to set any information.

I know that.  It is irrelevant.  -classpath is not.

This issue was discussed in depth in Bug #125250 and a solution for
the real problem was found that did not require mofifying Eclipse for
that problem.  The reason this Bug was started is only that it is user
unfriendly to overwite something the user specifies in -vmargs.  If
the user specifies it, it should be included in whatever Eclipse sets
for the classpath.  It is the user's responsibility to do something
reasonable.

The issue in Bug #125250 is resolved, and this issue does not need to
be continued there.  I believe the purpose of this bug was to isolate
this relatively small issue.

Thanks again.
Comment 3 Thomas Watson CLA 2006-02-20 09:21:38 EST
(In reply to comment #1)

Eclipse does not start two VM's to launch.  The native launcher (eclispe.exe) is native c code which is responsible for finding a VM and the startup.jar and the proceeds to run java with the -jar startup.jar.  That is the one and only VM which launches eclipse.

I think the problem is what the vm does when the -jar is used.  We have a similar issue in bug 95733.  It seems that -classpath and the environment var $CLASSPATH is ignored with -jar is used with some VMs.
Comment 4 Jeff McAffer CLA 2006-03-01 22:37:55 EST
yes, absolutely.  if you use -jar, the -classpath or -cp stuff is ignored.  
Comment 5 Pascal Rapicault CLA 2006-04-06 16:20:28 EDT

*** This bug has been marked as a duplicate of 95733 ***
Comment 6 Pascal Rapicault CLA 2006-04-06 16:39:34 EDT
I've been a bit too loose here. Reopening.
Comment 7 Pascal Rapicault CLA 2006-04-06 16:41:00 EDT
*** Bug 95733 has been marked as a duplicate of this bug. ***
Comment 8 Pascal Rapicault CLA 2006-04-06 16:41:51 EDT
Standard manifest has a basic support for expressing dependencies. It might be a way to go.
Comment 9 Thomas Watson CLA 2007-03-28 09:55:39 EDT
Closing as wontfix again.  It is by design that we ignore the classpath variable.  Eclipse does not want to expose extra stuff through the application classloader by default.  This leads to a poor modularity system.  If you need to do something fancy with extra classpaths then you must either launch with a different launcher jar and use pascal's suggestion in comment 8 or better yet use a real bundle that allows you to define proper modular dependencies on.
Comment 10 adrian CLA 2007-03-28 10:18:45 EDT
Please note that bug 95733 was marked as a dup of this one HOWEVER its complaint is exactly the opposite - the classpath is NOT ignored in all circumstances.  See comment #21 in 95733: "I finally am able to reproduce this.  This happens when an IBM 1.4.2 JRE is used.  When using the -jar option the Sun JRE will ignore the CLASSPATH env.  But the IBM 1.4.2 JRE appears to use the CLASSPATH variable even when using the -jar option."
Comment 11 Andrew Niefer CLA 2007-03-28 10:38:51 EDT
Note that with the new launcher, bug 126499 would no longer occur when the vm is loaded using JNI invocation (since we are completely bypassing the java.exe), which it would be when starting as described in bug 126499 comment #18
Comment 12 Kenneth Evans, Jr. CLA 2007-03-28 11:20:12 EDT
OK.  I submitted the bug, looks like about a year ago.  I have learned to deal with it, and don't have any problem with your closing it as WONTFIX.  I wrote a simple class loader that will load things from anywhere I want, though I haven't had to use it yet.  One could even use the URLClassLoader to do that.

The problem that initiated this bug was that JNI implementations that get callbacks from threads not started by the VM use a FindClass routine to find the Java class to handle the callback.  This supplied C routine uses the standard class loader, which uses the classpath, and I have found no way to avoid that.  It can be worked around as in Bug #125250 and there is a blurb in the release notes as to how to do that.  Unfortunately, it involves rewriting the JNI code, which is not always possible.

The problem, as with much of Eclipse, is that it is difficult to find these things out, and it uses a great deal of my time as well as that of others.

In particular, I guess I need to find out about the "new launcher".

The participants in this bug have been really friendly and helpful, and I appreciate that.  Unfortunately, my mileage in that regard varies for other bug report.  Consequently, I thank all of you for the information and feel the effort was not wasted, as others will also find the information here.
Comment 13 Thomas Watson CLA 2007-03-29 09:14:45 EDT
A bug needs to be opened against the IBM vm.  I will look open a bug.
Comment 14 Thomas Watson CLA 2007-03-29 09:31:46 EDT
(In reply to comment #11)
> Note that with the new launcher, bug 126499 would no longer occur when the vm
> is loaded using JNI invocation (since we are completely bypassing the
> java.exe), which it would be when starting as described in bug 126499 comment
> #18

Andrew, I'm not following.  Are you saying that this bug 126499 does not happen with the new launcher?  or that the duplicated bug 95733 will no longer occur with the new launcher?

This bug 126499 was opened because the classpath variable is ignored when launching with the -jar option.  Is that no longer the case with the new launcher?

Comment 15 Andrew Niefer CLA 2007-03-29 11:22:01 EDT
I think I got confused by the duplication. I meant bug 95733: with the new launcher, when using JNI invocation to start the vm, the CLASSPATH variable would not be read.  (Though when we fork java in a separate process, it may be read by the java launcher).  So I