Specify Java Location for Gatling - java

I am running Gatling on Centos server. The Server has Java 1.7 installed which is not supported by Gatling 2.2 and I am not allowed to update Java version. I was wondering if there was a way to specify java location in gatling configuration to run from a specific Java installation and not from /usr/bin or /usr/sbin. Thanks in advance.
Regards,
AB

You could export JAVA_HOME=/<your-path> before running gatling.

Assuming you're using the gatling.sh script to launch Gatling, you can just edit that script to refer to whatever installation of the JDK that you want. You can set a local JAVA_HOME value and also prefix the calls to java executable with the full path of your JDK 8 installation.
For example, near the end of the shell script, something like this:
JAVA_HOME=/path/to/JDK8
# Run the compiler
${JAVA_HOME}/bin/java java $COMPILER_OPTS -cp "$COMPILER_CLASSPATH" io.gatling.compiler.ZincCompiler -ccp "$COMPILATION_CLASSPATH" "$#" 2> /dev/null
# Run Gatling
${JAVA_HOME}/bin/java $JAVA_OPTS -cp "$GATLING_CLASSPATH" io.gatling.app.Gatling "$#"

Related

Failed to run sdkmanager --list with Java 9

I downloaded and installed:
JDK (jdk-9.0.1_osx-x64_bin.dmg) from Oracle here
Android SDK (sdk-tools-darwin-3859397.zip) from Google here.
After configuring the PATH variable, I tried running sdkmanager, which replaced the android command for managing SDK components. However, it failed as shown here:
$ sdkmanager --list
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)
at com.android.sdklib.tool.SdkManagerCli.main(SdkManagerCli.java:117)
at com.android.sdklib.tool.SdkManagerCli.main(SdkManagerCli.java:93)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 5 more
Here is the Java version:
$ java -version
java version "9.0.1"
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
Does anyone know how to fix it without going back to Java 8?
Related Questions
Failed to install android-sdk: "java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema"
This post asked a similar question. However, the post is closed and the only answer suggests going back to Java 8.
WARNING
Please note that I already mentioned above that going back to Java 8 or running it side-by-side is NOT what I wanted.
With the help of this answer, I successfully solved the problem.
We are going to apply a fix in sdkmanager. It is a shell script. It is located at $android_sdk/tools/bin, where $android_sdk is where you unzipped the Android SDK.
Open sdkmanager in your favorite editor.
Locate the line which sets the DEFAULT_JVM_OPTSvariable. In my copy, it is at line 31:
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME"'
Append the following options to the variable: -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee. Please pay attention to the quotes. In my copy, the line becomes:
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
Save the file and quit the editor.
Run the command again.
Here is the result:
$ sdkmanager --list
Installed packages:
Path | Version | Description | Location
------- | ------- | ------- | -------
tools | 26.0.1 | Android SDK Tools 26.0.1 | tools/
Available Packages:
Path | Version | Description
------- | ------- | -------
add-ons;addon-g..._apis-google-15 | 3 | Google APIs
add-ons;addon-g..._apis-google-16 | 4 | Google APIs
add-ons;addon-g..._apis-google-17 | 4 | Google APIs
add-ons;addon-g..._apis-google-18 | 4 | Google APIs
add-ons;addon-g..._apis-google-19 | 20 | Google APIs
add-ons;addon-g..._apis-google-21 | 1 | Google APIs
add-ons;addon-g..._apis-google-22 | 1 | Google APIs
add-ons;addon-g..._apis-google-23 | 1 | Google APIs
add-ons;addon-g..._apis-google-24 | 1 | Google APIs
...
Hola! It works!
-- Edit: 2017-11-07 --
Please note that you may need to apply the fix above again after running sdkmanager --update, since the sdkmanager shell script may be overridden if the tools package is updated.
Related Answers
https://stackoverflow.com/a/43574427/142239
#andy-guibert pointed out the necessary options to make this work. He also briefly what those mysterious options mean.
The accepted answer is outdated as of February 2019. Here's an answer that will work until sdkmanager migrates to a newer version of Java. But by then, you won't have this problem anymore.
OpenJDK 10 was superseeded by OpenJDK 11, which doesn't implement java.se.ee at all. This means that the hack of adding --add-modules java.se.ee doesn't do anything anymore. It also means that OpenJDK 10 will be automatically removed from your system and replaced with OpenJDK 11 the next time you update, if your updates are configured properly.
Modify sdkmanager to use Java 8 by setting JAVA_HOME inside sdkmanager to a Java 8 installation. It's, by default, at ~/Android/Sdk/tools/bin/sdkmanager.
# Add default JVM options here. You can also use JAVA_OPTS and SDKMANAGER_OPTS to pass JVM options $
JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64
DEFAULT_JVM_OPTS='"-Dcom.android.sdklib.toolsdir=$APP_HOME" -XX:+IgnoreUnrecognizedVMOptions'
#rem Add default JVM options here. You can also use JAVA_OPTS and SDKMANAGER_OPTS to pass JVM options to this script.
set JAVA_HOME="C:\ProgramData\scoop\apps\android-studio\current\jre"
set DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.."
This way, you can keep using a sane and maintained version of Java on your system while simultaneously using sdkmanager.
# Java
export JAVA_HOME=/usr/lib/jvm/default-java
And now I've got some pipelines to repair.
You can set sdkmanager options with SDKMANAGER_OPTS.
Example:
export SDKMANAGER_OPTS="--add-modules java.se.ee"
sdkmanager --list
When having java 11 in the system, the solutions provided are not valid.
This -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee or--add-modules java.xml.bind do not work with Java 11 on Mac OS.
For that reason you have to downgrade java version to version 8 from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
List Java versions installed
/usr/libexec/java_home -V
Java 11
export JAVA_HOME=$(/usr/libexec/java_home -v 11)
Java 1.8
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
Then go to
cd ~/Library/Android/sdk/tools/bin
and
./sdkmanager --licenses
Update 2019-10:
As stated in the issue tracker, Google has been working on a new SDK tools release that runs on current JVMs (9+)!
You can download and use the new Android SDK Command-line Tools inside Android Studio or by manually downloading them from the Google servers:
SDK Tools for Linux
SDK Tools for Mac OS
SDK Tools for Windows
For the latest versions check the URLs inside the repository.xml.
If you manually unpack the command line tools, take care of placing them in a subfolder inside your $ANDROID_HOME (e.g. $ANDROID_HOME/cmdline-tools/...).
Update 2021-03:
The latest stable command-line tools are also available at Googles Downloads-Website
Install the Command-line Tools in the SDK Manager via Android Studio.
Then run the version of SDK Manager from the cmdline-tools directory, as opposed to the tools directory.
$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --version # GOOD!
$ANDROID_HOME/tools/bin/sdkmanager --version # BAD! (java.lang.NoClassDefFoundError)
For Windows, if nothing works then try this:
Open sdkmanager.bat with Notepad.
Locate the following line:
%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %SDKMANAGER_OPTS%
Add --add-modules java.xml.bind
The modified line should look like this:
%JAVA_EXE%" %DEFAULT_JVM_OPTS% --add-modules java.xml.bind %JAVA_OPTS% %SDKMANAGER_OPTS%
I just add "Android SDK Command-line Tools (latest)" and this solved my issue.
Originally from here:
https://github.com/flutter/flutter/issues/56778#issuecomment-742639036
As some people have mentioned before, this very well could be a simpler problem having to do with one java installation taking precedence over the other.
In my case it was java 8 being overshadowed by a default newer java.
I installed java 8:
sudo apt-get install openjdk-8-jdk
Then I updated the installed java to be the new default:
sudo update-alternatives --config java
Whereby I selected java 8's id number.
After doing these (pretty simple) steps, I could just run sdkmanager without error.
Hope this helps someone!
As we read in the previous comments this error is occurring because the current SDK version is incompatible with the newest Java versions: 9 and 10.
So, to solve it, you can downgrade your java version to Java 8, or as a workaround, you can export the following option on your terminal:
Linux:
export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
Windows:
set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee'
If this does not work try to exports the java.xml.bind instead.
Linux:
export JAVA_OPTS='-XX:+IgnoreUnrecognizedVMOptions --add-modules java.xml.bind'
Windows:
set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.xml.bind'
This will solve this error for the sdkmanager
And to make it saved permanently you can export the JAVA_OPTS in your profile file on Linux (.zshrc, .bashrc and etc.) or add it as an environment variable permanently on Windows.
ps. This doesn't work for Java 11/11+, which doesn't have Java EE modules. For this option is a good idea, downgrade your Java version or wait for a Flutter update.
Ref: JDK 11: End of the road for Java EE modules
The Android Tools are still incompatible with JDK 9 or 10. You need to install JDK 8 or, if you need multiple Java versions make sure that the system-wide Java home points to a JDK 8.
More details here: How to configure Unity 2017.4 to target Android and avoid build failures on OSX?
I had a tough time figuring out this solution just adding the working sdkmanager.bat
#if "%DEBUG%" == "" #echo off
#rem ##########################################################################
#rem
#rem sdkmanager startup script for Windows
#rem
#rem ##########################################################################
#rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%..
#rem Add default JVM options here. You can also use JAVA_OPTS and SDKMANAGER_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.."
#rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
#rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
#rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
#rem Setup the command line
set CLASSPATH=%APP_HOME%\lib\sdklib-25.3.1.jar;%APP_HOME%\lib\layoutlib-api-25.3.1.jar;%APP_HOME%\lib\dvlib-25.3.1.jar;%APP_HOME%\lib\repository-25.3.1.jar;%APP_HOME%\lib\gson-2.2.4.jar;%APP_HOME%\lib\commons-compress-1.8.1.jar;%APP_HOME%\lib\httpclient-4.1.1.jar;%APP_HOME%\lib\httpmime-4.1.jar;%APP_HOME%\lib\common-25.3.1.jar;%APP_HOME%\lib\kxml2-2.3.0.jar;%APP_HOME%\lib\annotations-25.3.1.jar;%APP_HOME%\lib\annotations-12.0.jar;%APP_HOME%\lib\jimfs-1.1.jar;%APP_HOME%\lib\httpcore-4.1.jar;%APP_HOME%\lib\commons-logging-1.1.1.jar;%APP_HOME%\lib\commons-codec-1.4.jar;%APP_HOME%\lib\guava-18.0.jar
#rem Execute sdkmanager
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% -XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee %JAVA_OPTS% %SDKMANAGER_OPTS% -classpath "%CLASSPATH%" com.android.sdklib.tool.SdkManagerCli %CMD_LINE_ARGS%
:end
#rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable SDKMANAGER_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%SDKMANAGER_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
I was able to solve the issue by using an edited sdkmanager.bat file by forcing to use the Java embedded inside the Android Studio Itself, which i presume uses the OpenJDK 8. Here is the edited sdkmanager I Used :
#if "%DEBUG%" == "" #echo off
#rem ##########################################################################
#rem
#rem sdkmanager startup script for Windows
#rem
#rem ##########################################################################
#rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%..
#rem Add default JVM options here. You can also use JAVA_OPTS and SDKMANAGER_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.."
#rem find Java from Android Studio
#rem Find java.exe
if defined ANDROID_STUDIO_JAVA_HOME goto findJavaFromAndroidStudioJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
goto findJavaNormally
:findJavaFromAndroidStudioJavaHome
set JAVA_HOME=%ANDROID_STUDIO_JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
goto findJavaNormally
#rem java from java home
#rem Find java.exe
:findJavaNormally
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
goto javaError
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
goto javaDirectoryError
:javaError
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:javaDirectoryError
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
#rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
#rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
#rem Setup the command line
set CLASSPATH=%APP_HOME%\lib\dvlib-26.0.0-dev.jar;%APP_HOME%\lib\jimfs-1.1.jar;%APP_HOME%\lib\jsr305-1.3.9.jar;%APP_HOME%\lib\repository-26.0.0-dev.jar;%APP_HOME%\lib\j2objc-annotations-1.1.jar;%APP_HOME%\lib\layoutlib-api-26.0.0-dev.jar;%APP_HOME%\lib\gson-2.3.jar;%APP_HOME%\lib\httpcore-4.2.5.jar;%APP_HOME%\lib\commons-logging-1.1.1.jar;%APP_HOME%\lib\commons-compress-1.12.jar;%APP_HOME%\lib\annotations-26.0.0-dev.jar;%APP_HOME%\lib\error_prone_annotations-2.0.18.jar;%APP_HOME%\lib\animal-sniffer-annotations-1.14.jar;%APP_HOME%\lib\httpclient-4.2.6.jar;%APP_HOME%\lib\commons-codec-1.6.jar;%APP_HOME%\lib\common-26.0.0-dev.jar;%APP_HOME%\lib\kxml2-2.3.0.jar;%APP_HOME%\lib\httpmime-4.1.jar;%APP_HOME%\lib\annotations-12.0.jar;%APP_HOME%\lib\sdklib-26.0.0-dev.jar;%APP_HOME%\lib\guava-22.0.jar
#rem Execute sdkmanager
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %SDKMANAGER_OPTS% -classpath "%CLASSPATH%" com.android.sdklib.tool.sdkmanager.SdkManagerCli %CMD_LINE_ARGS%
:end
#rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable SDKMANAGER_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%SDKMANAGER_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
Here i used an environmental variable ANDROID_STUDIO_JAVA_HOME which actually points to the JRE embedded in the android studio eg: ../android_studio/jre
This also has a fallback to JAVA_HOME if ANDROID_STUDIO_JAVA_HOME is not set.
Short addition to the above for openJDK 11 with android sdk tools before upgrading to the latest version.
The above solutions didn't work for me
set DEFAULT_JVM_OPTS="-Dcom.android.sdklib.toolsdir=%~dp0\.."
To get this working I have installed the jaxb-ri (reference implementation) from the maven repo.
The information was given https://github.com/javaee/jaxb-v2 and links to the https://repo1.maven.org/maven2/com/sun/xml/bind/jaxb-ri/2.3.2/jaxb-ri-2.3.2.zip
This download includes a standalone runtime implementation in the mod-Folder.
I copied the mod-Folder to $android_sdk\tools\lib\ and added the following to classpath variable:
;%APP_HOME%\lib\mod\jakarta.xml.bind-api.jar;%APP_HOME%\lib\mod\jakarta.activation-api.jar;%APP_HOME%\lib\mod\jaxb-runtime.jar;%APP_HOME%\lib\mod\istack-commons-runtime.jar;
So finally it looks like:
set CLASSPATH=%APP_HOME%\lib\dvlib-26.0.0-dev.jar;%APP_HOME%\lib\jimfs-1.1.jar;%APP_HOME%\lib\jsr305-1.3.9.jar;%APP_HOME%\lib\repository-26.0.0-dev.jar;%APP_HOME%\lib\j2objc-annotations-1.1.jar;%APP_HOME%\lib\layoutlib-api-26.0.0-dev.jar;%APP_HOME%\lib\gson-2.3.jar;%APP_HOME%\lib\httpcore-4.2.5.jar;%APP_HOME%\lib\commons-logging-1.1.1.jar;%APP_HOME%\lib\commons-compress-1.12.jar;%APP_HOME%\lib\annotations-26.0.0-dev.jar;%APP_HOME%\lib\error_prone_annotations-2.0.18.jar;%APP_HOME%\lib\animal-sniffer-annotations-1.14.jar;%APP_HOME%\lib\httpclient-4.2.6.jar;%APP_HOME%\lib\commons-codec-1.6.jar;%APP_HOME%\lib\common-26.0.0-dev.jar;%APP_HOME%\lib\kxml2-2.3.0.jar;%APP_HOME%\lib\httpmime-4.1.jar;%APP_HOME%\lib\annotations-12.0.jar;%APP_HOME%\lib\sdklib-26.0.0-dev.jar;%APP_HOME%\lib\guava-22.0.jar;%APP_HOME%\lib\mod\jakarta.xml.bind-api.jar;%APP_HOME%\lib\mod\jakarta.activation-api.jar;%APP_HOME%\lib\mod\jaxb-runtime.jar;%APP_HOME%\lib\mod\istack-commons-runtime.jar;
Maybe I missed a lib due to some minor errors showing up. But
sdkmanager.bat --update or --list is running now.
This is what I did in Ubuntu 18.04 (Any Linux will do):
$ sudo apt-get install openjdk-8-jdk
$ sudo update-alternatives --config java
There are 2 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 manual mode
* 2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
$ export JAVA_HOME=$(/usr/lib/jvm/java-1.8.0-openjdk-amd64)
This is the answer to make this work for Java 11 and above since the entire JAXB APIs were removed.
Download Jakarta XML Binding, specifically this zip file. You need only the 3 files within mod folder i.e. jakarta.activation.jar, jakarta.xml.bind-api.jar and jakarta.xml.bind-api.jar and you can toss the rest off.
Move these files to APP_HOME/lib folder. I created a sub folder jaxb inside for this. So, on my macOS system this was:
$HOME/Library/Android/sdk/tools/lib/jaxb
Now open sdkmanager using your favorite text editor and under CLASSPATH= add the following at th beginning:
$APP_HOME/lib/jaxb/jakarta.activation.jar:$APP_HOME/lib/jaxb/jakarta.xml.bind-api.jar:$APP_HOME/lib/jaxb/jaxb-impl.jar
So it ended up looking like:
CLASSPATH=$APP_HOME/lib/jaxb/jakarta.activation.jar:$APP_HOME/lib/jaxb/jakarta.xml.bind-api.jar:$APP_HOME/lib/jaxb/jaxb-impl.jar:$APP_HOME/lib/dvlib-26.0.0-dev.jar:$APP_HOME/lib/jimfs-1.1.jar:$APP_HOME/lib/jsr305-1.3.9.jar:$APP_HOME/lib/repository-26.0.0-dev.jar:$APP_HOME/lib/j2objc-annotations-1.1.jar:$APP_HOME/lib/layoutlib-api-26.0.0-dev.jar:$APP_HOME/lib/gson-2.3.jar:$APP_HOME/lib/httpcore-4.2.5.jar:$APP_HOME/lib/commons-logging-1.1.1.jar:$APP_HOME/lib/commons-compress-1.12.jar:$APP_HOME/lib/annotations-26.0.0-dev.jar:$APP_HOME/lib/error_prone_annotations-2.0.18.jar:$APP_HOME/lib/animal-sniffer-annotations-1.14.jar:$APP_HOME/lib/httpclient-4.2.6.jar:$APP_HOME/lib/commons-codec-1.6.jar:$APP_HOME/lib/common-26.0.0-dev.jar:$APP_HOME/lib/kxml2-2.3.0.jar:$APP_HOME/lib/httpmime-4.1.jar:$APP_HOME/lib/annotations-12.0.jar:$APP_HOME/lib/sdklib-26.0.0-dev.jar:$APP_HOME/lib/guava-22.0.jar
And that's pretty much it, should solve the issue.
I did these steps because flutter doctor --android-licenses was giving me issues. And this fixed it.
(WINDOWS)
If you have installed Android Studio already go to File >> Project Structure... >> SDK Location.
Go to that location + \cmdline-tools\latest\bin
Copy the Path into Environment Variables
than it is OK to use the command line tool.
The only working solution for me is to use the java shipped with the Android studio.
set the JAVA_HOME to /Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home
in .bashrc
set JAVA_HOME="/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home"
If you are using fish shel, put this in ~/.config/fish/config.fish
set -gx JAVA_HOME /Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home
(This is for mac, but I am sure it should work with linux and windows by setting the correct path)
Apparently if you use "commandlinetools" version greater than 3.6.0 you may use JDK11+ to install Android SDK components.
They are available here: https://developer.android.com/studio#command-tools
Official issue tracker saying it is fixed: https://issuetracker.google.com/issues/122210344#comment11
As explained above by Saifur Rahman Mohsin, the problem is that sdmanager relies on the availability of J2EE functionality which no longer ships with JRE/JDK >= 11, so this can be worked around by using the JAXB classes which implement the same functionality.
However, you may prefer not (or not be able to) modify the sdkmanager script (e.g. because it is installed by some other process that you do not control). If you are running a Posix/Unix system (like GNU/Linux or BSD, maybe macOS) you may still have a chance.
At least with the sdkmanager shipped with sdk-tools-linux-4333796.zip (maybe also with later versions), if you set $JAVA_HOME, it tries to look for $JAVA_HOME/jre/sh/java for IBM's AIX SDK compatibility. So you can exploit that compatibility check to trick sdkmanager into using a wrapper script that inserts the necessary classes into the class path when calling the real java program.
For example, in Debian with OpenJDK 11 already installed (package openjdk-11-jre or openjdk-11-jdk) you can do this (as root):
# cd /usr/lib/jvm/java-11-openjdk-amd64 # use your Java home here
# mkdir -p jre/sh
# cd jre/sh
# touch java
# chmod a+rx java
Then edit the just-created java script and write this Bash code into it:
#!/bin/bash
cp="$JAVA_EXTRA_CLASSPATH" java="$JAVA_HOME/bin/java"
test "$cp" || exec "$java" "$#"
args=()
for arg in "$#"; do
if [[ "$setcp" ]]; then
cp="$arg:$cp" setcp=
elif [[ "$arg" =~ ^-(cp|-?classpath)$ ]]; then
setcp=y
else
args+=("$arg")
fi
done
exec "$java" -cp "$cp" "${args[#]}"
To make sdkmanager use the wrapper script and inject the JAXB classes into the class path, first install the relevant JAXB package in your system (libjaxb-java in Debian), and use sdmanager like this:
$ export JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64" # for Debian's OpenJDK 11
$ export JAVA_EXTRA_CLASSPATH="/usr/share/java/jaxb-impl.jar" # for Debian's `libjaxb-java` package
$ (now run sdkmanager or other processes running it as usual)
Please note that $JAVA_EXTRA_CLASSPATH has classpath syntax, so you can enter a colon-separated list of items.
I noticed that this trick also applies to the Gradle wrapper and maybe others, but they may be safe if $JAVA_EXTRA_CLASSPATH is not set.
https://adoptopenjdk.net currently supports all distributions of JDK from version 8 onwards.
For example https://adoptopenjdk.net/releases.html#x64_win
Here's an example of how I was able to use JDK version 8 with sdkmanager and much more: https://travis-ci.com/mmcc007/screenshots/builds/109365628
For JDK 9 (and I think 10, and possibly 11, but not 12 and beyond), the following should work to get sdkmanager working:
export SDKMANAGER_OPTS="--add-modules java.se.ee"
sdkmanager --list
JDK 13.0.1, Android SDK 29 , Windows 10
Basically i tried everything, but the most effective and only 1 solution that worked for me was to downgrade to jdk 1.8. I dont why, it is early 2020 and have to downgrade to 1 year old jdk version against latest flutter version. Maybe problem is in windows version, cause jdk 13.0.1 worked for me on macOS 10.15.2. Hope this solution works.
Download Link (JDK 1.8.0):
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
You just need to install jaxb har files and include in the classpath. this works in java 11 to 12 latest.
To those who are looking for the fix i made some gist in github hope this help. and the links are provided also.
https://gist.github.com/Try-Parser/b7106d941cc9b1c9e7b4c7443a7c3540
Define home directories of different JDK versions in your .bashrc or .zshrc:
export JAVA_8_HOME=$(/usr/libexec/java_home -v1.8)
export JAVA_14_HOME=$(/usr/libexec/java_home -v14)
First of all use JDK version 8. Put this line the top of sdkmanager file:
export JAVA_HOME=$JAVA_8_HOME
Switch back to JDK version 14. Put this line the bottom of sdkmanager file:
export JAVA_HOME=$JAVA_14_HOME
If you are using flutter,
Run this command flutter doctor --android-licenses
For users on mac, I solved an issue similar to this by modifying my zshrc file and adding the following (although your java_home might be configured differently) :
export JAVA_HOME=$(/usr/libexec/java_home)
export ANDROID_HOME=/Users/YOURUSER/Library/Android/sdk
export PATH=$PATH:/Users/YOURUSER/Library/Android/sdk/tools
export PATH=$PATH:%ANDROID_HOME%\tools
export PATH=$PATH:/Users/YOURUSER/Library/Android/sdk
I have a M1 chipset and the only solution was to install the JDK 8 from azul zuru and then change my JAVA_HOME to 1.8 and works!
Another solution possible to this error is check your Java version, maybe you can solve it downloading this jdk oracle-jdk-8, this was my mistake :P
I download Java 8 SDK
unistall java sdk previuse
close android studio
install java 8
run-> cmd-> flutter doctor --install -licenses
and after
flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.19041.388], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 4.0)
[√] VS Code (version 1.47.3)
[!] Connected device
! No devices available
! Doctor found issues in 1 category
display and finish
Go to {SDK_FOLDER}/lib/_/ (underscore folder). Copy all the files from the _ folder to its parent folder /lib.

Cordova can't find my Java installation, but JAVA_HOME looks valid. What's going on?

Windows 7 64-bit, with 64-bit JDK. Cordova plugman 1.4.2-dev. Using cygwin bash as a shell, but I don't see why that would affect anything.
$ echo $JAVA_HOME
"c:\Program Files\Java\jdk1.8.0_25"
$ echo $ANDROID_HOME
C:\Users\admin\AppData\Local\Android\Sdk
$ ls "c:\Program Files\Java\jdk1.8.0_25"
bin include lib release
COPYRIGHT javafx-src.zip LICENSE THIRDPARTYLICENSEREADME.txt
db jre README.html THIRDPARTYLICENSEREADME-JAVAFX.txt
$ ./main.js install --platform android --project ../myproject/ --plugin phonegap-facebook-plugin-gtg --variable APP_ID="1155264567919069" --variable APP_NAME="Voice Test"
Fetching plugin "phonegap-facebook-plugin-gtg" via npm
Installing "phonegap-facebook-plugin" for android
Failed to install 'phonegap-facebook-plugin':CordovaError: Failed to run "javac -version", make sure that you have a JDK installed.
You can get it from: http://www.oracle.com/technetwork/java/javase/downloads.
Your JAVA_HOME is invalid: "c:\Program Files\Java\jdk1.8.0_25"
I've also tried using JAVA_HOME without the quotes. What's going on?
#cubrr gave the correct answer in the comments. The error message being produced by Cordova is extremely misleading: the problem isn't that JAVA_HOME was incorrect, but that javac wasn't on my path. This was made all the more confusing by the fact that java was on my path, so when I checked it gave correct results. This is because the Oracle installer adds a directory to your path (c:\ProgramData\Oracle\Java\javapath) that contains links to java.exe and related programs but not the relevant JDK programs.
1) set > system variables > path to
`;C:\Program Files\Java\jdk1.8.0_xxx\bin;`
2) create new JAVA_HOME path with the value
C:\Program Files\Java\jdk1.8.0_xxx
now check javac version by issuing command at CMD
javac -version
*** don't touch the oracle - "C:\ProgramData\Oracle\Java\javapath;" path
If you are running windows 10, you need to restart your computer after changing the path and other variables. Possibly also on earlier windows versions.

Gradle finds wrong JAVA_HOME even though it's correctly set

When trying to run gradle, I get the following error:
# gradle
ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/default-java
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
However, when I check the JAVA_HOME variable I get:
# echo $JAVA_HOME
/usr/lib/jvm/java-7-oracle
My JAVA_HOME is defined in .bashrc and I have double checked that it is set as the source.
Running java -version also confirms that JAVA_HOME is set correctly and is on the PATH.
# java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
I have also checked that /usr/bin/java symlinks to /etc/alternatives/java which in turn correctly symlinks to /usr/lib/jvm/java-7-oracle/jre/bin/java
Additionally I've checked that there are no duplicate JAVA_HOME definitions in .bash_profile or /etc/profile.
So my question is how/why does Gradle find /usr/lib/jvm/default-java, and more importantly how do I point it to the correct directory?
Other programs which require the JDK work fine, so I think its a Gradle issue. I've also tried reinstalling Gradle which made no difference.
I'm running 64bit Xubuntu (Ubuntu 13.10 base)
Turns out that the particular Gradle binary I downloaded from the Ubuntu 13.10 repository itself tries to export JAVA_HOME. Thanks to Lucas for suggesting this.
/usr/bin/gradle line 70:
export JAVA_HOME=/usr/lib/jvm/default-java
Commenting this line out solves the problem, and Gradle finds the correct path to the Java binary.
If you just download the binary from their website it does not have this problem,
It's an issue with the Ubuntu repo version. There also seem to be some other issues with 13.10 version.
add a symbolic link
sudo ln -s /usr/lib/jvm/java-7-oracle /usr/lib/jvm/default-java
Solution is to make JAVA_HOME == dir above bin where javac lives as in
type javac
javac is /usr/bin/javac # now check if its just a symlink
ls -la /usr/bin/javac
/usr/bin/javac -> /etc/alternatives/javac # its a symlink so check again
ls -la /etc/alternatives/javac # now check if its just a symlink
/etc/alternatives/javac -> /usr/lib/jvm/java-8-openjdk-amd64/bin/javac
OK so finally found the bin above actual javac so do this
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
above can be simplified and generalized to
which javac >/dev/null 2>&1 || die "ERROR: no 'javac' command could be found in your PATH"
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac) )))
For me this error was due to the reason Gradle as installed as sudo and I was trying as default user to run Gradle.
Try:
sudo gradle -version
or
sudo gradle -v
In my Ubuntu, I have a headache for 2 days on this issue.
Step 1. Type on the terminal whereis java
then it will display something like this
java: /usr/bin/java /etc/java /usr/share/java /usr/lib/jvm/java-8-openjdk-amd64/bin/java /usr/share/man/man1/java.1.gz
Step 2. Take note of the path:
/usr/lib/jvm/java-8-openjdk-amd64/bin/java
exclude the bin/java
your JAVA_HOME = /usr/lib/jvm/java-8-openjdk-amd64
Did you export your JAVA_HOME? Without export, the setting will not be propagated to the commands started inside of that shell. Also, java -version does not use JAVA_HOME, rather it uses the first java found in your path. Make sure your .bashrc looks something like this:
JAVA_HOME=/path/to/java/home
export JAVA_HOME
Try installing latest version of gradle,
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle
If we install from ubuntu repo, it will install the old version , (for me it was gradle 1.4). In older version, it sets java home from gradle as export JAVA_HOME=/usr/lib/jvm/default-java. Latest version don't have this issue.
I faced this issue when I run the following command on Ubuntu:
ionic build android
To solve this issue, I did the following steps:
ln -sf /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java /usr/lib/jvm/default-java
Add JAVA_HOME to /etc/environment:
vi /etc/environment
Add:
JAVA_HOME="/usr/lib/jvm/default-java"
After saving, read it:
source /etc/environment
Finally, you can run build command.
I had the same problem, but I didnt find export command in line 70 in gradle file for the latest version 2.13, but I understand a silly mistake there, that is following,
If you don't find line 70 with export command in gradle file in your gradle folder/bin/ , then check your ~/.bashrc, if you find export JAVA_HOME==/usr/lib/jvm/java-7-openjdk-amd64/bin/java, then remove /bin/java from this line, like JAVA_HOME==/usr/lib/jvm/java-7-openjdk-amd64, and it in path>>> instead of this export PATH=$PATH:$HOME/bin:JAVA_HOME/, it will be export PATH=$PATH:$HOME/bin:JAVA_HOME/bin/java. Then run source ~/.bashrc.
The reason is, if you check your gradle file, you will find in line 70 (if there's no export command) or in line 75,
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
That means /bin/java is already there, so it needs to be substracted from JAVA_HOME path.
That happened in my case.
I have tested this on Manjaro Linux. Should work on other Disto too.
You need to include whole java-jdk dir instead of just java/bin for java env var.
For example, instead of:
export JAVA_HOME=/opt/jdk-14.0.2/bin #change path according to your jdk location
PATH=$PATH:$JAVA_HOME
use this:
export JAVA_HOME=/opt/jdk-14.0.2/ #change path according to your jdk location
PATH=$PATH:$JAVA_HOME
then run the gradle command it will work.
You can also go to the bin folder inside your gradle installation folder and correct the JAVA_HOME parameter in gradle.bat file.
In my case, my JAVA_HOME was set to c:\Program files\java\bin
The JAVA_HOME in gradle.bat was set to %JAVA_HOME%\bin\java.exe.
I corrected the JAVA_HOME in gradle.bat and it worked.
Thank you!!!
Before running the command try entering:
export JAVA_HOME="path_to_java_home"
Where path_to_java_home is the folder where your bin/java is.
If java is properly installed you can find it's location, by using the command:
readlink -f $(which java)
Don't forget to remove bin/java from the end of the path while putting it into JAVA_HOME
For me an explicit set on the arguments section of the external tools configuration in Eclipse was the problem.
sudo ln -s /usr/lib/jvm/java-7-oracle/jre /usr/lib/jvm/default-java
Create a symbolic link to the default-java directory.
You can find your java directory by
readlink -f $(which java)
# outputs: /usr/lib/jvm/java-7-oracle/jre/bin/java
# Remove the last `/bin/java` and use it in above symbolic link command.
I had a problem with this too. It said wrong directory when it was correct. So I just created a local variable with the name of JAVA_HOME omitting the final /bin/java. It worked fine for me.
If your GRADLE_HOME and JAVA_HOME environment are set properly then check your JDK directory and make sure you have java.exe file under below path.
C:\Program Files (x86)\Java\jdk1.8.0_181\bin
As error mentioned in gradle.bat file
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
It is not able to locate your java installation. So find and set
java.exe
under %JAVA_HOME%/bin if everything is correct.
This works for me (my account got disabled by client and their admin has removed java.exe from my directory.)
[Windows] As already said, it looks like .bat -file tries to find java.exe from %JAVA_HOME%/bin/java.exe so it doesn't find it since bin is repeated twice in path.
Remov that extra /bin from gradle.bat.
In my dockercontainer (being minimal the problem of not finding java) was, that "which" was not installed. Comipling a project using gradlew used which in ./gradlew to find java
Installing which solved the problem.
Adding below lines in build.gradle solved my issue .
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
#ISSUE:GradleException: javaConfig.targetVersion is Java 8, but the environment variable JAVA8_HOME does not exist
I think this is how you fix it in IntelliJ. I've run into it a couple times as I choose "Launch in New Window" for a new project but I haven't written down the steps yet.
1.File -> Project Structure. Project Settings / Project. Make sure Project SDK and Project language level are correct.
2.Preferences. Build, Execution, Deployment / Build Tools / Gradle. Make sure Gradle JVM is correct.
You may have to restart IntelliJ after this.
NOW it SOLVED THE ISSUE
Task :prepareKotlinBuildScriptModel UP-TO-DATE
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 22s

JAVA_HOME environment variable not set Validator.nu HTML Parser

I am trying to install a local version of the Validator.nu server and it keeps failing on trying to build the HTML Parser.
It says it can't find the JAVA_HOME variable which I have set in my .bashrc file and shows correctly when I type "echo $JAVA_HOME" at the prompt
Ideas appreciated thanks
Error output
"hg" pull --update -R build https://bitbucket.org/validator/build/
Not trusting file build/.hg/hgrc from untrusted user dave, group dave
Not trusting file /home/dave/src/checker/build/.hg/hgrc from untrusted user dave, group dave
warning: bitbucket.org certificate with fingerprint 81:2b:08:90:dc:d3:71:ee:e0:7c:b4:75:ce:9b:6c:48:94:56:a1:fe not verified (check hostfingerprints or web.cacerts config setting)
pulling from https://bitbucket.org/validator/build/
warning: bitbucket.org certificate with fingerprint 81:2b:08:90:dc:d3:71:ee:e0:7c:b4:75:ce:9b:6c:48:94:56:a1:fe not verified (check hostfingerprints or web.cacerts config setting)
searching for changes
no changes found
Error: The JAVA_HOME environment variable is not set.
Set the JAVA_HOME environment variable to the pathname of the directory where your JDK is installed.
Instead of:
$ sudo python build/build.py all
try:
$ sudo -E python build/build.py all
The sudo command for security reasons resets the environment (so your JAVA_HOME for the python process is wiped out even when it's exported). The "sudo -E" will preserve the environment.
I assume (from tag) you use ubuntu.
list versions of installed javas in your system:
dave#ubuntu:~$ update-java-alternatives --list
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
Note, that if you set JAVA_HOME in ~/.bashrc it will be set only in your terminal sessions.
Unless you export it, it will be set only for your current shell process (not subprocesses like mercurial).
add line to your .bashrc:
export JAVA_HOME="/usr/lib/jvm/java-6-openjdk"
open a new terminal and test it:
$JAVA_HOME/bin/java -version && echo java seen by bash
bash -c '$JAVA_HOME/bin/java -version && echo java seen by bash subprocesses'
If you want to set environment for all processes (not only started by hand from terminal), you can:
dave#ubuntu:~$ sudo $EDITOR /etc/environment
After tackling this for the last 4 days I have managed to get the validator.nu server running on my local Ubuntu VM and so I thought I would update this thread in case anyone else runs in to the same issues.
I am still not 100% sure where the original issue with the JAVA_HOME variable was coming from but I suspect (although I am not an expert at this) that it had something to do with the way I was using sudo to run the python build.
I was initially following the instructions on http://about.validator.nu/#src but using
$ sudo python build/build.py all
This was because part of the build needed the correct permissions to work.
This is my step-by-step process which starts from a clean install of Ubuntu 11.
installed ubuntu 11
opened the terminal
sudo /bin/bash <----------- I THINK THIS IS THE CRUCIAL LINE
apt-get install mercurial
apt-get install subversion
apt-get install openjdk-6-jre
apt-get install openjdk-6-jdk
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
follow rest of http://about.validator.nu/#src instructions
I'm going to need to do it again when I set this up for the internal network for our build scripts so i'll edit this if I've missed out on anything.
Hope this saves another person's headache and lost days!

DOS script to check if the default java installed version is greater than 1.x

As the subject said, i need a dos script to check the version of java installed on windows xp Machine.
Furthermore, I need to check if the version is greater than a prefixed value 1.x.
Anyone can help me?
Thanks!
Getting the version, and write it into a temp file. Then only parse the version itself:
#echo off
echo off
java -version 2> tmp_java_version.txt
set /p JAVA_VERSION= < tmp_java_version.txt
del tmp_java_version.txt
set JAVA_VERSION=%JAVA_VERSION:~14,3%
echo %JAVA_VERSION%
pause > NUL
if you can download and gawk for windows.
C:\test>java -version 2>&1 | gawk "NR==1{print $3}"
"1.6.0_16"
java -version
You can also use the command
java -fullversion
and produce output such as:
java full version "1.6.0_17-b04"
On a computer without any version of Java from Sun Microsystems installed, this results in an error message:
'java' is not recognized as an internal or external command, operable program or batch file.
In a batch you could do:
#echo off
java.exe -fullversion 2> c:\temp\out.txt
for /F "tokens=4" %%i IN (c:\temp\out.txt) DO echo %%i
You can't avoid the temp file because the java.exe output writes on the standard error! So you have to redirect the standard error to a file.
In commmand prompt you can just type it has java -version.
For example:
D:\Users> java -version
then you will get the answer as
java version 1.8.0_11

Categories

Resources