简体   繁体   English

在Gradle项目中使用Apache Commons IO

[英]Using Apache Commons IO in a Gradle project

I'm writing a Java program - a plain command line program, not Android or anything like that - using Gradle, and trying to include Apache Commons IO. 我正在使用Gradle编写Java程序-一个普通的命令行程序,而不是Android或类似的程序-并尝试包含Apache Commons IO。 Per https://mvnrepository.com/artifact/commons-io/commons-io/2.6 I ended up with build.gradle like this: 根据https://mvnrepository.com/artifact/commons-io/commons-io/2.6,我最终获得了build.gradle如下所示:

apply plugin: 'application'
apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    // https://mvnrepository.com/artifact/commons-io/commons-io
    compile group: 'commons-io', name: 'commons-io', version: '2.6'
}

mainClassName = 'Main'

Gradle seems to download the package happily enough, but import statements referring to apache or commons get a not found error; Gradle似乎足够高兴地下载了该软件包,但是引用apachecommons import语句得到了一个未发现的错误。 this is true even when I run gradle build from the command line, omitting any IDE. 即使我从命令行运行gradle build ,而忽略任何IDE,也是如此。 What am I missing? 我想念什么? (Previous similar discussions have been for Android or Eclipse projects; the instructions for those haven't worked here.) (以前的类似讨论是针对Android或Eclipse项目的;这些说明在这里没有用。)

I don't see any problems with your Gradle script, so at first glance, I'm thinking of two possible explanations: 我看不到您的Gradle脚本有任何问题,因此乍一看,我在想两种可能的解释:

  • you import a class that cannot be found in the artifact (eg a previous version of commons-io deprecated it and now they removed it) 您导入了无法在工件中找到的类(例如,commons-io的先前版本已弃用该类,现在他们将其删除了)
  • your project's structure is set up incorrectly 您的项目的结构设置不正确

I copied the exact contents of your script in a build.gradle file, created a src/main/java directory structure in the same directory, and wrote a small application Main.java under that directory with the following: 我将脚本的确切内容复制到build.gradle文件中,在同一目录中创建了src / main / java目录结构,并在该目录下编写了一个小型应用程序Main.java ,内容如下:

import org.apache.commons.io.IOCase;

public class Main {
    public static void main(String[] args) {
        System.out.println(IOCase.SENSITIVE.checkEndsWith("abcd1234", "1234"));
    }
}

The code compiles successfully, so I need more context to troubleshoot your problem. 代码成功编译,因此我需要更多上下文来解决您的问题。

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

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