I'm in CentOS 6.3 and I'm attempting to recompile a .java file using the ant command however I'm getting these two results.
When I run ant:
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: org.apache.tools.ant.launch.Launcher. Program will exit.
When I run sudo ant:
Error: JAVA_HOME is not defined correctly.
We cannot execute java
When I run *echo $JAVA_HOME*:
/usr/lib/jvm/java-1.6.0-openjdk/
Before anyone suggests that I should be using the JRE instead of the JDK, I just need to mention that my installation manual for the software I'm running - OpenGTS - specifically requests the JDK. Any ideas as to what I'm doing wrong?
Thanks in advance.
ant is script to launch a java program. It appears that script could not figure out a value for ANT_HOME. On linux the script tries to load /etc/ant.conf which reset the ANT_HOME. Your symptoms does not match, but it is worth checking.
Quote from site
The cause of this is that there is an old version of ant somewhere in
the class path or configuration.
A version of this problem may be seen on some linux systems. Some
linux systems (Fedora Core 2 for example), comes with a version of ant
pre-installed. There is a configuration file called /etc/ant.conf
which if present, the ant shell script will 'dot' include. On Fedora
Core 2, the /etc/ant.conf file resets the ANT_HOME environment
variable to /usr/share/ant. This causes the problem that an old
version of ant (1.5.x in this cause) will be used with a new version
of the ant script file.
One can check if this is the case by doing ant --noconfig -version.
Related
So this error is a weird one...
I'm using EXE4J 6 to build a .exe file for my JavaFX Application. This has worked with no issues through Java version 13.0.1. I recently upgraded my environment to use Java 14.0.1 and now I get the following stacktrace whenever I try to run my application through exe:
java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.InternalError: platform encoding not initialized
at java.base/java.net.Inet6AddressImpl.getLocalHostName(Native Method)
at java.base/java.net.InetAddress.getLocalHost(Unknown Source)
at org.apache.logging.log4j.core.util.NetUtils.getLocalHostname(NetUtils.java:54)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:612)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:691)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:708)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:243)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:174)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:669)
This error happens when trying to initialize my Log4J logging. however if I just made a direct call to InetAddress.getLocalHost() I can replicate this error out of .exe. Running my application directly out of my Eclipse (EE 06/2020) works just fine. After doing some debugging. I determined that removing Java from my PATH allowed the application to run. My .exe4j configuration file is set up so that the application should look for a separate Java 14 jre and not attempt to use my PATH for java.
<searchSequence>
<directory location="../java/jre64" />
</searchSequence>
The jre64 is built through ANT using the 14.0.1 jdk that I have and only importing the modules I need. Again, this all worked through 13.0.1 prior to my upgrade to 14.0.1
From research and testing on other computers, I think this boils down to an environment issue on my computer. However I've run out of places to look. Any thoughts or ideas would be much appreciated. Specifically why EXE4J would try to use the Java on my Path instead of the one in the search sequence.
Other Notes:
Running on Windows 10 Latest Updates
Path points to OpenJDK 14.0.1 (causes break) (java -version is correct in cmd)
I've confirmed that the working exe, after removing java from my Path, is still running on version 14.0.1 through the jre64
Application is built with and Eclipse Workspace/project JRE also points to same OpenJDK 14.0.1
Running on other computers with similar versions & environment works & doesn't cause this issue.
I was finally able to determine what the issue was.
I was using Exe4J 6.0 which was not compatible with Java versions 10+. I was surprised that I wasn't getting outright errors when trying to run exe4j to compile my executable, however it seems that exe4j was sucking in an older 1.8 java version from my registry and using a 1.8 jdk that I never cleaned out of my "C:/Program Files/Java" folder. When I deleted all my old JDKs, exe4j started complaining about missing a Java VM (even though 14.0.1 was set on path).
Upgrading to Exe4J 7.0 solved the issue for me.
In my case the problem was the PATH environment variable pointing to one jre directory.
I had 2 applications in different directories:
Application A had a jre directory included in the PATH environment variable and was working fine.
Application B had another jre directory NOT included in the PATH environment variable and was throwing this error.
After removing this jre directory from the PATH environment variable everything worked ok.
Trying to execute myApp based on ChronicleMap API:
java -jar myApp-00.00.01-SNAPSHOT-jar-with-dependencies.jar
and getting exception.
Exception in thread "main" java.lang.AssertionError: java.lang.ClassNotFoundException: com.sun.tools.javac.api.JavacTool
at net.openhft.chronicle.values.CompilerUtils.reset(CompilerUtils.java:62)
at net.openhft.chronicle.values.CompilerUtils.<clinit>(CompilerUtils.java:51)
at net.openhft.chronicle.values.ValueModel.createClass(ValueModel.java:348)
at net.openhft.chronicle.values.ValueModel.createHeapClass(ValueModel.java:327)
at net.openhft.chronicle.values.ValueModel.heapClass(ValueModel.java:317)
at net.openhft.chronicle.values.Values.heapClassFor(Values.java:68)
at net.openhft.chronicle.values.Values.newHeapInstance(Values.java:37)
at com.twi.lib.ev.ipc.VTORId.<clinit>(VTORId.java:189)
at com.twi.lib.ev.ipc.Ipc.initialize(Ipc.java:294)
at com.twi.lib.ev.base.Preferences.areRequiredPreferencesSet(Preferences.java:356)
at com.twi.lib.ev.base.ApiEv.autoinitialize(ApiEv.java:48)
at com.twi.demo.ev_examples.Main.main(Main.java:116)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.api.JavacTool
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at net.openhft.chronicle.values.CompilerUtils.reset(CompilerUtils.java:58)
... 11 more
Here is my config:
OS Installed: Windows 10
Java Installed: JDK 1.8.0_131
Java Path: C:\Program Files\Java\jre1.8.0_131\bin\javaw.exe
ChronicleMaps tested: 3.10 - 3.13 - same problem for all these versions
MyApp runs fine under Netbeans 8.2 but this exception always comes up if trying to run in command window and command:
java -jar myApp-00.00.01-SNAPSHOT-jar-with-dependencies.jar
What is wrong?
Missing jar library JavacTool ?
Compatibility?
Bug in ChronicleMap?
Thank you for any input for getting myApp running with command:
java -jar myApp.jar
Got it working. Here is how in case someone else struggles with Windows and java configuration.
If you want to run your jar application (with the ChronicleMap API) the standard java way - e.g:
java -jar myApp.jar
you must make sure your executing "java" is the JDK java and not JRE java.
This means you and your app. users will need to have JDK installed on your system
and configured so that the JDK java is used, not the JRE java.
That's been clear to me from beginning, and I thought my system was running
JDK java, but it did not. Here is how I solved it.
In Windows (after you have installed JDK) you may have several locations/folders
specified in your system environment variables as the PATH to java.exe.
In my case I had 3 references to java. You can check that from command line:
where java
My result was:
C:\Program Files\Java\jre1.8.0_131\bin
C:\Program Files\Java\jdk1.8.0_131\bin
C:\ProgramData\Oracle\Java\javapath
As advised by others I added:
JAVA_PATH variable and pointed it to:
C:\Program Files\Java\jdk1.8.0_131
But that did not solve the issue and I was still running JRE, not JDK java.
I also checked the java control panel ("Configure Java" in start menu item).
First of all note that you must run it as administrator or no changes will stick -
that's what Oracle says. But for me after a reboot the settings were all back to
defaults and all my changes gone.
In case it works for you here are the steps:
Windows start menu
right-click "Configure Java"
More > Run as administrator
enter your admin. password
(if you do not see the password window, look for the icon on your task bar)
Java Control panel will appear
select tab: Java
click: View
select tab: System
click: Find and navigate to your java JDK folder - e.g:
C:\Program Files\Java\jdk1.8.0_131\bin
click: Next
you'll see: C:\Program Files\Java\jdk1.8.0_131\bin\javaw.exe
click: Finish
enable the added entry check-box and disable all others
OK, OK
Now, this was supposed to specify my preference of JDK java over JRE java.
But it did not.
So, at the end I removed all references to java in my PATH - Windows system environment variables
except the one for JDK:
C:\Program Files\Java\jdk1.8.0_131\bin
That did it.
#Felix's answer works. But note, if you're currently running in vscode, you'd need to close and reopen it before it works.
I'm trying to install Amazon Mechanical Turk command line tools on Ubuntu 14.04 LTS, using this tutorial. It requires Java, so I installed OpenJDK7. However, when attempting to run the command , I get the following error, which the internet informs me indicates the wrong Java version.
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at com.amazonaws.mturk.service.axis.AWSService.<clinit>(AWSService.java:104)
at com.amazonaws.mturk.cmd.AbstractCmd.initService(AbstractCmd.java:119)
at com.amazonaws.mturk.cmd.AbstractCmd.run(AbstractCmd.java:143)
at com.amazonaws.mturk.cmd.GetBalance.main(GetBalance.java:28)
Some of the documentation for the AMT tools indicates that I need JRE 1.5 (while others say "most recent version"), so I have been trying to install that. Since it's no longer available through apt-get, I downloaded the bin file and installed it at '/home/USERNAME/', (I don't use the machine much and didn't want to deal with sticking it at the end of a long chain of folders, so all my AWS stuff is in there) then put in my AWS keys and set the environment variables:
export JAVA_HOME="/home/USERNAME/jre1.5.0_22"
export MTURK_CMD_HOME="/home/USERNAME/aws-mturk-clt-1.3.1"
Then, checking my balance to make sure everything is configured, as specified in the AWS Getting Started PDF, I still get the same error shown above.
Did I do something wrong when installing JRE 1.5? Is it still using OpenJDK7, or is JRE 1.5 also no good? I'm really at my wit's end here.
It turns out that I am an idiot and installed Java wrong.
Instructions for anyone else having this problem: http://www.webupd8.org/2012/09/install-oracle-java-8-in-ubuntu-via-ppa.html
We are creating a runnable java jar to run on a beagle bone black(running ubuntu).
We have created a runnable jar which runs fine on our mac and pc(windows) but will not run on the ubuntu system. We keep getting the following error when running:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: /home/ubuntu/.jssc/linux/libjSSC-2.6_armhf.so: /home/ubuntu/.jssc/linux/libjSSC-2.6_armhf.so: cannot open shared object file: No such file or directory
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1851)
at java.lang.Runtime.load0(Runtime.java:795)
at java.lang.System.load(System.java:1062)
at jssc.SerialNativeInterface.<clinit>(SerialNativeInterface.java:172)
at jssc.SerialPort.<init>(SerialPort.java:118)
at InputBoard.<init>(InputBoard.java:33)
at InputBoard.main(InputBoard.java:22)
... 5 more
Any information would be greatly appreciated. As I said this runs fine through terminal on a mac which is unix based so it seems it should work on Ubuntu. We have no idea why it is referencing the /home/ubuntu directory. Please let us know if you need any code information on the project but I would not think it would be related.
You are missing a native runtime library. You can install this library by using apt-get to fetch the package it contains. To do this, give this command.
sudo apt-get install libc6-*
I fixed this problem when I installed the latest JDK 8 for Hard float for Arm. Previously I tried several things, I tried using versions 2.6, 2.7 and 2.8, specified LD_LIBRARY_PATH env. variable, making sure that library was in ~/.jssc/linux, etc, etc all this to no avail, only after I upgraded java, it worked flawlessly.
I had this same error even with the latest version. In my case it turned out to be that JSSC was trying to use the "soft float" version of the native libraries that it copies out of the .jar file. I ended up replacing the file with the hard float version from the .jar file and removing write access to the file. Everything started working after that.
I'm attempting to install Weka, which I have installed into /weka directory. I set the CLASSPATH variable, but that shouldn't matter anyway because I'm using -cp.
I enter this into SSH:
java -Xmx5G -cp /weka/weka.jar
weka.core.converters.TextDirectoryLoader -dir /home/myuser/test >
/home/myuser/test.arff
And it spits out:
Exception in thread "main" java.lang.NoClassDefFoundError:
weka/core/converters/TextDirectoryLoader Caused by:
java.lang.ClassNotFoundException:
weka.core.converters.TextDirectoryLoader
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266) Could not find the main class: weka.core.converters.TextDirectoryLoader.
Program will exit.
What wrong? There is no "weka/core/converters/TextDirectoryLoader" because its all stored in weka.jar, which is where it should be looking.
My Java version:
java version "1.6.0_20" OpenJDK Runtime Environment (IcedTea6 1.9.10)
(rhel-1.23.1.9.10.el5_7-x86_64) OpenJDK 64-Bit Server VM (build
19.0-b09, mixed mode)
I just downloaded Weka today from the link on their downloads page, so there shouldn't be anything wrong with it.
Now I know that this would normally be because it can't find weka.jar, but I promise you that it is right there at: /weka/weka.jar. And I can also promise that both the /weka directory and weka.jar have execute permissions.
Please help!
Just downloading and running the .jar works for me:
carsten#dallas:~$ java -Xmx5G -cp /tmp/weka-3-6-5/weka.jar weka.core.converters.TextDirectoryLoader
Usage:
TextDirectoryLoader [options]
Options:
...
as well as java -jar /tmp/weka-3-6-5/weka.jar, which opens some GUI tool.
You sure that you installed Weka on the server you SSH into?
I happened the same to me in Mac OS when I used the jar released in the dmg packaged.
Instead of that one, I imported the jar file under:
Applications/Weka/Resources/java/weka.jar
To get it you have to:
go to Applications
right click over weka-3-x-x
Show package content
go to /Resources/java/weka.jar
import that one jar into your classpath