0

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
  • 2
    I would recommend using an IDE (netbeans, InelliJ or Eclipse) to get started and let it manage all this for you. In the IDE, create a library called JAnsi (or whatever you want to call it), add the JAR, Javadoc and source to the library in the appropriate tabs then add your new library to your project. Having said that, it looks like your are using Windows. Did you open a new command prompt when you modified your "envirables"? The envirables are only read from "Settings" when you open a new command prompt. – GMc May 15 '19 at 02:26
  • I am using Windows, but no I literally opened the setting inside of the TextPad text editor to change the environment, I never opened the command prompt to change or modify the environment. I am actually not even too sure what you mean by "Setting" in a command prompt... Do you mean like the properties of the command prompt? – Leonardo Duenes May 18 '19 at 02:43
  • 1
    You mentioned * 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 you do that, you must exit and restart all of your command prompts for the change to take effect. Also, do not include the % signs in the variable name. Alternatively in the command prompt, you can simply enter ```set CLASSPATH=C:\Users\Leonardo\Jansi\jansi-1.17.1.jar;%CLASSPATH%``` but you will have to do this every single time you open a new CMD prompt. – GMc May 18 '19 at 07:46
  • Oh wow... ok so I guess the only issue I had was that I was naming it with the % sign. Now it's working thank you for your help! – Leonardo Duenes May 23 '19 at 00:27
  • 1
    sometimes it is the littlest thing. can you upvote my reply that heped you and perhaps answer your own question to close it off - you will earn reputation points for doing so. – GMc May 23 '19 at 03:06

1 Answers1

2

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.