Skip to content

Wrong classpath at runtime when the maven project is in a folder #584

Closed
microsoft/java-debug
#281

Description

@dmarrazzo

Launching vscode in the maven root folder, the debug is able to manage correctly the classpath.
Whereas when vscode is launched in the parent folder (that contains more maven projects) it fails to execute the project due to a wrong classpath evaluation.
In order to debug, I've added those lines at the beginning of the main:

        try {
            Class.forName("org.drools.compiler.commons.jci.readers.ResourceReader");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        ClassLoader cl = EmbedMain.class.getClassLoader();

        URL[] urls = ((URLClassLoader) cl).getURLs();

        for (URL url : urls) {
            System.out.println(url.getFile());
        }

The output (attached) shows that the classpath is significantly different:

parent.txt

inner.txt

Linked issue:

redhat-developer/vscode-java#925

Environment
  • Operating System: Linux Fedora 30

  • JDK version: penjdk version "1.8.0_212"
    OpenJDK Runtime Environment (build 1.8.0_212-b04)
    OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)

  • Visual Studio Code version: 1.34

  • Java extension version: 0.44.0

  • pref
    "java.home": "/usr/lib/jvm/java-1.8.0-openjdk/",
    "java.jdt.ls.vmargs": "-noverify -Xmx3G -Xss128M -XX:+UseG1GC -XX:+UseStringDeduplication",

Steps To Reproduce
  1. import projects:
    https://gitlab.com/ba-demos/dmn-insurance/insurance-decision
    https://gitlab.com/ba-demos/dmn-insurance/kie-client

  2. install decision project

cd insurance-decision
mvn clean install
  1. running the client from maven, it works as expected
mvn clean exec:java
  1. Launch vscode inside kie-client project:
  • execute client.EmbedMain
  • the program runs with no error
  1. Launch vscode in the parent folder of the kie-client project:
  • open and execute the class: client.EmbedMain
Current Result

Loading failed because Cannot create instance of class:

org.kie.pmml.assembler.PMMLAssemblerService
Exception in thread "main"
java.lang.ExceptionInInitializerError
	at org.kie.api.internal.utils.ServiceRegistry.getInstance(ServiceRegistry.java:27)
ServiceRegistry.java:27
	at org.kie.api.KieServices$Factory$LazyHolder.<clinit>(KieServices.java:341)
	at org.kie.api.KieServices$Factory.get(KieServices.java:348)
(...)
Expected Result

it runs with no error and completes with:

(...)
DMNResultImpl{context={
    PreviousIncidents: false
    Age: 28
    CarAge: 3
    Insurance Base Price: 1000
    Car reliability factor: function Car reliability factor( car age )
    FinalPrice: 1100.0
}
, messages=org.kie.dmn.core.util.DefaultDMNMessagesManager@102d92c4}

Activity

  1. minkir014 commented on May 19, 2019

    @minkir014

    What's your launch.json? Please show it.

  2. dmarrazzo commented on May 19, 2019

    @dmarrazzo
    Author

    Here you are, the same in both cases:

    {
        "configurations": [
            {
                "type": "java",
                "name": "CodeLens (Launch) - EmbedMain",
                "request": "launch",
                "mainClass": "client.EmbedMain",
                "projectName": "kie-client"
            }
        ]
    }

    Thank you for looking into it.

  3. minkir014 commented on May 20, 2019

    @minkir014

    If the project folder name is kie-client.
    So set mainClass setting to kie-client/client.EmbedMain and project Name to {workspace}/kie-client.

  4. dmarrazzo commented on May 20, 2019

    @dmarrazzo
    Author

    Hi Mina Fawzy (@minkir014) ,
    I think that it's not a config problem, but a bug.
    Even because launch.json is generated by vscode and works fine for other similar projects with the same structure!
    Nevertheless, I tested your suggestions:

    {
        "configurations": [
            {
                "type": "java",
                "name": "CodeLens (Launch) - EmbedMain",
                "request": "launch",
                "mainClass": "kie-client/client.EmbedMain",
                "projectName": "${workspaceFolder}/kie-client"
            }
        ]
    }

    It leads to: Path for project must have only one segment.

    If you want to try on your own you can find the instruction to reproduce the problem in the first description.

    Thank you

  5. dmarrazzo commented on May 20, 2019

    @dmarrazzo
    Author

    Hi Jinbo Wang (@testforstephen), could you please give your opinion on this issue?
    Thank you

  6. testforstephen commented on May 21, 2019

    @testforstephen
    Contributor

    i tried to clone these two sample projects into a parent folder dmn-insurance, and open it in VS Code, there are many unresolved maven dependencies org.kie.x.

    btw, it may be better to use a parent pom.xml to manage the modules when you open a parent folder with multiple maven projects in VS Code.

  7. dmarrazzo commented on May 21, 2019

    @dmarrazzo
    Author

    Hi Jinbo Wang (@testforstephen) , thank you for reviewing my problem.
    Those projects are not modules, kie-client depends on the other one.
    I'd like to get a functional parity with eclipse where I can have in the same workspace multiple unrelated projects (at least more than 1): for this reason I cannot create a parent pom.

    Maybe you need to add Red Hat maven repo to resolve all the dependencies:

        <profile>
          <id>jboss-ga-profile</id>
          <repositories>
            <repository>
              <id>jboss-ga-repository</id>
              <url>https://maven.repository.redhat.com/ga/</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>false</enabled>
              </snapshots>
            </repository>
          </repositories>
          <pluginRepositories>
            <pluginRepository>
              <id>jboss-ga-plugin-repository</id>
              <url>https://maven.repository.redhat.com/ga/</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>false</enabled>
              </snapshots>
            </pluginRepository>
          </pluginRepositories>
        </profile>
  8. testforstephen commented on May 21, 2019

    @testforstephen
    Contributor

    i can reproduce it. Looks like it doesn't add the dependencies of the referenced maven project insurance-decision to the runtime classpaths. This is a bug.

  9. dmarrazzo commented on May 21, 2019

    @dmarrazzo
    Author

    Hi Jinbo Wang (@testforstephen) , I look forward to see it solved :-)
    Thank you very much for your help!

  10. dmarrazzo commented on Jun 3, 2019

    @dmarrazzo
    Author

    Hi! Any plan for solving this bug?
    Thank you

  11. testforstephen commented on Jun 3, 2019

    @testforstephen
    Contributor

    should be fixed in the next release 0.20.0

  12. 5 remaining items

  13. dmarrazzo commented on Jun 12, 2019

    @dmarrazzo
    Author

    Hi Jinbo Wang (@testforstephen) ,
    thank you for the explanation.
    So can I assume that when you will solve #566 it will address even my issue?
    IMHO, the debugger should provide the same behaviour at runtime (same classpath) either the project is in the workspace root or it's at subfolder level, at least other IDEs work in this way.
    I think that having multiple maven projects in the workspace and running them in isolation is an important feature: I'm not sure if this is already the goal of vscode-java-debug. I hope so!

  14. testforstephen commented on Jun 12, 2019

    @testforstephen
    Contributor

    YES, Fix #566 will solve this issue, too. The debugger mistakenly excludes the shared dependencies by multiple projects if one of them marks it as test scope, this is the same root cause for these two issues.

    Finally, it should have same behavior as eclipse and mvn exec:java.

    • Run a main class in src/main/java, exclude test classes and include all dependencies with runtime scope.
    • Run class in src/test/java, add test scope.
  15. dmarrazzo commented on Jun 12, 2019

    @dmarrazzo
    Author

    Thank you very much. I will wait the next release and confirm the final resolution!
    Great job!

  16. minkir014 commented on Jun 12, 2019

    @minkir014

    When will you intend to fix that issue #556 and subsequently this issue??

  17. testforstephen commented on Jun 14, 2019

    @testforstephen
    Contributor

    The fix is on the way.

  18. spulci commented on Jun 20, 2019

    @spulci

    Jinbo Wang (@testforstephen) have you got a release date? Thanks

  19. testforstephen commented on Jun 27, 2019

    @testforstephen
    Contributor

    Simone Pulcini (@spulci) i plan to have a release earlier next week.

  20. testforstephen commented on Jul 2, 2019

    @testforstephen
    Contributor

    A new release is ready in vscode marketplace. Have a try!

    //Simone Pulcini (@spulci) Donato (@dmarrazzo) Mina Fawzy (@minkir014)

  21. dmarrazzo commented on Jul 2, 2019

    @dmarrazzo
    Author

    it works for me! Cool. Thank you so much

  22. spulci commented on Jul 2, 2019

    @spulci

    A new release is ready in vscode marketplace. Have a try!

    //Simone Pulcini (@spulci) Donato (@dmarrazzo) Mina Fawzy (@minkir014)

    Thank you so much!! Great release!! Works fine! ;)

  23. emmanuelBayle commented on Jul 4, 2019

    @emmanuelBayle

    Hello, since the last update all dependencies with a 'classifier' are no longer included in the classpath when I try to debug my app.
    My current workarround is to directly add the desired jar in the .classpath of my sub-module but it's not ideal.
    I didn't have problems with the 0.19.0 version

  24. testforstephen commented on Jul 4, 2019

    @testforstephen
    Contributor

    emmanuelBayle could you share a sample project to help reproduce the issue?

  25. emmanuelBayle commented on Jul 4, 2019

    @emmanuelBayle

    Jinbo Wang (@testforstephen) not easily, I'll try to make you one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions