有人知道是否可以在Maven存储库中找到源jar吗?
当前回答
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
其他回答
你可以,如果他们被上传。通常它们被称为“frameworkname-version-source(s)”
如果你知道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支持高级搜索)。请看这个搜索的例子。
如果你正在使用eclipse,你也可以打开Preferences > Maven并选择下载Artifact Sources,这将使pom.xml保持完整,并将你的源代码或java文档(如果选中)保存在你的机器位置~/.m2中进行开发
如果您想手动找到任何工件的源jar文件,请转到特定工件的maven存储库位置,并在Files中单击“view All”。你可以找到源jar文件。
推荐文章
- 在流中使用Java 8 foreach循环移动到下一项
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- c#和Java中的泛型有什么不同?和模板在c++ ?
- 在Java中,流相对于循环的优势是什么?
- Jersey在未找到InjectionManagerFactory时停止工作
- 在Java流是peek真的只是调试?
- Recyclerview不调用onCreateViewHolder
- 将JSON字符串转换为HashMap