Visual Studio Code fails to use a library - java

I have project which I need to modify for a task and that runs a terminal with the help of a .jar file. I can run the very same Code on an IDE like Eclipse, but not VSC.
This is the error is get:
The jar files for this project are:
text-io-3.4.0.jar, slf4j-api-2.0.0-alpha5.jar and slf4j-nop-2.0.0-alpha5.jar
Exception in thread "main" java.lang.NoClassDefFoundError: jline/console/ConsoleReader
at org.beryx.textio.jline.JLineTextTerminalProvider.getTextTerminal(JLineTextTerminalProvider.java:28)
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 ch.zhaw.catan.Catan.run(Catan.java:19)
at ch.zhaw.catan.Catan.main(Catan.java:50)
Caused by: java.lang.ClassNotFoundException: jline.console.ConsoleReader
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 7 more
I assume it's about configurations. The path to the library is set within the project. I don't see the error, my professor doesn't use VSC.
What can I do to fix this? Do I need to provide more data? I could upload the files if needed.
-edit
here's a link to the dummy.java and the jar files
https://github.com/dangdung87/test
as for the lines causing the error:
private void run() {
TextIO textIO = TextIoFactory.getTextIO();
TextTerminal<?> textTerminal = textIO.getTextTerminal();

It appears that the textio lib needs the jline library (https://mvnrepository.com/artifact/jline/jline/2.14.6).
Download the jar and add it to the dependencies of the project.
We had the same problem with the catan project ;)

Related

Where can I add javax.media.jai Jar package in Java?

I am getting class not found(javax.media.jai.JAI) exception while running my code. I have downloaded(https://www.oracle.com/java/technologies/java-archive-downloads-java-client-downloads.html#jai-1_1_2_01-oth-JPR) the JAI jar and added in Project lib folder but not working getting same error again. where can I add this jar. Please advise.
Note : The is old servlet project structure there is no Maven features.
Error Log:
java.lang.ClassNotFoundException: javax.media.jai.JAI
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
enter image description here
You can go to build path and add ur external jars by downloading it online.

Error: Could not find or load main class MakePhoneCall Caused by: java.lang.ClassNotFoundException: MakePhoneCall

I am following the Twilio tutorial"How to Make Outbound Calls" Located at this URL: Twilio MakePhoneCall I've copied the code to my InteliJ and then run the program.
I get the following error:Error Code and Java code
Thanks for your assistance in this matter.
It seems you are missing Twillo jar attached to your project.
Try downloading it from Maven Repo and attach to your project classpath.

Why is my IDE looking in the wrong dependency folder for a needed class?

I'm trying to run a script that was working fine until I changed the home folder.
Once I changed the home folder I ran into a few issues but I was able to resolve them. The only thing I have not been able to resolve is the following error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/internal/JsonToWebElementConverter
at BrowserStackAndroid.main(BrowserStackAndroid.java:43)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.internal.JsonToWebElementConverter
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
This is an interesting error that, after some research, I have not been able to wrap my head around.
The class that it is searching for is in the org.selenium.remote dependency. Except that it's not in the internal folder but the remote folder.
So the class that it is searching for is JsonToWebElementConverter.
This class is located in the following path
org/openqa/selenium/remote/JsonToWebElementConverter
The folder that the IDE (or Maven?) is looking into is
org/openqa/selenium/remote/internal
Which only has the class WebElementToJsonConverter
I've tried reinstalling the library via maven in several different ways, using different dependencies, etc but haven't been able to fix this issue.
I've never come across an issue like this before so I'm really excited to see what the solution is going to be.
Notes:
The error is being thrown because of the following line of code
AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("https://" + userName + ":" + accessKey + "#hub-cloud.browserstack.com/wd/hub"), caps);
This project worked perfectly fine before but as soon I changed the directory of the project stopped working.
This is happening as you have same class or library with in 2 dependencies. Simply removing selenium based dependencies will resolve the issue as all selenium dependencies already comes with Appium java client. For classpath you can check at java docs
So the way to set class path via cmd (Navigate to project root folder)
set CLASSPATH= target/org/openqa/selenium/remote/internal/JsonToWebElementConverter
Note: for maven project all compiled java files should be in target folder. If you are facing same issue you can add missing class inclasspath destination should be target folder as explained in java docs

Intellij dynamic classpath loading fails: ClassNotFoundException

Using Intellij 15.0.3 on a Scala project, I am unable to run my scala console.
I added one too many dependencies and Intellij told me "Command line is too long. In order to reduce its length classpath file can be used.Would you like to enable classpath file mode for all run configurations of your project?" I enabled it, whihc sets dynamic.classpath=true in an xml file.
Now when I try to run the console I get
Exception in thread "main" java.lang.ClassNotFoundException: #vm_params
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.intellij.rt.execution.CommandLineWrapper.loadMainClassWithOldCustomLoader(CommandLineWrapper.java:174)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:38)
Googling around I didn't see anyone else have this problem. This feature seems like it should "just work". Is there something else I have to do do get intellij to make a classpath file and send the path to the VM?

Use GDCM in Java - how to include?

I'd like to use GDCM in Java, but somehow I fail using it. I downloaded precompiled files for win x86. I've never tried to include a SWIG library, so I may did something wrong. I tried to include the gdcm.jar in original folder, and as a copy.
What I did(using Netbeans):
Added the gdcm.jar at Project->Properties->Libraries->Compile->Add Jar
Error:
java.lang.reflect.InvocationTargetException
...
Caused by: java.lang.UnsatisfiedLinkError: gdcm.gdcmJNI.swig_module_init()V
at gdcm.gdcmJNI.swig_module_init(Native Method)
at gdcm.gdcmJNI.<clinit>(gdcmJNI.java:2751)
How to correctly use it? Thanks a lot!
You need to add libgdcmjni.jnilib to your library path in java using:
-Djava.library.path="Path to directory that contains libgdcmjni.jnilib"

Categories