简体   繁体   English

如何将JAR文件添加到现有gradle项目?

[英]How to add a JAR file to an existing gradle project?

I have a jar file for Aspose Cells for Java that I want to add to an existing Gradle project in IntelliJ IDEA 2017.2.1. 我有一个用于Java的Aspose Cells的jar文件,我想将其添加到IntelliJ IDEA 2017.2.1中的现有Gradle项目中。

If I go to View -> Tool Windows -> Gradle , I see the gradle window like so but I don't know what to click. 如果我去查看->工具窗口-> Gradle ,我会看到gradle窗口,但是我不知道要单击什么。 I tried right-clicking on Dependencies but nothing happened. 我尝试右键单击“ 依赖项”,但没有任何反应。 Should I click the + sign? 我应该点击+号吗? I think not. 我想不是。

在此处输入图片说明

How do I do that? 我怎么做?

  1. Is it okay to add it the non-gradle way, ie by clicking File -> Project Structure -> Dependencies tab -> + sign? 可以以非渐进方式添加它吗,即通过单击文件->项目结构->依赖项选项卡-> +符号?

  2. What is the gradle way of doing it? gradle的方式是什么? Where do I find the build.gradle file to edit? 在哪里可以找到要编辑的build.gradle文件? I could see it a few commits earlier but I am having a hard time finding my way around the IDE. 我可以较早地看到一些提交,但是我很难在IDE中找到自己的出路。 I can see the build.gradle file in Windows explorer. 我可以在Windows资源管理器中看到build.gradle文件。 Should I edit it by hand outside of the IDE? 我应该在IDE之外手动编辑它吗?

compile files('/<ABSOLUTE_PATH>/<DEPENDENCY>.jar')
or
//put jar file in lib directory of project.
compile fileTree(dir: 'lib', includes: ['*.jar']) }

How to add Jar in existing project in Intellij 如何在Intellij中的现有项目中添加Jar

  1. Goto File->project structure-> Libraries tab -> + sign? 转到文件->项目结构->库选项卡-> +符号?
  2. Select Java from the list 从列表中选择Java
  3. Select jar file from file system 从文件系统中选择jar文件
  4. Choose apply and ok 选择应用并确定

How to add dependency in gradle project 1. If your project is gradle project it will have build.gradle in root path of project. 如何在gradle项目中添加依赖项 1.如果您的项目是gradle项目,它将在项目的根路径中具有build.gradle。 2. Open build.gradle and add it in the dependencies block in required decencies. 2.打开build.gradle并将其按要求的十进制添加到依赖关系块中。 3. Make sure that repositories for libraries should be already included. 3.确保已经包含库的存储库。 (Usually if library is on mavenCentral then it should be like mavenCentral() ) (通常,如果库位于mavenCentral上,则应该像mavenCentral()一样)

You can also add the directory to the repositories{} and simply add the jar as every other. 您还可以将目录添加到repositories{}并且只需将jar彼此添加即可。

repositories {
   flatDir {
       dirs 'path/to/your/dir'
   }
}

then 然后

dependencies {
   compile name: 'yourJar'
}

BTW: If you take it from GitHub it should be published to some repo I presume. 顺便说一句:如果您从GitHub上获得它,它应该发布到我认为的某些仓库中。

What about this one? 这个如何? Aspose.Cells 的Aspose.Cells

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

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