skip to Main Content

In a Java project running in VSCODE, when executing a certain class, there is a conflict between the rt.jar library (from the JDK itself); and the referenced library jaxb-api-osgi.jar. Specifically, it loads the javax.xml.bind.JAXBContext class from the rt.jar; instead of the one included in jaxb-api-osgi.jar.

That is, I would like the referenced library jaxb-api-osgi.jar to have precedence over the rt.jar

This configuration in settings.json doesn`t helps:

{
    "java.project.referencedLibraries": [
        "lib/**/*.jar",
        "c:\PROYECTOS\Librerias\glassfish4\jaxb-api-osgi.jar"
    ],
    "java.jdt.ls.java.home": "C:\Instalados\Java\jdk8u192-b12"
}

2

Answers


  1. Chosen as BEST ANSWER

    The contribution is very interesting. I have learned a lot from it.

    But, it hasn't worked for me.

    However, I put the details of the changes here because I'm sure it will help someone.

    I finally got everything working for me from a clean workspace using Maven projects.

    (I give the answer as good because of the detail of it, and because surely I was missing something to do correctly).

    settings.json:

    {
        "java.project.sourcePaths": ["src"],
        "java.project.outputPath": "bin",
        "java.project.referencedLibraries": {
            "include": [
                "lib/**/*.jar",
                "C:\PROYECTOS\Librerias\glassfish4\jaxb-api-osgi.jar",
            ],
            "exclude": [
                "C:\Instalados\Java\jdk8u192-b12\jre\librt.jar"
            ]
        }
    }
    

    launch.json:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "java",
                "name": "Current File",
                "request": "launch",
                "mainClass": "${file}"
            },
            {
                "type": "java",
                "name": "Main",
                "request": "launch",
                "mainClass": "tirea.sfe.facturae.Main",
                "projectName": "SFEAAPP_bcc312b8",
                "vmArgs": "-Xbootclasspath/p:${workspaceFolder}/facturae/lib/jaxb-api-osgi.jar"
            }
        ]
    }
    

    • Add exclude to exclude rt.jar library under java.project.referencedLibraries configuration.

      Example settings.json

      "java.project.referencedLibraries": {
          "include": [
              "library/**/*.jar",
              "/home/username/lib/foo.jar"
          ],
          "exclude": [
              "library/sources/**"
          ]
      }
      
    • Add the following configuration to vmArgs in launch.json to add the jaxb-api-osgi.jar library to the boot classpath of the JVM with a higher priority than the default boot classpath (which includes rt.jar)

      // Modify the path to your actual jaxb-api-osgi.jar path
      "-Xbootclasspath/p:${workspaceFolder}/lib/jaxb-api-osgi.jar"
      

      Note: The launch.json file will only be referenced by using Starting Debugging or Run Without Debugging or executing the file in the Run and Debugging panel.

      enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search