question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for m2e source attachement on specific maven dependency

See original GitHub issue

Support 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
  1. add a maven dependency that doesn’t have source attached. (for exemple a system one whose systemPath only points to a .jar file)
  2. 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:

Screenshot from 2020-03-04 13-13-02

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:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
fbriconcommented, Mar 4, 2020

Have you tried to right click on a decompiled class: screen shot 2018-11-13 at 7 05 33 pm

See https://github.com/redhat-developer/vscode-java/issues/233#issuecomment-438486647

0reactions
ltorokcommented, Nov 30, 2022

@fbricon This is functional, but images not rendered. See my screenshot: image

Source is attached from my local file src.zip, in JavaDoc is img as:

...
 <p>The above example will produce the following:</p>
 <p><img src="doc-files/Application.png" alt="A black circle in the top left
 corner of scene"></p>
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Get source jar files attached to Eclipse for Maven-managed ...
For existing dependencies, I browsed in package explorer down to the "Maven Dependencies" and right-clicked on commons-lang-2.5.jar, selected Maven | Download ...
Read more >
Apache Maven Dependency Plugin – Introduction
The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified...
Read more >
Re: [m2e-users] Dependency Plugin - Artifact has not ... - Eclipse
plugins:maven-dependency-plugin:2.8:copy:default:process-sources)" >>> >>> This seems to be a problem with the resolution in the plugin and not >>> with my POM.
Read more >
Maven JAR Artifiact Dependency Search Not Working in Eclipse
If you have fresh workspace, just try creating a Maven project then option it's pom.xml file and go to Eclipse GUI (don't open...
Read more >
Setup CZT in Eclipse - Community Z Tools
The Maven integration with Eclipse (m2e) project aims to provide first-class Apache Maven support in Eclipse IDE. However, it also aims to participate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found