简体   繁体   中英

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:

compile files('org/springframework/batch/spring-batch-excel/0.5.0-SNAPSHOT/*.jar') and adding the mavenLocal() repository

But I don't know how to actually use this jar in my java code. Copying the config from here: https://github.com/spring-projects/spring-batch-extensions/blob/master/spring-batch-excel/README.md doesn't work. 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. How do I make it do that?

The jar file contains src/main/java/org/springframework/batch/item/excel/[useful things]

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)

You're mixing up some things:

  1. Adding the mavenLocal() repository has absolutely no impact on file dependencies (like the one you specified). 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() .

  2. The files(...) method does not allow wildcards, so in your example it searches for a file with the exact name *.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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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