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


当前回答

IntelliJ idea的maven idea插件允许您指定是否应该解析和下载源代码和java文档

mvn idea:idea -DdownloadSources=true -DdownloadJavadocs=true

其他回答

如果你知道groupId和aritifactId,你可以像这样生成下载url。

    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
        <version>1.2.3</version>
    </dependency>

http://central.maven.org/maven2/ch/qos/logback/logback-classic/

你会得到一个像这样的页面,选择你需要的版本,只是享受它!

我还使用eclipse插件将项目放到eclipse工作区中。 因为我在一个不同的项目中工作过,我发现可以使用eclipse而不使用maven-eclipse-plugin。这使得它更容易在不同的环境中使用,并使maven比eclipse更容易使用。并且不需要更改pom.xml文件。

所以,我推荐加布里埃尔·拉米雷斯的方法。

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引导启动器介绍

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

配置和运行maven-eclipse插件(例如从命令行mvn eclipse:eclipse)

   <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>true</downloadJavadocs>
                </configuration>
            </plugin>
        </plugins>
    </build>