Support for m2e source attachement on specific maven dependency
See original GitHub issueSupport for m2e source attachement on specific maven dependency as it is possible in Eclipse.
Environment
- Operating System: Linux x64 5.3.0-40-generic
- JDK version: openjdk version “1.8.0_242”
- Visual Studio Code version: 1.42.1
- Java extension version: 0.57.0
Steps To Reproduce
- add a maven dependency that doesn’t have source attached. (for exemple a
system
one whosesystemPath
only points to a.jar
file) - try to find a way to manually attach the source to this specific dependency
Here is the project where I am running into this issue. It is not that easy to setup so I’m not sure if it will be of a great help: https://github.com/Atlaoui/ParallelProgramingInterface
Current Result
// Failed to get sources. Instead, stub sources have been generated by the disassembler.
// Implementation of methods is unavailable.
Expected Result
Sources correctly load and can be used for debugging.
Additional Informations
Eclipse has this particular ability to manually attach sources to maven dependencies:
But this action doesn’t modify the .classpath
so it must be managed at a higher level. I tried to find a way to manually edit the .classpath
to add the sources of a dependency in the m2e
con
classpathentry
with no succes.
I also tried to set a lib
classpathentry
with a sourcepath
field in addition to the m2e
one by adding:
<classpathentry kind="lib" path="peersim-1.0.5/peersim-1.0.5.jar" sourcepath="peersim-1.0.5/src"/>
This makes the source fetching working while developing but then I can’t use vscode to run or debug the application as the classes are defined two times in my classpath. Here is the error I am getting from PeerSim in my specific project:
peersim.config.IllegalParameterException: Parameter "protocol.transport": The class peersim.transport.UniformRandomTransport appears more than once in the classpath; please check your classpath to avoid duplications.
Then I tried to exclude a dependency from the m2e
container to sole this issue but I couldn’t find a way to do so.
Here is my final .classpath
:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<!-- <classpathentry kind="lib" path="peersim-1.0.5/peersim-1.0.5.jar" sourcepath="peersim-1.0.5/src"/> -->
<!-- <classpathentry kind="lib" path="openmpi-4.0.2/ompi/mpi/java/java/mpi.jar" sourcepath="openmpi-4.0.2/ompi/mpi/java/java/mpi-src.zip"/> -->
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Conclusion
What I am looking for is either a way to configure the .classpath
according to my need, but I didn’t find the way to do so. Or a new feature in vscode-java to attach source on Maven dependencies like in eclipse.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top GitHub Comments
Have you tried to right click on a decompiled class:
See https://github.com/redhat-developer/vscode-java/issues/233#issuecomment-438486647
@fbricon This is functional, but images not rendered. See my screenshot:
Source is attached from my local file src.zip, in JavaDoc is img as: