有人知道是否可以在Maven存储库中找到源jar吗?


当前回答

Maven存储库确实提供了下载jar源代码的简单方法。

我将使用“spring-boot-actuator-autoconfigure”的演示来解释它。

Go to maven repository - https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-actuator-autoconfigure The page lists various versions. Click-on to desired one, let's say, 2.1.6.RELEASE - https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-actuator-autoconfigure/2.1.6.RELEASE The page have link "View All" next to "Files". Click it - https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-actuator-autoconfigure/2.1.6.RELEASE/ The page lists various files including the one for sources - https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-actuator-autoconfigure/2.1.6.RELEASE/spring-boot-actuator-autoconfigure-2.1.6.RELEASE-sources.jar

否则,你总是可以“git克隆”从github的回购,如果它在那里,并获得特定的代码。

正如其他人解释的那样,您可以使用“mvn dependency:sources”命令获取并生成您正在使用的依赖项的sources jar。

注意:有些依赖项没有sources.jar,因为这些依赖项不包含源代码,只包含一个pom文件。例如spring-boot-starter-actuator。 在这个例子中:

初学者pom是一组方便的依赖描述符,可以包含在应用程序中。您可以获得所需的所有Spring和相关技术的一站式商店,而不必寻找示例代码和复制粘贴依赖描述符负载。

参考:Spring引导启动器介绍

其他回答

如果你正在使用eclipse,你也可以打开Preferences > Maven并选择下载Artifact Sources,这将使pom.xml保持完整,并将你的源代码或java文档(如果选中)保存在你的机器位置~/.m2中进行开发

为了调试,你也可以使用“Java反编译器”,如:JAD,并在运行中反编译源代码(尽管生成的源代码永远不会与原始源代码相同)。然后将JAD作为插件安装到Eclipse或您喜欢的IDE中。

在eclipse中-点击项目然后:

.

Maven Micro-Tip: Get sources and Javadocs When you're using Maven in an IDE you often find the need for your IDE to resolve source code and Javadocs for your library dependencies. There's an easy way to accomplish that goal. mvn dependency:sources mvn dependency:resolve -Dclassifier=javadoc The first command will attempt to download source code for each of the dependencies in your pom file. The second command will attempt to download the Javadocs. Maven is at the mercy of the library packagers here. So some of them won't have source code packaged and many of them won't have Javadocs. In case you have a lot of dependencies it might also be a good idea to use inclusions/exclusions to get specific artifacts, the following command will for example only download the sources for the dependency with a specific artifactId: mvn dependency:sources -DincludeArtifactIds=guava

来源:http://tedwise.com/2010/01/27/maven-micro-tip-get-sources-and-javadocs/

文档:https://maven.apache.org/plugins/maven-dependency-plugin/sources-mojo.html

如果您想手动找到任何工件的源jar文件,请转到特定工件的maven存储库位置,并在Files中单击“view All”。你可以找到源jar文件。