简体   繁体   English

在mavenLocal()中为.jar文件成功添加gradle依赖关系之后,我实际上如何从Java类导入和使用该jar

[英]After successfully adding a gradle dependency for a .jar file in mavenLocal(), how do I actually import and use that jar from a java class

Using mvn install I have a jar file that I can compile with gradle using the dependency: 使用mvn install我有一个jar文件,可以使用依赖项使用gradle进行编译:

compile files('org/springframework/batch/spring-batch-excel/0.5.0-SNAPSHOT/*.jar') and adding the mavenLocal() repository compile files('org/springframework/batch/spring-batch-excel/0.5.0-SNAPSHOT/*.jar')并添加mavenLocal()存储库

But I don't know how to actually use this jar in my java code. 但是我不知道如何在我的Java代码中实际使用这个jar。 Copying the config from here: https://github.com/spring-projects/spring-batch-extensions/blob/master/spring-batch-excel/README.md doesn't work. 从此处复制配置: https : //github.com/spring-projects/spring-batch-extensions/blob/master/spring-batch-excel/README.md不起作用。 The link gives the import lines 该链接提供了导入行

import org.springframework.batch.item.excel.mapping.PassThroughRowMapper;
import org.springframework.batch.item.excel.poi.PoiItemReader;

But Intellij has a problem finding the .excell directory, which is where the files in the jar add new things to the spring framework, which tells me that it's not looking in the jar I added. 但是Intellij在查找.excell目录时遇到问题,该目录是jar中的文件向spring框架添加新内容的地方,这告诉我它不在我添加的jar中。 How do I make it do that? 我如何做到这一点?

The jar file contains src/main/java/org/springframework/batch/item/excel/[useful things] jar文件包含src / main / java / org / springframework / batch / item / excel / [有用的东西]

I also generated metadata for intelliJ after maven install with maven idea:idea but I don't know where to put the two files it created (.iml and .ipr) 在使用maven idea:idea安装maven idea:idea之后,我还为intelliJ生成了元数据,但我不知道将创建的两个文件(.iml和.ipr)放在哪里。

You're mixing up some things: 您正在混淆一些事情:

  1. Adding the mavenLocal() repository has absolutely no impact on file dependencies (like the one you specified). 添加mavenLocal()存储库绝对不会影响文件依赖性(如您指定的文件依赖性)。 It allows you to import dependencies you've installed via mvn install as external dependencies by specifying their classifier ( <group>:<id>:<version> ), the same way you import dependencies from mavenCentral() or jcenter() . 通过指定它们的分类器( <group>:<id>:<version> ),它允许您将通过mvn install依赖项作为外部依赖项导入,与从mavenCentral()jcenter()导入依赖项的方式相同。

  2. The files(...) method does not allow wildcards, so in your example it searches for a file with the exact name *.jar . files(...)方法不允许使用通配符,因此在您的示例中,它搜索的文件名为*.jar Also, since you provide a relative path, it starts with this relative path from the project directory. 另外,由于您提供了相对路径,因此它从项目目录中的该相对路径开始。 You can either pass the correct and exact paths of all required files as consecutive arguments to the files(...) method or use a fileTree to specify a base directory and a name with wildcards. 您可以将所有必需文件的正确路径和精确路径作为连续参数传递给files(...)方法,也可以使用fileTree指定基目录和带通配符的名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM