Code running in Netbeans but not in command line - java

I downloaded the time series classification toolbox available here that I succeed to run with Netbeans (not with Eclipse due to compatibility problems) using the command
netbeans --jdkhome /usr/lib/jvm/java-1.8.0-openjdk-amd64/
I would like to be able to run it on a server so I need to be able to run it using command lines.
However I didn't succeed. My guess is that there is a problem with jdk (I'm not used to Java so it might be something else), since when I run
sudo update-alternatives --config java
I get
There are 5 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 auto mode
1 /usr/bin/gij-4.8 1048 manual mode
2 /usr/bin/gij-4.9 1049 manual mode
3 /usr/bin/gij-5 1050 manual mode
* 4 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
5 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 manual mode
Which does not contains the path to the jdk I use with Netbeans.
I didn't find a way to tell Java that I wanted to use another jdk, so I tried without:
Example where I run a specific main file
From TimeSeriesClassification/src:
javac timeseriesweka/classifiers/LearnShapelets.java
java -cp ../bin:. timeseriesweka.classifiers.LearnShapelets
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: TechnicalInformation
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: TechnicalInformation
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
Any help on how to set up correctly Java will be appreciated
With (following the answer of ACV)
java -cp ../bin/Test.jar:lib/*:. timeseriesweka.classifiers.LearnShapelets
Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: java/lang/invoke/StringConcatFactory
at timeseriesweka.classifiers.LearnShapelets.main(LearnShapelets.java:746)
Caused by: java.lang.NoClassDefFoundError: java/lang/invoke/StringConcatFactory
... 1 more
Caused by: java.lang.ClassNotFoundException: java.lang.invoke.StringConcatFactory
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)
... 1 more

Try this:
-cp "../bin/Test.jar:lib/*:." instead of your:
-cp ../bin:.

Related

Running java code on Linux, and the code is written in IntelliJ in windows and CPLEX libraries are used, as well as I got input data from txt filex

I have a problem to run my java code on Linux. I wrote the code in IntelliJ on windows environment and it works. The code needs CPLEX libraries and I get data from txt files. Now, I want to run this code on Linux, but I got these errors:
Exception in thread "main" java.lang.NoClassDefFoundError: ilog/concert/IloException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:650)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
Caused by: java.lang.ClassNotFoundException: ilog.concert.IloException
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
I compiled the code first, and then run it. I do not know how can I run my code. Could you help me please?
for compiling the code I used this command:
javac -classpath /opt/ibm/ILOG/CPLEX_Studio128/cplex/lib/cplex.jar /home/../MIP_Case1/src/MIP.java
Thank you so much for your help.

Error : java.lang.NoClassDefFoundError: org/apache/zookeeper/KeeperException while invoking a java class from a jar

I am trying to schedule a cron job, which will run a java class out of a jar created using maven.
I am able to run the program in IDE (IntelliJ IDEA) but when I try to run the same using terminal using below command it is throwing error.
Command I am using to run the class :
/usr/bin/java -cp zookeeper-util-1.0.0-SNAPSHOT.jar com.myapp.services.app.zk.ZKDeleteJob
Error I am getting :
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/zookeeper/KeeperException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.zookeeper.KeeperException
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
I read another answer here where it is suggested to add following export HBASE_CLASSPATH=/usr/local/hbase-0.94.1/lib but I do not see this folder in my system, still I able to run the program from IDE.
Please help me resolve this.

Uiautomatorviewer SWT exception

Since StackExchange advised me to not ask for help or clarification on a previously existing post, I am making a new thread.
On Windows 10x64 I downloaded the Eclipse SWT (in second-to-last section of Downloads page), set my ANDROID_SWT environment variable to <download location>\swt.jar, and have attempted to run uiautomatorviewer from cmd again, only to receive the same error message as when I tried to use the SWT bundled with eclipse:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Listener
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Listener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Has anyone else encountered this error, and if so, what was the root cause?
Thanks in advance for your time and help!
In my case adding ANDROID_SWT to environment variables or editing PATH didn't solve the problem. Therefore I found a different solution via help from this question.
Running uiautomatorviewer.bat and output :
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Control
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:650)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Listener
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
Solution :
Go to : https://www.findjar.com/ and search for missing class.
In this case search for class :
org.eclipse.swt.widgets.Control
For your case it is:
org.eclipse.swt.widgets.Listener
Names of the classes in the error can change, but all the classes needed comes from .jar file that will be downloaded.
In the results click :
[CLASS] org.eclipse.swt.widgets.Control
or for your case :
[CLASS] org.eclipse.swt.widgets.Listener
Download latest and suitable file for your OS. This was the latest and suitable for Windowsx86_64 currently.
Put downloaded .jar file into :
C:\Users\{userId}\AppData\Local\Android\Sdk\tools\lib
or equivalent path for your OS.
Now uiautomatorviewer.bat should run without any problems.
Make sure JDK location selected in Android studio is same as JDK set in environment variable.
In my case the exception was
Exception in thread "main" java.lang.NoClassDefFoundError:
org/eclipse/swt/custom/TableTreeItem
at org.eclipse.jface.util.OpenStrategy.initializeHandler(OpenStrategy.java:270)
at org.eclipse.jface.util.OpenStrategy.<init>(OpenStrategy.java:108)
at org.eclipse.jface.viewers.StructuredViewer.hookControl(StructuredViewer.java:1213)
at org.eclipse.jface.viewers.ColumnViewer.hookControl(ColumnViewer.java:68)
at org.eclipse.jface.viewers.AbstractTreeViewer.hookControl(AbstractTreeViewer.java:1452)
at org.eclipse.jface.viewers.TreeViewer.hookControl(TreeViewer.java:274)
at org.eclipse.jface.viewers.TreeViewer.<init>(TreeViewer.java:137)
at org.eclipse.jface.viewers.TreeViewer.<init>(TreeViewer.java:124)
at com.android.uiautomator.UiAutomatorView.<init>(UiAutomatorView.java:361)
at com.android.uiautomator.UiAutomatorViewer.createContents(UiAutomatorViewer.java:66)
at org.eclipse.jface.window.Window.create(Window.java:431)
at org.eclipse.jface.window.Window.open(Window.java:790)
at com.android.uiautomator.UiAutomatorViewer.main(UiAutomatorViewer.java:78)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.custom.TableTreeItem
at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 13 more
Steps followed for the solution
Go to https://jar-download.com/
Search for the missing jar file in my case it was org.eclipse.swt.custom.tabletreeitem
Download the jar file compatible with your system Mac/Win/Linux (In my case it was mac
enter image description here
Extract the jar file and copy it
Go to the lib folder inside SDK (Android/Sdk/Tools/Lib
Paste the jar file into the lib folder
Restart your terminal or cmd
Run the command again for cd $ANDROID_HOME/tools/bin
Run the command ./uiautomatorviewer
Alternatively
Try to download the swt jar file with a different version and copy it to the respective folders.
Follow this thread :
https://github.com/android/android-test/issues/911#issuecomment-849389068
Precisely follow these instructions. I made the mistake of trying to download the Eclipse SWT in order to troubleshoot other issues I was having; setting this different SWT version in the CLASSPATH and ANDROID_SWT environment variables caused this exception.

Running java program using packages in multiple folders

I'm trying to run a program with the following structure:
+src
+gui
-XL.java
-moreFiles.java
+menu
-guiFiles.java
+util
-utilFiles.java
+extra
-extraFiles.java
I'm trying to compile the code by calling
javac gui/XL.java
Which succeeds.
When I try running the code with
java gui.XL
I get the following error message:
Exception in thread "main" java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: java/lang/invoke/StringConcatFactory
at gui.XL.<init>(XL.java:25)
at gui.XL.main(XL.java:58)
Caused by: java.lang.NoClassDefFoundError: java/lang/invoke/StringConcatFactory
... 2 more
Caused by: java.lang.ClassNotFoundException: java.lang.invoke.StringConcatFactory
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)
... 2 more
I guess I have some problems with my classpath but I have no clue about how to fix it. Does anyone have any suggestions?
My problem had nothing to do with classpaths or that I wasn't using an IDE. My problem came from the fact that I was changing the 'java' command to run my java-openjdk-8 but my compiler still ran with java-openjdk-9. The solution was therefore
sudo update-alternatives --config javac #Change to java 8
sudo update-alternatives --config java #Change to java 8

Error running spoon on Ubuntu 14.04 64 bit

I am using Spoon tool of Pentaho data integration for long and it was working fine on my system. But since i moved it to /opt I am unable to run again . I have Oracle Java 8 installed on my system and each time try to run it i am end up with following exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Composite
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2688)
at java.lang.Class.getMethod0(Class.java:2937)
at java.lang.Class.getMethod(Class.java:1771)
at org.pentaho.commons.launcher.Launcher.main(Launcher.java:149)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Composite
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
please help me to resolve this error i haven't found any solution yet
I found a solution to this problem I have removed all hidden directories generated by Kettle as well as its copy from /opt . Then I have extracted new version copy . after that I have added /opt/data-integration to my path variable and I have tried to run it from my home . Although it was not a successful run but it has generated all those dependent hidden folders required to run it . then I have to go to that directory by issuing
cd /opt/data-integration
and then I was successful to run it by issuing
sh spoon.sh
I have to go to that directory because Pentaho developers has set it so by placing relative path to launcher folder in their main command at spoon.sh.

Categories

Resources