A user of my software is running Windows with Cygwin installed, which provides access to the standard GNU which command. In my CMakeLists.txt there is a line that reads:
FIND_PACKAGE( JAVA REQUIRED CONFIG )
This fails on his machine, because both JAVAConfig.cmake and java-config.cmake (executed by FIND_PACKAGE) use this command as a first-line attack in locating Java. The command returns a bad path to a non-existent install of Java. What can I do to override this annoying behavior from my CMakeLists.txt?
Ask him to send you his "path" env. variable, you will find something interesting there for sure.
Other issue is Java installations.
Ask him to unstall old javas or just update to newest, current installer removes older copies.
Related
I recently installed Java (Java Runtime 1.8.121) to my machine. I need to set up JAVA_HOME and set the variable from the Java folder where it installed.
Everywhere I have looked online says the Java folder should be located in Program files (x86), however, it is nowhere to be found. Its not in program files (x86), not in program files.
I wasn't able to choose a destination when it was installed as Software center was used. It simply completed the installation.
Can someone please help me find where the Java folder is so I can set up JAVA_HOME???!
cmd:
where java
git bash (same as cmd or):
which java
powershell:
(get-command java.exe).Path
Superuser: Equivalent of cmd's "where" in powershell
Open a command prompt
type: wmic product where "Name like '%%Java%%'" get installlocation,Name
This command can take a minute to complete. But should return something like this.
Edit: The benefit of this command, is that it doesn't rely on any system environment variables. It searches for installed programs that have the word 'Java' in the name. It won't return extra files or locations.
I downloaded the Carrot2 Document clustering server build 3.15.0 for Mac. The read me file says:
The DCS requires a Java Runtime Environment (JRE) version 1.7.0 or later. To
run the DCS, execute the 'dcs' script and point your browser at
http://localhost:8080 for further instructions.
Mac OS Sierra doesn't make it easy, but I got 1.8.0_112 installed.
The problem is that I don't know how to execute the 'dcs' script.
There are .cmd, .sh, .war, and .jar files. I wasn't sure which of those to work with. I thought .jar looked promising, so I followed some of this thread and tried this in a terminal window:
java -jar invoker.jar
I cd-ed to the correct directory, but it just says Provide main class, but I'm not sure what or where that is.
Can anybody provide instructions or a link to how to do this?
Use the dcs.sh (on Linux/Mac) and dcs.cmd (on Windows) to start the server. The scripts will set some extra options for the JVM and then start the DCS. In case of any problems, append the -v option to see diagnostic output.
I have a simple Java program that uses:
Runtime.getRuntime().exec("/usr/bin/javaws", [path for JNLP file])
to open a JNLP file using java web start.
However, I need to deal with the scenario of javaws not being installed. So I need to check to see if it is installed and, if it's not, install it. Any idea how to do either of those (or both)?
Firstly, you're assuming that the path to javaws is /usr/bin/javaws, which may not be the case.
If it were that simple, then you can check if the file exists:
File javawsFile = new File("/usr/bin/javaws");
if (! javawsFile.exists()) {
System.out.println("javaws not installed");
}
Having said that, java does not have to be installed to any particular location. Thus you can't assume it's in /usr/bin/. Many people will download the java binary zip and simply decompress it to their choice of location, and set the environment variable JAVA_HOME.
Now, you could go down the path of resolving the JAVA_HOME variable - but even then it'll only tell you if javaws is installed - or not.
If javaws is not installed, there is not really a way to install it - other than prompting the user to go off to the java website and download it.
The path you give is in *nix style. In this case it would require root access to install new applications - which isn't something you can simply manufacture.
Even if your user was already running your application as root, I would still be wary of this. It's not your responsibility to install software on your users' machines.
I just installed Java Developer on Windows Vista. The installation process looked OK and it was successfuly finished. However, I do not know how I cun run this program? Nothing new on the desctop appeared?
First of all it is important to note that the Java Development Kit (JDK) is not a GUI tools such as Visual Studio. It consists mainly of pure command-line tools used to compile, run and debug Java code.
There are IDEs (Integrated Development Environment) which provide the entire Editor/Compiler/Build-System integrated in one big setup, but in my opinion the very first steps should be done with the pure JDK.
Start with this intial Java tutorial.
Generally The Really Big Index should keep you occupied for quite some time.
Fetch yourself a development environment like Eclipse: http://www.eclipse.org/ and start playing around.
The JDK is just that: a software development kit, sitting around in a directory specified by you and waiting for you to invoke its command line tools ...
If by "Java Developer" you mean the Java Development Kit (JDK), then you "run" it via the command line - use javac to compile and java or javaw to run the compiled classes.
If you mean you installed the JDK—the Java development kit—then this is just the Java compiler and the sources of the class library (roughly). You can then go ahead, create Java programs in any text editor and compile them.
But you probably want an IDE, such as Eclipse.
Go to Command Prompt. In the command prompt go to the directory where the Java program is located. In the command line type "java name_of_the_program.java". It will generate name_of_the_program.class. After that you can type (in the command line) "javac name_of_the_program" and the program will be executed.
It is how it should be in theory. But in practice it will not work. To make it work you have to find your java-directory (a directory where "javac.exe" is located). In my case it was "C:\Program Files\Java\jdk1.6.0_18". Then you have to create 4 new environment variables (classpath, include, lib, path) and set them to be equal to the name of the above mentioned directory. After that you need to restart your computer and after that will be able to compile your progam (by typing "javac name_of_the_program.java").
But of couse it is not the end of the story. If you type "java name_of_the_program" the program will not be executed. Java will write you that it is cannot find the main class. How to solve this problem I do not know yet.
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.