简体   繁体   中英

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.

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). 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. 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%; If anyone has any experience with TextPad and Jansi I would appreciate any help you could give me. I am also open to switching to a different text editor or ide if someone has used Jansi with another program. 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. 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%; After this hit Ok and Apply and restart any command prompt you have open to save any changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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