When opening a class included through a Maven dependency, Eclipse tells me that the containing .jar
file has got no source attachment.
But in the directory in which the .jar
file resides, there is also as corresponding -sources.jar
file.
Do you have any hints regarding the solution of this problem?
Is there a way to tell Eclipse where it should automatically look for the source attachment?
Edit: In the Eclipse .classpath
file, the sourcepath
value is set for external archives, but not for ours. But both jar
s and sources file reside in the same repo.
The property -Declipse.useProjectReferences=false
is also set.开发者_如何学编程
The problem was that there were already sources.jar-not-available
files for certain projects in my local repository.
I've deleted them and now the attachment of source files is working. Obviously Eclipse respectively the Maven Eclipse plugin doesn't look for source attachments as long as these marker files exist.
If it hadn't been for the comment from K. Claszen I'd have never came up with this solution.
Check that you have downloadSources in the maven-eclipse-plugin section of your pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
...
</configuration>
</plugin>
If you are using m2eclipse plugin for integrating Maven projects in Eclipse, you might need to enable downloading sources and javadocs in m2eclipse preferences:
Window > Preferences > Maven > Download Artifact Sources
For me the file was in place in local repo and eclipse (4.5) kept complaining there is no associated source jar (sources.jar-not-available
did not existed). I ended up removing the directory from local repo, letting eclipse to download the sources again repolulating the repo, running mvn eclipse:eclipse
and refreshing the project.
For me all these steps was necessary to get this working.
For those who are still having trouble downloading sources for your Maven dependencies (like me), you can try this alternate method:
- Find the particular Maven dependency you wished to inspect Java source code for. You need to have the Maven artifact name.
- Next, navigate to the Maven repository server where you download the Maven dependency from. For example, I have
spring-security-core-5.5.1.jar
as my Maven dependency. The repository host site is frommvnrepository.com
, in which the repository server is fromhttps://repo1.maven.org/maven2/
. - Navigate to
mvnrepository.com
and search for your Maven dependency artifact. In my case, it would bespring-security-core
, and I located the artifact information page here. - On this page, in the table row labeled Files, you want to click on
View All
, on the right of the JAR link with how many kilobytes displayed to the side. (Underlined)
- Once you're viewing the list of all JARs provided with the Maven dependency, click and download the one that says,
[artifact name]-[artifact version]-sources.jar
. In my case, it'sspring-security-core-5.5.1-sources.jar
. - Once downloaded, on your local machine, use your File Explorer to navigate to the folder containing the artifact JAR which you have trouble downloading the source codes for. In my case, it would be
$MAVEN_HOME/repository/org/springframework/security/spring-security-core/5.5.1
. - Move the
[artifact name]-[artifact version]-sources.jar
into this folder. - Go back into Eclipse, and try attaching the sources. You should be able to pick up the
...-sources.jar
file upon attaching it.
After attaching it, you will then be able to see the source codes for your Maven dependency.
Right click at project, select Maven, select Download Sources.
I download a maven project from online,use mvn eclipse:eclipse converted to eclipse project then I occurred the problem.
solution is remove all external lib that start with 'M2_REPO',it's work for me.
精彩评论