I tried GCJ and it compiled fine. I tried both for Ubuntu and windows. The compiled file is running on my Ubuntu machine as well the .exe with wine. But if I tried to run in on my Ubuntu server I got this error:
error while loading shared libraries: libgcj.so.14: cannot open shared object file: No such file or directory
But I thought I would not need to install anything to run "native" code. I also could not run the .exe on a windows machine.
Could you please tell me why this is happening? Maybe I'm compiling wrong. I use this: gcj --main=Hello -o hello.exe Hello.jar for windows.
When you run an executable it is very common to need a shared library, whether you use Visual Studio .NET or Java or C++.
When you compile a program for a specific platform, it usually only works on that platform or similar. If you want to run this program on Windows, you need to compile it for windows.
BTW GCJ is pretty old and out of date. I suggest you use Java 7 or 8. This will avoid the need to install additional libraries and will run on Windows or Linux without re-compiling.
Related
I have a jar file 'myApp.jar' that I need to run through command line. When I run the jar on linux server it working perfect. However, when I tried to the same jar on mac terminal I am getting this error message:
Exception in thread "main" java.lang.UnsatisfiedLinkError: while loading kognac-core: Stream closed
at karmaresearch.vlog.VLog.loadLibrary(VLog.java:72)
at karmaresearch.vlog.VLog.<clinit>(VLog.java:22)
at org.semanticweb.rulewerk.reasoner.vlog.VLogReasoner.<init>(VLogReasoner.java:82)
at org.semanticweb.rulewerk.client.picocli.MyApp.someMethod(MyApp.java:150)
at org.semanticweb.rulewerk.client.picocli.MyApp.main(MyApp.java:110)
The command that I used to run the jar is:
java -jar myApp.java
The jar file is compiled and created by javaSE-1.8 through Eclipse on Mac.
The java version of Linux server is openjdk version "1.8.0_292"
The java versions on Mac are 3: Java SE 11.0.1(default version) , 1.8.0_202, 1.8.0_201 by these commands:
/Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/bin/java -jar myApp.java
/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home/bin/java -jar myApp.java
I tried to run the jar file on mac with all 3 java versions, but still getting the same error above.
How could I resolve this error on Mac terminal?
The problem isn't related to your app or how you run it.
Your app uses the karmaresearch project which I'm not familiar with (possibly, that's your own code, that you / your team wrote?) and this code attempts to load a so-called native library: These are libraries compiled straight for the OS/architecture your JVM is running on top of.
These take the form of a .jnilib file on mac, .dll on windows, and .so on linux and other posix-based OSes.
Native libraries are incredibly convoluted to ship: You need 1 such file for each combination of OS and underlying architecture. So, these days, you'd need at a minimum to make a reasonable claim that you're 'portable':
Mac AAarch64
Mac x84
Windows x64
Linux AArch64
Linux x64
Linux x32
BSD x64
and that's just a bare bones minimum.
These files cannot be inside the jar when you load them. The usual procedure is to obtain a location you can write to and load code out of (tricky), unpack the right file for the host OS to this folder, and then loadLibrary it. This is all very complicated. In general, either [A] you wrote karmaresearch and you need to think long and hard about using native libraries first, and if you truly need it, follow a tutorial, or [B] it's not your code, in which case you can't run this on a mac, at all, and there's nothing you can do about that, other than contact the makers of this library and ask them to add support for this.
I have installed the java runtime in the window subsystem for Linux (Ubuntu), and the Vscode is installed on the windows 10 system.
I did not install java runtime in windows 10 system. When I use vscode to edit java, it usually pop up a notice says the "java runtime could not be located".
I have point the vscode "java.home" to the java jdk directory of window subsystem linux file folder, which is C:\\Users\\Myusername\\AppData\\Local\\Packages\\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\\LocalState\\rootfs\\usr\\lib\\jvm\\. In the folder, it has:
java-8-openjdk-amd64 directory, and three files
.java-1.8.0-openjdk-amd64.jinfo,
default-java
java-1.8.0-openjdk-amd64.
But however, the vscode still pop out the notice that the java.home variable defined in VS Code settings does not point to a JDK.
Can anyone let me know how to set up the vs code properly so that it can locate the JDK file in the window subsystem for Linux (WSL)?
Thanks in advance.
It won´t work like this because you are trying to use a jdk builded for linux on windows.
It is the same as if you download the jdk for linux and try to execute on windows.
As for the solution, unfortunately there is no solution right now.
However you can call your java and javac directly on terminal using WSL
wsl javac
You can´t point the java_home using wsl.
Maybe in the future the guys from Microsoft can make the trick. I hope so.
When I open adt-bundle-windows-x86_64-20131030 and click on the Eclipse.exe application to install it I get the message; A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java Virtual Machine was found after searching the following locations: C:\users\username\desktop\development\adt-bundle-windows-x86_64-20131030\eclipse\jre\bin\javaw.exe
javaw.exe is your current PATH.
I do have JDK, and JRE on this computer, I need them to view the emulator for my job. I have tried uninstalling and reinstalling Java with the same results. What can I do to fix this problem?
You will have to put Java in your classpath, so Eclipse knows where it can find Java. See here: http://docs.oracle.com/javase/tutorial/essential/environment/paths.html for info on how to do this.
install 32 bit version of jdk from oracle website
put the path of your java bin directory under Environment variables.
System->Advanced System Settings->Environment Variables->path
Open command prompt. use java and javac commands to know if you have successfully installed java and compiler.
if it doesn't help, this question has a lot of helpful answers
Eclipse - no Java (JRE) / (JDK) ... no virtual machine
From what you said:
"'java' is not recognized as an internal or external command, operable program or batch file"
Your java may not have been installed correctly, or, it was installed, but you did not set path to it correctly. It is not a problem with ADT, any of your programs that need Java will not be able to find it.
So I have the latest version of JRE 7 on my computer, and everything is working fine. Lately, I've downloaded a program that requires JRE 6. I know where all of the files are located on my computer, all I'm asking is the .bat file code to run a specific version of Java with only that program. I am somewhat of a newbie when it comes to Windows and Java PATH structure, so
Stanford's computer science course has you use a modified version of Eclipse to code in Java, and it was created when Java was still in version 6. If you are familiar with this, then you may know of karel the robot, a Java application that opens in Eclipse. When I tried to run this, the Karel program did not appear; only a blank screen. I found a youtube video about using Karel and many of the people in the comments had been having this problem, and some said that using JRE 6 fixed it. Also on the installation instructions, it said to use JRE 1.6, but I thought it would work with JRE 7
you can call each java.exe directly.
You can create 2 batch file named java6.bat and java7.bat :
java6.bat
#echo off
"C:\Program Files\Java\jre6\bin\java.exe" %*
java7.bat
#echo off
"C:\Program Files\Java\jre7\bin\java.exe" %*
to call a program with jre6
java6 -jar helloworld.jar
and to call a program with jre7
java7 -jar helloworld.jar
If you mean this program then I had no problem launching it with java 7
However if you really need java 6 for operating it then you could write some .bat file like this:
#echo off
set JAVA_HOME=C:\oracle\jdk1.6
set MY_CLASSPATH=lib\karelj.jar;lib\silk.jar
%JAVA_HOME%\bin\javaw.exe -cp %MY_CLASSPATH% karel.swingui.Main
I have JRE 6 in my PC (Windows XP) but when I compile a program in the command prompt it shows javac is not recognised as internal or external command. Which software is needed to compile a Java program?
You need to download and install a JDK, not a JRE.
As a (very rough) explanation, the JRE contains just the Java Virtual Machine, whereas the JDK contains not only the JRE but also the compiler (javac), some debugging tools (javap, jvisualvm, ...), extra libraries and the API documentation.
See also:
What is the difference between JRE and JDK?
as recommended by dogbane, you can follow the Java Hello World for Windows Tutorial.
I suggest you run through the steps of the Hello World! Tutorial.
As per the instructions:
Download JDK6. (Make sure you download the JDK, not the JRE.)
Update the PATH variable to be able to conveniently run the JDK executables such as javac from any directory without having to type the full path of the command
JRE stands for Java Runtime Environment. It allows you to run already compiled java programs. To compile your own programs, you need JDK which stands for Java Development Kit. You can download it at JDK Downloads Page.
You need to install JDK-6 (Java Development Kit) which contains javac Java compiler. JRE does not contain it.
Instead of a simple JRE, you'll need a full JDK. As an example, youc an download sun one here : http://www.oracle.com/technetwork/java/javase/downloads/index.html#need (and don't forget to select "download JDK").
JDK is needed to develop applications whereas JRE is enough to run applications.
In other words JRE is enough to run a application (i.e) it includes java.exe and doesnot contain javac.exe
JDK contains both java.exe and javac.exe
There are also other chances that you dint set your class path properly.