如何在Gradle中导入外部依赖项? [英] How to import external dependencies in gradle?

查看:106
本文介绍了如何在Gradle中导入外部依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是Java开发的新手.我在Eclipse中使用gradle.

New to java development here. I'm using gradle in eclipse.

我想导入JSONParser.在我的代码中,我有:

I want to import the JSONParser. In my code I have:

    import org.json.simple.parser.JSONParser;

在build.gradle中,我有:

and in build.gradle I have:

repositories {

    mavenCentral()
}

dependencies {

    compile 'com.googlecode.json-simple:json-simple:1.1.1'


}

但是,当我尝试构建时,我得到了:

However, when I try to build I get:

int/MainApp.java:7: error: cannot find symbol
import org.json.simple.parser;
                      ^
  symbol:   class parser
  location: package org.json.simple
1 error

这是怎么回事?我想我不完全了解gradle的工作原理.

What's going on here? I think I don't understand exactly how gradle works.

推荐答案

如果您将jar文件放在一个文件夹中,例如在根目录下的lib文件夹中,则将以下内容添加到gradle版本中

If you have the jar files in a folder, for example in the lib folder in root directory, add the following to your gradle build

dependencies 
{
compile files('libs/something_local.jar')
}

这篇关于如何在Gradle中导入外部依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆