简体   繁体   English

由于.jar文件,IntelliJ程序无法在终端中编译

[英]IntelliJ program won't compile in terminal due to .jar file

I have used the more student-oriented IDE DrJava before, and did not have trouble running programs dependent on .jar files in the terminal/command line. 我以前使用过面向学生的IDE DrJava,并且在终端/命令行中运行依赖于.jar文件的程序没有遇到麻烦。

Right now I am writing a simple program to find eigenvalues of matrices in IntelliJ, and although I have followed the steps listed in the stack overflow question "Importing jar file into IntelliJ Idea?" 现在,我正在编写一个简单的程序,以在IntelliJ中查找矩阵的特征值,尽管我已按照堆栈溢出问题“将jar文件导入IntelliJ Idea中?”中列出的步骤进行操作。 to add the .jar file I am using as a dependency, I am getting errors like this when I try to compile the program in terminal: 添加我正在使用的.jar文件作为依赖项,当我尝试在终端中编译程序时遇到如下错误:

javac eigenvalues.java
eigenvalues.java:11: error: package Jama does not exist
import Jama.*;
^

and etc. (more errors of the form such-and-such does not exist). 等等(不存在其他形式的错误)。

My program has multiple classes and I only need the .jar file for one of them. 我的程序有多个类,其中一个只需要.jar文件。

The program compiles fine within intelliJ, just not from terminal. 该程序可以在intelliJ中很好地编译,而不是从终端编译。

You can make it work by two ways: 1. You can try by putting the required JAR in the ext folder: Below is the path to ext folder, then try to compile. 您可以通过两种方式使其工作:1.您可以通过将所需的JAR放在ext文件夹中进行尝试:以下是ext文件夹的路径,然后尝试进行编译。

On Linux Systems -    /urs/lib/JDK/jre/lib/ext/

On Windows Systems- C:/Program Files/Java/jdk..0.1/jre/lib/ext/
  1. You can add the path of that required jar to the CLASSPATH system variable also. 您也可以将所需jar的路径添加到CLASSPATH系统变量中。

  2. You can compile the program by dynamically providing the classpath with javac command as below: 您可以通过使用javac命令动态向classpath提供以下内容来编译程序:

     javac -classpath "<Path to the JAR>" YourProgram.java 

    There is a very good link on the classpath . 类路径上有一个很好的链接。

Hope It may work. 希望它可能会起作用。

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

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