How do I make grails choose the right JDK? - grails

I'm using Mac OSX 10.8.5 with Oracle's Java 1.7 installed in addition to the mac's 1.6.
I have my JAVA_HOME set and the JAVA_HOME/bin in the front of my path.
When I run a grails compile from the command line I can see it's choosing the Java 1.6 instead of 1.7. How do I make the grails command-line choose the JDK I want?
➤ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home
➤ echo $PATH
/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/bin /usr/local/share/npm/bin /Users/kbrodhagen/bin /Users/kbrodhagen/.rvm/bin /usr/bin /bin /usr/sbin /sbin /usr/local/bin /opt/X11/bin /usr/local/git/bin
➤ set -x JAVA_OPTS "-showversion"
➤ grails compile
java version "1.6.0_51"
Java(TM) SE Runtime Environment (build 1.6.0_51-b11-457-11M4509)
Java HotSpot(TM) 64-Bit Server VM (build 20.51-b01-457, mixed mode)

Which shell are you using and exactly how did you set JAVA_HOME? Grails should respect your JAVA_HOME setting as long as it is visible to the grails command, for example in bash you must export the variable rather than just setting it, in tcsh you would use setenv rather than set.
$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home
You can also remove /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/bin from your PATH as /usr/bin/java will automatically delegate to the appropriate java command for the current JAVA_HOME.

If you want to localise the Java version only to Grails the best way is to edit below file,
.gvm/bin/gvm-init.sh
You can set the JAVA_HOME in this file as below,
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_71.jdk/Contents/Home
I have Java 8 in my machine and here I am setting java 1.7 for grails ONLY.

For the new SDKman method you can export JAVA_HOME in [YOUR HOME]/.sdkman/candidates/grails/[concrete version or current]/bin/grails

I needed to be able to switch between a Java 7/Grails 2.4.4 project and a Java 8/Spring 4 project in Ubuntu 12.04 and certain things made this difficult:
I'd set Java 8 as the default version after installing it using sudo apt-get install oracle-java8-set-default, but that apparently creates /etc/profile.d/jdk.sh and /etc/profile.d/jdk.csh containing JAVA_HOME, JRE_HOME and other env vars that prevented me from swapping the JDK.
This kinda worked, but the above env vars clouded things too much.
In the end, I removed both of the above items from my environment and the files in /etc/profile.d and I now:
Change the JDK by running sudo update-java-alternatives -s java-8-oracle (or java-7-oracle) as mentioned in the webupd8 article;
Run gvm to set the current or default grails and other tools as required
Seems messier than it should be, but I think it is working now.

If you use SDKMAN to install Grails (which is the currently recommended method), you can add any versions of Java you have installed to SDKMAN and it will manage them for you as well. For example:
sdk install java openjdk-8 /usr/lib/jvm/java-8-openjdk-amd64
sdk use java openjdk-8
Note that this will set JAVA_HOME for your user, so if you don't want that you may want to consider one of the other options.
$ echo $JAVA_HOME
/home/user/.sdkman/candidates/java/current
For more information: SDKMAN local versions

Related

Anchor environtment variable

When I make an anchor test or anchor build I've this error:
BPF SDK: \\?\C:\Users\user\.local\share\solana\install\releases\1.9.4\solana-release\bin\sdk\bpf
Can't get home directory path: environment variable not found
solana version 1.9.4
anchor-cli 0.23.0
If you want $HOME defined, you likely need to run anchor test / anchor build from a Bash-compatible shell. Git bash is a great option for Windows, and I've had success with it in the past when not using WSL: https://gitforwindows.org/
Use WSL and dont use the latest Solana CLI suite, use the stable version.
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"

Using specific JDK version for non Java build

Let's say I have a job using non JVM language. For the sake of this question let's assume that it is R so my .travis.yml looks like this:
language: r
Now, some of the packages I use interact with Java libraries and I'd like to fix JDK version (specifically to OpenJDK 8 if that matters).
Java projects have some tools like
jdk_switcher use openjdk8
but these don't seem to work if language is not set to Java.
Is there any clean built-in way to handle this?
I can imagine combining apt and script that updates-alternatives, but I'd like to avoid this path, unless it is necessary.
After installing openjdk8, I used update-alternatives (not sure if this is necessary) and then exported the JAVA_HOME and PATH environment variables. The relevant lines from my .travis.yml look something like:
before install:
- sudo apt install -y openjdk-8-jdk
- sudo update-alternatives --set java /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
script:
- export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/
- export PATH=$JAVA_HOME/bin:$PATH
- java -version
- R CMD javareconf
- R CMD build
- R CMD check

Running Jenkins on Tomcat Fail applicaton at context path /jenkins could not be started

For a few days I am trying to set Jenkins on Tomcat7 without any result... I read many tutorials and I could not find any help...
I set a virtual system on VirtualBox -> Ubuntu 12.04.04
Using apt-get I installed tomcat7, and then Jenkins.
While using them separately by usingcommad sudo service tomcat7 start or sudo service jenkins start both services starts and are visable on my localhost.
However, when I copied jenkins.war to /var/lib/tomcat7/webapps I cannot run it via tomcat.
I have set JENKINS_HOME as /var/lib/jenkins.
In the folder /usr/share/tomcat7 i run these commands: sudo mkdir .jenkins | sudo chown tomcat7:nogroup .jenkins
And from localhost:8080/manager jenkins is viable:
When I try localhost:8080/jenkins as tutorials says I get en error message:
I really have no idea what am I doing wrong...
What else may I try to make it work?
I had the same issue. Please check Java compatibility version with the "Jenkins.war" file. I used Java 8 for Jenkins version 2.107.1.
I would suggest to shutdown restart the tomcat server. As it should be able to read the .war file. Hence, you will go through additional setup.
Check the version of your jenkins.war file
Check the compatibe java version for hat jenkins version in web
Download that version of java and define system environment variables path for JAVA_HOME
Open "Monitor tomcat" in that JAVA define the path of jvm.dll
example C:\Program Files\Java\jdk-11.0.16\bin\server\jvm.dll
This picture shows how to run in windows:
Please check your JRE path, as I face a similar issue where JRE_HOME was incorrectly set
JRE_HOME=/usr/jdk/jdk1.6.0_21,
It started working when I correct it to latest JRE version
JRE_HOME=/usr/jdk/jdk1.7.0_09/jre.

How create environment variable for tomcat?

I'm trying create environment variable in tomcat 8 for my project, I need use this variable for choice properties logger. I read about setenv.sh and i create this file, but when i run my project - it does not run. How me create environment variable for check my project?
I read about setenv in this site. I use ubuntu 14.04.
setenv.sh
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
export JAVA_HOME
JAVA_OPTS="-Xmx4096m -Xms512m -server"
export JAVA_OPTS
CATALINA_HOME="/opt/tomcat"
export CATALINA_HOME
Please do the following. It'll work for you.
1 sudo su and cd to /var/lib/tomcat8/bin/
2 touch setenv.sh(if it doesn't exist)
3 chmod 777 setenv.sh
4 vim setenv.sh and set following line in setenv.sh
export varriable=value
5 sudo service tomcat8 restart
and Enjoy...!!
Rather than create /usr/share/tomcat8/bin/setenv.sh, you can put those settings in /etc/default/tomcat8.
I've found that setting JAVA_HOME in setenv.sh causes tomcat8 to not start up properly if it doesn't match what /etc/init.d/tomcat8 comes up with. The init.d script ignores setenv.sh but needs to know which java version is used so that it can check the process list to see if tomcat is running. The init.d script does use /etc/default/tomcat8, so it makes sense to delete setenv.sh and just put the settings in /etc/default.
There is an alternate way if we're using eclipse:
Go to Servers tab
Double click on the server
Click Open launch configuration
Go to Environment tab
Click New and set the key-value pair of environment variables

ANT_HOME cmd issue in Windows 8

I have set
ANT_HOME as C:\Janice\GuideWire\AllSoftwares\apache-ant-1.7.1 (User variables)
And
PATH=%ANT_HOME%\bin (system variables)
It just does not work. I get ANT_HOME incorrectly set or cannot be located.
I also tried:
ANT_HOME as C:\Janice\GuideWire\AllSoftwares\apache-ant-1.7.1 (User variables)
And
PATH=%ANT_HOME%\bin (User variables)
I tried re starting the system for both the cases. Nothing works. plz help
I have got variables in system variables section and it's working...
After modification plesae execute:
Restart OS
Type in command line set and check if ANT_HOME/ant configuration is present
Type ant -v
If C:\Janice\GuideWire\AllSoftwares\apache-ant-1.7.1\bin is set in the path, then that should work. Make sure this parameter is separated by a semi-colon(;) in path.
set path=C:\Janice\GuideWire\AllSoftwares\apache-ant-1.7.1\bin;%path%
Or you may try adding double slash once.
You also need to have Java installed and present on path.
Run cmd and there:
set | findstr ANT
set | findstr JAVA
and
echo %PATH% | findstr jdk
each of those commands need to return something.
Verify your java config by running:
java -version
where java
result should be as follows
c:\Guidewire\TrainingApp\bin>java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)
c:\Guidewire\TrainingApp\bin>where java
C:\Windows\System32\java.exe
c:\tools\jdk1.6.0_21\bin\java.exe
if it's not, then probably you need to set up Java first
Make sure that your ANT_HOME variable is

Resources