[英]Setting up a classpath for Jansi
I've been trying to use Jansi for the first time on a Java program, but I can't import org.fusesource.jansi.AnsiConsole and get an error saying that this package does not exist.我第一次尝试在 Java 程序上使用 Jansi,但是我无法导入 org.fusesource.jansi.AnsiConsole 并收到一个错误,说这个包不存在。
I downloaded the latest Jansi version under C:\\Users\\Leonardo\\Jansi where the jansi-1.17.1.jar is (I do not know if you have to do anything with this file after that or not).我在 jansi-1.17.1.jar 所在的 C:\\Users\\Leonardo\\Jansi 下下载了最新的 Jansi 版本(我不知道你之后是否需要对这个文件做任何事情)。 The text editor I am using for the program is TextPad and I know that to use Jansi I have to manually add it to its environment variables.
我用于该程序的文本编辑器是 TextPad,我知道要使用 Jansi,我必须手动将其添加到其环境变量中。 I tried doing with by going into
我试着通过进入
Configure > Preferences > Environment Variables
and adding a new variable named: %CLASSPATH%
with the value: C:\\Users\\Leonardo\\Jansi\\jansi-1.17.1.jar;%CLASSPATH%;
Configure > Preferences > Environment Variables
并添加一个named: %CLASSPATH%
的新变量,其value: C:\\Users\\Leonardo\\Jansi\\jansi-1.17.1.jar;%CLASSPATH%;
If anyone has any experience with TextPad and Jansi I would appreciate any help you could give me.如果有人对 TextPad 和 Jansi 有任何经验,我将不胜感激您能给我的任何帮助。 I am also open to switching to a different text editor or ide if someone has used Jansi with another program.
如果有人将 Jansi 与另一个程序一起使用,我也愿意切换到不同的文本编辑器或 ide。 Below is the sample code I've been using to see if I set it up correctly, no luck so far.
下面是我一直在使用的示例代码,看看我是否正确设置了它,到目前为止还没有运气。
import org.fusesource.jansi.AnsiConsole;
public class JansiDemo{
public static final String CLS = "\u001b[2J\u001b[1;1H";
public static final String RED = "\u001b[31;1m";
public static final String GREEN = "\u001b[32;1m";
public static final String YELLOW = "\u001b[33;1m";
public static final String BLUEONWHITE = "\u001b[34;47m";
public static void main(String[] args){
AnsiConsole.systemInstall();
System.out.println(RED + "apple " + YELLOW + "banana " + GREEN + "pepper");
System.out.println(BLUEONWHITE + "this is blue on white" + NORMAL);
}
}
This is what the console outputs when I compile it:这是我编译时控制台输出的内容:
E:\game.java:2: error: package org.fusesource.jansi does not exist import org.fusesource.jansi.AnsiConsole;
E:\game.java:16: error: cannot find symbol AnsiConsole.systemInstall();
symbol: variable AnsiConsole
location: class game
2 errors
Tool completed with exit code 1
To set up a classpath in Textpad (I am using version 8.1.2) you have to download the .jar file first and then go to into Configure > Preferences... > Environment Variables > New.要在 Textpad 中设置类路径(我使用的是 8.1.2 版),您必须先下载 .jar 文件,然后进入配置 > 首选项... > 环境变量 > 新建。 Then set name:CLASSPATH and the value to the directory of the .jar file in my case value: C:\\Users<User_Name>\\Jansi\\jansi-1.17.1.jar;%CLASSPATH%;
然后将 name:CLASSPATH 和值设置为 .jar 文件的目录在我的情况下值:C:\\Users<User_Name>\\Jansi\\jansi-1.17.1.jar;%CLASSPATH%; After this hit Ok and Apply and restart any command prompt you have open to save any changes.
在此之后点击 Ok 和 Apply 并重新启动您打开的任何命令提示符以保存任何更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.