简体   繁体   English

如何将.jar文件添加到IntelliJ IDEA Java项目中?

[英]How do I add a .jar file into an IntelliJ IDEA Java project?

I have a java project loaded into IntelliJ IDEA. 我有一个Java项目加载到IntelliJ IDEA中。 The code requires JDBC and so I downloaded and unzipped the sqljdbc_6.4.0.0_enu file into the recommended directory, "C:\\Program Files\\Microsoft JDBC Driver 6.4 for SQL Server". 该代码需要JDBC,因此我下载了sqljdbc_6.4.0.0_enu文件并将其解压缩到推荐的目录“ SQL Server的C:\\ Program Files \\ Microsoft JDBC Driver 6.4”中。 This creates the jar files: 这将创建jar文件:

  • mssql-jdbc-6.4.0.jre7.jar mssql-jdbc-6.4.0.jre7.jar
  • mssql-jdbc-6.4.0.jre8.jar mssql-jdbc-6.4.0.jre8.jar
  • mssql-jdbc-6.4.0.jre9.jar mssql-jdbc-6.4.0.jre9.jar

in the directory, "C:\\Program Files\\Microsoft JDBC Driver 6.4 for SQL Server\\sqljdbc_6.4\\enu". 在目录“ SQL Server的C:\\ Program Files \\ Microsoft JDBC驱动程序6.4 \\ sqljdbc_6.4 \\ enu”中。 And so, now, how do I make use of all this in my project in IntelliJ IDEA? 因此,现在,如何在IntelliJ IDEA的项目中利用所有这些? And if I later put all my java code into Git Hub, how can I ensure that another user will have code that will compile and link? 而且,如果以后将所有Java代码放入Git Hub中,如何确保其他用户将拥有可以编译和链接的代码? Will I have to include the .jar file in Git Hub somehow? 我是否需要以某种方式将.jar文件包含在Git Hub中?

you should not do this. 你不应该这样做。 For your case, you can choose one of them: 对于您的情况,可以选择以下之一:

  1. create lib foder into project folder - put .jar files in the folder- setup module with library point to the folder - commit metadata folder of IDEA such as .idea, {projectName}.iml (not recommend) 在项目文件夹中创建lib foder-将.jar文件放在文件夹中-库设置模块指向该文件夹-提交IDEA的元数据文件夹,例如.idea,{projectName} .iml(不推荐)

  2. The best solution is using maven or Gradle, you are able to put the dependencies which are neccessary into pom.xml file. 最好的解决方案是使用maven或Gradle,您可以将必需的依赖项放入pom.xml文件中。 (Recommend) (推荐)

You can refer this for adding external jar files in IntelliJ IDEA. 您可以参考文件以在IntelliJ IDEA中添加外部jar文件。

As for GitHub, you can put your jar files there by removing *.jar from .gitignore configuration file. 对于GitHub,您可以通过从.gitignore配置文件中删除* .jar来放置jar文件。 However this is not a recommended practice to have JAR files in repository as they've considerable size. 但是,建议不要在存储库中包含JAR文件,因为它们的大小很大。 You can consider using some build tool(maven or gradle) to add external dependencies. 您可以考虑使用某些构建工具(Maven或Gradle)添加外部依赖项。

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

相关问题 在 IntelliJ IDEA 中创建 Java Gradle 项目并构建 .jar 文件 - 如何? - Creating a Java Gradle project and building the .jar file in IntelliJ IDEA - How to? 如何从 Intellij 创意项目制作可执行文件? - How do I make an executable file from an intellij idea project? 如何解决 IntelliJ IDEA 中 Java 文件的依赖冲突? - How do I resolve dependency conflict for a Java file in IntelliJ IDEA? 如何在 Intellij Idea 中为 Spring Boot 项目构建 jar 文件? - How to build jar file for Spring Boot project in Intellij Idea? 将JAR文件添加到Intellij Idea时为空库 - Empty Library when I add JAR file to Intellij Idea 如何在intellij IDEA中为Java项目添加单元测试? - How to add unit tests to Java project in intellij IDEA? 如何将现有的IntelliJ Java项目添加到git? - How do I add an existing IntelliJ Java project to git? 如果pom.xml不在根级别,如何将Maven项目添加到intellij想法中 - How do I add maven project into intellij idea if pom.xml is not in the root level Intellij IDEA:如何将单个类文件添加到项目 - Intellij IDEA: How to add single class file to project IntelliJ IDEA中的java Maven项目,如何找到不需要的依赖项? - java Maven Project in IntelliJ IDEA, How do I find unneeded dependencies?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM