0

This SO question asks how to get Eclipse to compile with the —patch-module javac option.

However, I have found no obvious and easy way to get Eclipse to run the compiled patched code using the same configuration.

i.e. to use the Build Path / Module Dependencies configuration described in the question above at Run / Debug time too.

After much fruitless hunting, I resorted to adding "—patch-module xxxx" to the Launch “Debug Configurations / Arguments / VM Arguments” to point to the folder containing the classes compiled by Eclipse. e.g.

--patch-module java.security.jgss=/Users/xxx/svn/JGSSDebug/bin

That worked, but is a bit brute force! Is there an easier way that I have missed?

Edit1

One can use Java Build Path / Module Dependencies / Show JPMS Options from the project JGSSDebug to get the correct command line syntax, and manually paste to the VM Arguments of the Launch Configuration of the project JGSSDebug-Test. (...just don't forget to change "src" to "bin" at the end of the path ...). The first time round I worked the syntax myself.

End Edit1

I am running Eclipse Version: 2021-03 (4.19.0) Build id: 20210312-0638

Background:

In order to troubleshoot problems with SPNEGO SSO we want to enrich classes in the JRE module java.security.jgss with additional log output.

I have created two Eclipse Projects:

  1. JGSSDebug This project contains the java.security.jgss classes we will patch with log output. The .classpath file contains:

    <attribute name="patch-module" value="java.security.jgss=/JGSSDebug"/>'
    
  2. JGSSDebug-Test This project will call code in java.security.jgss including the patched code in JGSSDebug. It depends on JGSSDebug:

    <classpathentry combineaccessrules="false" kind="src" path="/JGSSDebug"/>
    

The only way I could find to make JGSSDebug-Test run the patched code was via the “VM Arguments” as described above.

Neither project has a module-info.java file.

We are using Azul OpenJDK 11.0.11 to compile and run.

FlyingSheep
  • 804
  • 1
  • 9
  • 20
  • It works for me using the Eclipse UI. Please provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) (maybe by sharing the Eclipse project via GitHub, GitLab, etc.). I would recommend using only one project to avoid unnecessary complexity. Depending on your project layout select the project instead of the source folder might be wrong. The patch has to be specified in the project of the launch configuration, not in a dependent project. – howlger Jul 23 '21 at 15:41
  • @Howlger tx: The "two projects" example is closer to the real life use, where I will call the patched code from a large multi-project code, and is thus the minimum reproducible example. As stated in the question, adding --patch-module manually to the launch of the calling project works. Let me work out how to share my code ... – FlyingSheep Jul 23 '21 at 15:55
  • @Howlger plus, if I call the patched code from a main method in the JGSSDebug project, I get a java.lang.ClassNotFoundException - for the class in which the main method is in! I did not want to complicate the question with this side issue, as it does not represent how the patched code will be called in practice. – FlyingSheep Jul 23 '21 at 16:01
  • What you are saying sounds like you missed configuring the patch in the project of the launch configuration, because you mistakenly assume the setting is propagated from the dependent project (which is not true for this and other settings of the same tab). Please note, `--patch-module` should not used for production code (see the documentation). – howlger Jul 23 '21 at 18:05
  • @howlger, yes I am aware --patch-module is not for production code. We will use it for debugging / troubleshooting only, hence the use of "debug" in the project names 8-) – FlyingSheep Jul 23 '21 at 18:43
  • @howlger as should be clear from the question, I did NOT miss configuring the patch in the calling project launch - I explicitly had to do this manually, and did so to my surprise with success on first attempt. Perhaps mistakenly, I had hoped that Eclipse might automagically help me here. At the end of the day, if the result is that in my use-case I must manually configure the launch of the calling project, as I did, then that is like it or not the current answer. Tx. – FlyingSheep Jul 23 '21 at 19:00
  • Your question says that you specified the patch in the _JGSSDebug_ project. If the launch configuration belongs to the _JGSSDebug-Test_ project, then you have it also configure it in the _JGSSDebug-Test_ project. The settings of the _Module Dependencies_ tab of dependent(!) projects do not matter. So, instead of telling you did not miss anything, tell what do you have (show what you have in the _Module Dependencies_ tab of project to which the launch configuration belongs). – howlger Jul 23 '21 at 19:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/235238/discussion-between-flyingsheep-and-howlger). – FlyingSheep Jul 23 '21 at 19:48

1 Answers1

1

It does not work with dependent projects. Each project has its own and exclusive Project > Properties: Java Build Path > Module Dependencies settings.

There seems to be an issue in the current version of Eclipse: in the Module Dependencies tab, when hitting the Show JPMS Options... buttons, the correct --patch-module java.security.jgss=... will be shown, but in the launch configuration these JPMS options are missing. Please make sure, this has been reported to Eclipse JDT.

As alternative or workaround, to avoid to specify --patch-module java.security.jgss=... in each launch configuration, add it as default VM argument to the JRE/JDK:

  1. In the preferences Java > Installed JREs choose the JRE/JDK used in your project and hit Edit...
  2. As Default VM argument enter the following:
    --patch-module java.security.jgss=${workspace_loc:/JGSSDebug/bin}
howlger
  • 31,050
  • 11
  • 59
  • 99
  • From more testing this morning, I can confirm that manually adding "--patch-module java.security.jgss=..." as a VM Argument to the calling project works both for a bin folder, and also for a compiled jar (with the same classes). – FlyingSheep Jul 26 '21 at 08:59
  • I have reported to Eclipse JDT: https://bugs.eclipse.org/bugs/show_bug.cgi?id=575029 – FlyingSheep Jul 26 '21 at 09:36