beryx / text-io

A library for creating interactive console applications in Java
http://text-io.beryx.org/
Apache License 2.0
342 stars 45 forks source link

Making System console as default instead of JLint based console. #5

Closed manikmagar closed 7 years ago

manikmagar commented 7 years ago

I am building a console application using text-io in intellij ide. I have added text-io:2.7.2 dependency in pom. I am creating terminal as TextIO textIO = TextIoFactory.getTextIO(). When I run this application in IDE, it opens a JLint based terminal.

Then I am using maven-shade plugin to create an uber jar. When I run this jar on mac terminal, it is throwing below error -

Exception in thread "main" java.lang.NoClassDefFoundError: javafx/scene/paint/Color
    at org.beryx.textio.jline.JLineTextTerminal.<clinit>(JLineTextTerminal.java:64)
    at org.beryx.textio.jline.JLineTextTerminalProvider.getTextTerminal(JLineTextTerminalProvider.java:32)
    at org.beryx.textio.TextIoFactory$Holder.getDefaultTerminal(TextIoFactory.java:95)
    at org.beryx.textio.TextIoFactory$Holder.<init>(TextIoFactory.java:65)
    at org.beryx.textio.TextIoFactory$Holder.<clinit>(TextIoFactory.java:54)
    at org.beryx.textio.TextIoFactory.getTextIO(TextIoFactory.java:111)
    at com.javastreets.jeegen.Main.main(Main.java:12)
Caused by: java.lang.ClassNotFoundException: javafx.scene.paint.Color
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 7 more

I want to use the standard console/terminal, how to default the TextIOFactory to use console instead of JLint.

Using below gets me what I wanted but just wondering if there is better way of doing that with TextIOFactory -

TextIO textIO = new TextIO(new ConsoleTextTerminalProvider().getTextTerminal());

And, thanks for this cool libarby 👍 !

siordache commented 7 years ago

It seems that your Java runtime does not include JavaFX. Although Text-IO does not currently provide a JavaFX terminal, it uses the class javafx.scene.paint.Color to configure the colors of JLine and Swing terminals via properties.

I think the best solution is to make JavaFX available to your Java runtime and let the TextIoFactory choose the appropriate terminal type. (If you use OpenJDK, you will have to install OpenJFX.)

Another option is to force the use of a console terminal when running the program on your mac, by setting the system property org.beryx.textio.TextTerminal: -Dorg.beryx.textio.TextTerminal=org.beryx.textio.console.ConsoleTextTerminal

manikmagar commented 7 years ago

You are correct, I am using OpenJDK, I am not having FX in my runtime.

If I am building a tool which would be installed by others, I do not control what runtime they have. They may have similar setup like me. If javafx.scene.paint.Color is the only dependent class from JavaFX, may be there are other options to remove that dependency, unless there is JavaFX terminal.

For now, forcing terminal to be console or system seems to be the best option.

Thanks for the update.

siordache commented 7 years ago

I released the version 2.7.3, which should fix this issue. Please give it a try.

manikmagar commented 7 years ago

Hi @siordache, I changed the version to 2.7.3 and reverted TextIO initialization to -

TextIO textIO = TextIoFactory.getTextIO();.

Now, the application is properly running on the terminal, without FX, as expected. Thanks for quickly resolving it. I think this can be closed now.