Repository navigation
Wrong classpath at runtime when the maven project is in a folder #584
Description
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:
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
-
import projects:
https://gitlab.com/ba-demos/dmn-insurance/insurance-decision
https://gitlab.com/ba-demos/dmn-insurance/kie-client -
install decision project
cd insurance-decision
mvn clean install- running the client from maven, it works as expected
mvn clean exec:java- Launch vscode inside
kie-clientproject:
- execute
client.EmbedMain - the program runs with no error
- Launch vscode in the parent folder of the
kie-clientproject:
- 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
minkir014 commentedon May 19, 2019
What's your
launch.json? Please show it.dmarrazzo commentedon May 19, 2019
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.
minkir014 commentedon May 20, 2019
If the project folder name is
kie-client.So set
mainClasssetting tokie-client/client.EmbedMainandproject Nameto{workspace}/kie-client.dmarrazzo commentedon May 20, 2019
Hi Mina Fawzy (@minkir014) ,
I think that it's not a config problem, but a bug.
Even because
launch.jsonis 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
dmarrazzo commentedon May 20, 2019
Hi Jinbo Wang (@testforstephen), could you please give your opinion on this issue?
Thank you
testforstephen commentedon May 21, 2019
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.
dmarrazzo commentedon May 21, 2019
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:
testforstephen commentedon May 21, 2019
i can reproduce it. Looks like it doesn't add the dependencies of the referenced maven project
insurance-decisionto the runtime classpaths. This is a bug.dmarrazzo commentedon May 21, 2019
Hi Jinbo Wang (@testforstephen) , I look forward to see it solved :-)
Thank you very much for your help!
dmarrazzo commentedon Jun 3, 2019
Hi! Any plan for solving this bug?
Thank you
testforstephen commentedon Jun 3, 2019
should be fixed in the next release 0.20.0
5 remaining items
dmarrazzo commentedon Jun 12, 2019
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!
testforstephen commentedon Jun 12, 2019
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
testscope, this is the same root cause for these two issues.Finally, it should have same behavior as
eclipseandmvn exec:java.runtimescope.testscope.dmarrazzo commentedon Jun 12, 2019
Thank you very much. I will wait the next release and confirm the final resolution!
Great job!
minkir014 commentedon Jun 12, 2019
When will you intend to fix that issue #556 and subsequently this issue??
testforstephen commentedon Jun 14, 2019
The fix is on the way.
spulci commentedon Jun 20, 2019
Jinbo Wang (@testforstephen) have you got a release date? Thanks
testforstephen commentedon Jun 27, 2019
Simone Pulcini (@spulci) i plan to have a release earlier next week.
testforstephen commentedon Jul 2, 2019
A new release is ready in vscode marketplace. Have a try!
//Simone Pulcini (@spulci) Donato (@dmarrazzo) Mina Fawzy (@minkir014)
dmarrazzo commentedon Jul 2, 2019
it works for me! Cool. Thank you so much
spulci commentedon Jul 2, 2019
Thank you so much!! Great release!! Works fine! ;)
emmanuelBayle commentedon Jul 4, 2019
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
testforstephen commentedon Jul 4, 2019
emmanuelBayle could you share a sample project to help reproduce the issue?
emmanuelBayle commentedon Jul 4, 2019
Jinbo Wang (@testforstephen) not easily, I'll try to make you one.