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


当前回答

如果你知道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/

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

其他回答

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

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

在Eclipse中

右键单击pom.xml 选择Run As -> Maven generate-sources 默认情况下,它将在.m2文件夹中生成源代码

Pre-Requisite:

Maven应该使用Eclipse进行配置。

如果你知道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/

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

如果一个项目创建了一个项目源代码的jar,并将其部署到maven存储库中,那么你会发现它:)

仅供参考,源构件通常是由maven-source-plugin创建的。这个插件可以将项目的主要或测试源绑定到jar存档中,如配置源插件中所述:

(…)生成的jar文件将由finalName的值加上“-sources”(如果它是主要源代码)来命名。否则,它将是finalName加上“-test-sources”(如果它是测试源)。

附加的文本用来描述一个工件(这里是“-sources”或“-test-sources”)称为分类器。

要声明对使用分类器的工件的依赖,只需添加<classifier>元素。例如:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate</artifactId>
  <version>3.2.7.ga</version>
  <classifier>sources</classifier>
</dependency>

注意,您通常不会这样做,大多数ide都支持从主工件下载源(和/或JavaDoc),而无需显式地声明对它们的依赖。

最后,还要注意一些存储库搜索引擎允许使用分类器搜索工件(至少Nexus支持高级搜索)。请看这个搜索的例子。