I do not wish to change my host's notion of what Java is, only download one or more JDKs including OpenJDK. I need to test and compare JDKs as part of a build system.
Just as I am able to download and then not install Oracle JDK with no problem, I need to download and not install a copy of open JDK. The website http://openjdk.java.net/install/index.html doesn't offer this possibility.
Has anyone found a solution to this?
The easiest way to do that would be to download OpenJDK source code and build it. For 8, it basically boils down to cloning the right set of trees and then doing the regular build steps:
cd /path/to/where/you/cloned/jdk8u
mkdir build
bash ../configure # not ../configure because configure is not marked as executible
make all
Look under build/ and search for a j2sdk-image directory. That's your jdk:
cp -a build/images/j2sdk-image /location/where/i/put/my/jdks/
The distribution packages of OpenJDK often include various changes that make it not suitable for moving around (liked tweaked RPATHs). That said, if you are feeling up to the risk, you can do something like:
yum --download-only install 'java-1.8.0-openjdk*'
Now you have a bunch of RPMs. Extract them manually:
rpm2cpio ./name.of.rpm.x86_64.rpm | cpio -id
You should see usr and other fumnny looking directories in the current working directory. Go through the, find the OpenJDK dir and move it over to some other location. For example:
cp -a usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-1.b16.fc24.x86_64/ /location/where/i/put/my/jdks/
Note that it's usr/, not /usr/. Strip non-$ORIGIN RPATHs if you see on any ELF files.
Something similar probably exists for Debian/Ubuntu, but I am not familiar with them.
Related
I've read a lot of troubleshooting for similar occurrences of this error, but what is causing it for this particular .jar?
https://download.cnet.com/android/nabin-bhandari/3260-20_4-10982661-1.html
It works on Windows, but when attempting to run the file on a raspbian (linux) system running java version 1.8.0_65 with the command java -jar Local\ Area\ Messenger\ Desktop.jar it throws the error about not being able to find or load the main class.
The MANIFEST.MF defines Main-Class: com.nabinbhandari.lam.Main and there doesn't appear to be any issues with case sensitivity.
What am I missing? Do I need to install something more than Java Runtime Environment?
Edit: In case it is not clear, I am not the developer of this file. I am simply a user trying to run the file. This question has nothing to do with Eclipse and I don't understand why people are linking to that other question. I am not running Eclipse. Please stop linking to that. Please examination the .jar file I have provided.
Edit 2: I have followed the instructions and in this answer:
https://stackoverflow.com/a/1238173/2407742
It gives the error no main manifest attribute, in test.jar
Is there something missing from my java runtime environment? It seems like nothing works.
The Local Area Network Messenger application was developed using JavaFX, which is not included in the Oracle Java build for Rasperry Pi. I had to reinstall Java and then openjfx by doing the following:
sudo apt-get purge openjdk-8-jre-headless
sudo apt-get install openjdk-8-jre-headless
sudo apt-get install openjdk-8-jre
sudo apt-get install openjfx
It runs fine now.
The solution to this was the following:
Close Eclipse/STS
Use a file explorer on your operating system to navigate to your workspace (In my case, I'm on Windows so I used Windows Explorer)
Delete the .metadata directory (or to be safe, copy the directory somewhere else to be safe, then delete it)
Restart Eclipse/STS
Is there a more improved answer than this? I don't want to look like I'm trying to boost my own reputation points, so if someone can provide a better answer then please do so.
I need java 1.7 and server has only got 1.6. I have no root privileges. I tried to google out something but it seems like nobody was doing it. Can I somehow compile it or get ready binaries so I could put those into my PATH. Could you help? System is Redhat.
It is quite easy...
Download the JDK as a tarball from Oracle (a simple google search will yield the link).
Unzip it somewhere in your $HOME (for instance, $HOME/jdk).
Set JAVA_HOME to the path of the root JDK install; then prepend $JAVA_HOME/bin to your PATH.
And off you go.
Here I have a particular setting insofar as I run three different major versions of the JDK: 6, 7, 8. For instance, here is my source file for setting the current shell to use Java 8:
$ cat ~/.jdk/8
export JAVA_HOME=/opt/sunjdk/1.8/current
export PATH="$JAVA_HOME/bin:$PATH"
And in /opt/sunjdk/1.8 (given that /opt/sunjdk is writable by my user hence I don't need to be root):
$ ls -l /opt/sunjdk/1.8/* -d
lrwxrwxrwx 1 fge fge 11 Oct 30 10:09 /opt/sunjdk/1.8/current -> jdk1.8.0_25
drwxr-xr-x 1 fge fge 274 Mar 18 2014 /opt/sunjdk/1.8/jdk1.8.0_05
drwxr-xr-x 1 fge fge 274 Sep 18 02:44 /opt/sunjdk/1.8/jdk1.8.0_25
(and yes, I was root to begin with so as to grant write permissions for /opt/sunjdk to "my" user; if you have no such liberty, just create another directory in your home)
Oracle offers JRE and JDK also as *.tar.gz for Linux. I usually had success just downloading such a package, untarring/unzipping it (tar -xzvf jdk-8u25.tar.gz) and then running it, using the absolute path.
I was able to accomplish this using conda.
Conda is an open-source package-manager by Anaconda, that according to the website:
You do not need administrative or root permissions to install Anaconda if you select a user-writable install location.
You can search the package repo from a browser at anaconda.org or command line, for example here are the results for JDK.
For Linux, you would download this installer. Here is a command line that will start the installer for convenience:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && bash Miniconda3-latest-Linux-x86_64.sh
Once conda is installed, you can install packages. For example, to install the JetBrains Runtime OpenJDK build:
conda install -c anaconda openjdk
Other builds may be available from other channels in the repository.
The instructions above should give a working install, but the Getting started guide is a good place to get started. Conda uses the concept of environments to help manage versions and paths in a fairly simple and straightforward manner.
I hope this helps someone.
export JAVA_HOME=/opt/sunjdk/1.8/current
export PATH="$JAVA_HOME/bin:$PATH"
For me this option only worked when I changed linux to use bash instead ksh. I don't know if this is some kind of configuration in my company, but when I tried to run via ksh using "set" command instead "export" to define path, It was set correctly with the path of my new Java installation, but when I typed which java the old version was showed. But, when I executed bash, and typed the "export", it worked. So, if someone have the same problem to configure it using set command, try to use bash with export command. I am using Redhat 6.2.
I have read this article
http://lifehacker.com/5354441/google-docs-batch-upload-eases-online-document-transfers
java -jar google-docs-upload-1.2.jar /home/kevin/uploads --recursive
now its not working it says bas command not found.
is java already installed in vps centos or i have to install it
Either you don't have java or its not available in your path. Some linux distros install java in the /opt directory. So be sure to check if that's the case with you. If so then its just a matter of updating your path if not then there are two possibilities :
1. You have root access.
2. You don't have root access.
If you do have root access then you can easily install java with your package manager, if now you can still install java as a local user. Read this to do that. You can install any version of java that you so wish, also it may be unnecessary to install JDK, just JRE might be enough for you.
Don't do the steps that need root access, just copy it somewhere in your home directory or any of the directories to which you have access. Then set the appropriate values for JAVA_HOME and your PATH. It should work then.
If you need any help in doing that feel free to ask.
Download the jar google-docs-upload-1.2.jar.
Ensure you have Java.
Use your own home- and upload-folder, not the "kevin/uploads" one.
I have both Java JRE and Java JDK on a FreeBSD 7.2 box (running PFSense) from http://www.freebsdfoundation.org/downloads/java.shtml
find / -name gives me output like:
/usr/local/diablo-jre1.6.0/bin/java
/usr/local/diablo-jdk1.6.0/bin/java
/usr/local/diablo-jdk1.6.0/jre/bin/java
so I make a link to /usr/local/bin like so:
ln /usr/local/diablo-jre1.6.0/bin/java /usr/local/bin/java
and now I get
# rehash
# java
Error: could not find libjava.so
Error: could not find Java 2 Runtime Environment.
SOOOOOO, I'm wondering if there is some tool I can use to turn on a particular java vm similar to Ubuntus' /etc/jvm?
The /usr/local/diablo-jre1.6.0/bin/java application probably locates libjava.so relative to the location of the java application itself. By creating a hard link to java and executing it via that hard link, you've probably broken that mechanism.
Suggestions:
Put /usr/local/diablo-jre1.6.0/bin on your search path.
Create an alias for java instead of a link.
Replace the hard link with a symbolic link; i.e. use ln -s to create it.
The FreeBSD packages should have installed a wrapper-script in /usr/local/bin/java that knows about the different installed JVMs, and their JAVA_HOMEs etc. Did you by chance accidentally download the tarball instead of the package?
What does pkg_info | grep jdk yield?
If this is in a jail, you may need to move /proc temporarily so it doesn't try to use it to find out where the Java libraries are. Got bitten by this one!
Is there some way to see the native code produces by the JIT in a JVM?
General usage
As explained by other answers, you can run with the following JVM options:
-XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly
Filter on a specific method
You can also filter on a specific method with the following syntax:
-XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,*MyClass.myMethod
Notes:
you might need to put the second argument within quotes depending on OS etc.
if the method gets inlined, you could miss some optimisations
How to: Install the required libraries on Windows
If you are running Windows, this page has instructions on how to build and install hsdis-amd64.dll and hsdis-i386.dll which are required to make it work. We copy below and extend the content of that page* for reference:
Where to get prebuilt binaries
You can download prebuilt binaries for Windows from the fcml project
hsdis-amd64.dll
hsdis-i386.dll
How to build hsdis-amd64.dll and hsdis-i386.dll on Windows
This version of the guide was prepared on Windows 8.1 64bit using 64-bit Cygwin and producing hsdis-amd64.dll
Install Cygwin. At the Select Packages screen, add the following packages (by expanding the Devel category, then clicking once on the Skip label next to each package name):
make
mingw64-x86_64-gcc-core (only needed for hsdis-amd64.dll)
mingw64-i686-gcc-core (only needed for hsdis-i386.dll)
diffutils (in Utils category)
Run the Cygwin Terminal. This can be done using the Desktop or Start Menu icon created by the installer, and will create your Cygwin home directory (C:\cygwin\home\<username>\ or C:\cygwin64\home\<username>\ by default).
Download the latest GNU binutils source package and extract its contents to your Cygwin home directory. At the time of writing, the latest package is binutils-2.25.tar.bz2. This should result in a directory named binutils-2.25 (or whatever the latest version is) in your Cygwin home directory.
Download the OpenJDK source by going to the JDK 8 Updates repository, selecting the tag corresponding to your installed JRE version, and clicking bz2. Extract the hsdis directory (found in src\share\tools) to your Cygwin home directory.
In the Cygwin Terminal, enter cd ~/hsdis.
To build hsdis-amd64.dll, enter
make OS=Linux MINGW=x86_64-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.25
To build hsdis-i386.dll, enter
make OS=Linux MINGW=i686-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.25
In either case, replace 2.25 with the binutils version you downloaded. OS=Linux is necessary because, although Cygwin is a Linux-like environment, the hsdis makefile fails to recognize it as such.
The build will fail with messages ./chew: No such file or directory and gcc: command not found. Edit <Cygwin home directory>\hsdis\build\Linux-amd64\bfd\Makefile in a text editor like Wordpad or Notepad++ to change SUBDIRS = doc po (line 342, if using binutils 2.25) to SUBDIRS = po. Re-run the previous command.
The DLL can now be installed by copying it from hsdis\build\Linux-amd64 or hsdis\build\Linux-i586 to your JRE's bin\server or bin\client directory. You can find all such directories on your system by searching for java.dll.
Bonus tip: if you prefer Intel ASM syntax to AT&T, specify -XX:PrintAssemblyOptions=intel alongside any other PrintAssembly options you use.
*page license is Creative Commons
Assuming you're using the Sun Hotspot JVM (i.e. the one provided on java.com by Oracle), you can add the flag
-XX:+PrintOptoAssembly
when running your code. This will print out the optimized code generated by the JIT compiler and leaves out the rest.
If you want see the entire bytecode, including the unoptimized parts, add
-XX:CompileThreshold=#
when you're running your code.
You can read more about this command and the functionality of JIT in general here.
You need an hsdis plugin to use PrintAssembly. A convenient choice is the hsdis plugin based on FCML library.
It can be compiled for UNIX-like systems and on Windows you can use pre-built libraries available in the FCML download section on Sourceforge:
To install in Windows:
Extract the dll (it can be found in hsdis-1.1.2-win32-i386.zip and hsdis-1.1.2-win32-amd64.zip).
Copy the dll to wherever exists java.dll (use Windows search). On my system, I found it at two locations:
C:\Program Files\Java\jre1.8.0_45\bin\server
C:\Program Files\Java\jdk1.8.0_45\jre\bin\server
To install in Linux:
Download source code, extract it
cd <source code dir>
./configure && make && sudo make install
cd example/hsdis && make && sudo make install
sudo ln -s /usr/local/lib/libhsdis.so <JDK PATH>/lib/amd64/hsdis-amd64.so
sudo ln -s /usr/local/lib/libhsdis.so <JDK PATH>/jre/lib/amd64/hsdis-amd64.so
On my system, the JDK is in /usr/lib/jvm/java-8-oracle
How to run it:
java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly
-XX:+LogCompilation -XX:PrintAssemblyOptions=intel,mpad=10,cpad=10,code
-jar fcml-test.jar
Additional configuration parameters:
code Print machine code before the mnemonic.
intel Use the Intel syntax.
gas Use the AT&T assembler syntax (GNU assembler compatible).
dec Prints IMM and displacement as decimal values.
mpad=XX Padding for the mnemonic part of the instruction.
cpad=XX Padding for the machine code.
seg Shows the default segment registers.
zeros Show leading zeros in case of HEX literals.
The Intel syntax is a default one in case of Windows, whereas the AT&T one is a default for the GNU/Linux.
For more details see the FCML Library Reference Manual
For the HotSpot (was Sun) JVM, even in product modes:
http://wikis.oracle.com/display/HotSpotInternals/PrintAssembly
Some assembly required: it needs a plugin.
I believe WinDbg would be helpful if you are running it on windows machine.
I have just run one jar.
Then I attached to the java process
through Windbg
Examined threads by ~ command; There were 11 threads, 0 thread was main worker thread
Switched to 0-thread - ~0s
Looked through unmanmaged callstack by kb there was:
0008fba8 7c90e9c0 ntdll!KiFastSystemCallRet
0008fbac 7c8025cb ntdll!ZwWaitForSingleObject+0xc
0008fc10 7c802532 kernel32!WaitForSingleObjectEx+0xa8
0008fc24 00403a13 kernel32!WaitForSingleObject+0x12
0008fc40 00402f68 java+0x3a13
0008fee4 004087b8 java+0x2f68
0008ffc0 7c816fd7 java+0x87b8
0008fff0 00000000 kernel32!BaseProcessStart+0x23
Highlighted lines is direct running JIT-ed code on JVM.
Then we can look for method address:
java+0x2f68 is 00402f68
On WinDBG: Click View -->
Disassembly. Click Edit --> Go to
Address. Put 00402f68 there
and got
00402f68 55 push ebp
00402f69 8bec mov ebp,esp
00402f6b 81ec80020000 sub esp,280h
00402f71 53 push ebx
00402f72 56 push esi
00402f73 57 push edi
... and so on
For additional info here is the Example how to trace back JIT-ed code from memory dumps using process explorer and WinDbg.
Another way to see machine code and some performance data is to use AMD's CodeAnalyst or OProfile, which have a Java plugin to visualize executing Java code as machine code.
Print the assembly of your hotspots with JMH's perfasm profilers (LinuxPerfAsmProfiler or WinPerfAsmProfiler). JMH does require the hsdis library since it relies on PrintAssembly.