How to set environment variable in Solaris 11 for ant? - ant

I am trying to install ant in Solaris. I am using this:
https://ant.apache.org/manual/install.html
but I have no idea how to set the ANT_HOME environment variable. Please help?

If you want to set the ANT_HOME temporally, typing export ANT_HOME=you ant path in your installing terminal. Otherwise, you can add ANT_HOME permanently by adding a line of export ANT_HOME=you ant path in /etc/profile file (you have to own root privilege).

Related

Jenkins Sonarqube Plugin: JAVA_HOME exists but does not point to a valid Java home

I am trying to set up the Sonarqube for my project, but when I start to generate a build, I get the following error:
ERROR: JAVA_HOME exists but does not point to a valid Java home
folder. No "\bin\java.exe" file can be found there.
The SonarQube Scanner did not complete successfully
I check some docs but none of them helps. For the JAVA_HOME environment variable, I point it to be C:\Program Files (x86)\Java\jdk1.8.0_111 I also double check it by using powershell java -version command. It also gives me the same answer: java version "1.8.0_111" . Anyone knows how to solve the problem?
Thanks.
You can edit:
C:\Users\HOME_FOLDER\.jenkins\tools\hudson.plugins.sonar.SonarRunnerInstallation\SonarQubeScanner\bin>notepad sonar-scanner.bat
and put following:
SET JAVA_HOME=< JDK Path>
if EXIST in the sonar-scanner.bat fails because there is a space in the path, so the solution is to set the JAVA_HOME to a value without spaces e.g. using the short name of the "Program Files" SET JAVA_HOME= C:\Progra~1\Java\jre9
I encountered the same error. The issue was with sonar-scanner.bat referencing wrong %JAVA_HOME% path.
In the sonar-scanner.bat the variable "use_embedded_jre" is set to true and immediately the validation is done for the PATH.
#REM ==== START VALIDATION ====
#REM *** JAVA EXEC VALIDATION ***
set use_embedded_jre=true
if "%use_embedded_jre%" == "true" (
set "JAVA_HOME=%SONAR_SCANNER_HOME%\jre"
)
Set the variable value to "false", the issue will be fixed.
set use_embedded_jre=false
Ensure that JAVA_HOME is pointing JDK .
Please try to reinstall the java 8. Setup JAVA_HOME again then It will work.
This problem might be because space between "Program Files (x86)"
I had the same problem and struggled with it for a while.
After modifying sonar-scanner.bat a bit I found out that during execution of Sonarqube the %JAVA_HOME% was completely different from the one I configured in my environment variables.
Turned out I had hardcoded JDK installations in my Global Tool Configuration inside Jenkins.
My solution:
Open your Jenkins, go to Manage Jenkins -> Global Tool Configuration
Click JDK installations...
Make sure JAVA_HOME parameter is empty or just click Delete JDK
In this case Jenkins will use %JAVA_HOME% variable it finds during the execution and it's just the one you configured in your environment variables. Worked for me
You should restart your machine after java installation.
I was having the same issue. On my machine JRE was located at C:\Program Files (x86)\Jenkins\jre. So I appended System's PATH Environment Variable with C:\Program Files (x86)\Jenkins\jre\bin;
It worked.
Do not forget to restart Jenkins service from Windows Services

How to set path variables in ant

LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib:${LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
PATH=/usr/bin:${PATH}
export PATH
SQLPATH=/usr/lib/oracle/11.2/client64/lib:${SQLPATH}
export SQLPATH
Hi all,
This is the path variables I am setting in my shell script. I want to set this same in my ant file. Can you please explain how to set these variables in ant?

in ant :BUILD EXCEPTION

I am getting some problem while running ant
Here is the details of problem:
C:\jboss-5.1.0.GA\server\default\deploy\mdd_install\mc_config\ant\compile\compile.xml:30: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
at org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:105)
at org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:924)
at org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:757)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
I echo java_home and its value is correct
I am running my aplication from jboss and try to execute it, but it is getting the above exception. I put tools.jar in jboss server lib folder ,with that it is runnig fine,but it is not correct way.
Make sure the case of the path to JAVA_HOME is right. Reopen the window or environment you're running ant from to make sure it's using the updated environment vars.

setting environment variables

I'm setting up grails, and these are the commands the README indicates you should run for a unix machine. My problem is that the echo command doesn't output anything like it should. I double checked and have the grails folder in the right directory.
> set GRAILS_HOME=~/grails
> export GRAILS_HOME
> echo ${GRAILS_HOME}
~/grails
you need to set the path variable:
export GRAILS_HOME=/path/to/grails
export PATH=$PATH:$GRAILS_HOME/bin
For OS X Lion you add these lines this is to your ~/.bash_profile file. This is the same as your /Users/macUsername/.bash_profile. After saving this edit, new terminal windows will have this effect in place. You can also run source ~/.bash_profile to make the change happen in your current terminal window.
On another *nix you would edit a slightly different file.
The .bash_profile file holds commands that run every time you start your terminal.
Installation from Download
Prerequisites
Before you can start using Grails you will need to install a Java SDK (not just a JRE) and set the JAVA_HOME environment variable to the location of that SDK. The minimum required version of the SDK depends on which version of Grails you are using:
Java SDK 1.4+ for Grails 1.0.x and 1.1.x
Java SDK 1.5+ for Grails 1.2 or greater
Steps
Download the latest Grails release
Extract the archive into an appropriate location; typically C:\grails on Windows or ~/grails on Unix
Create a GRAILS_HOME environment variable that points to the path where you extracted the archive (eg C:\grails on Windows or ~/grails on Unix)
If you have not set the JAVA_HOME environment variable yet, create JAVA_HOME environment variable that points to the path where you have installed Java
Append a reference to the "bin" directory within the Grails directory to your PATH variable (eg %GRAILS_HOME%\bin on Windows or $GRAILS_HOME/bin on Unix). Note that, for Windows, both PATH and GRAILS_HOME must be defined at the same environment variable level (eg. 'System variables') rather than across environment variable levels (eg. PATH under 'System variables' and GRAILS_HOME under 'User variables')
Type "grails" at the command line, if a help message is displayed you are ready to start using Grails!
If you get an error message, try to chmod +x the grails script inside the bin directory.
Installation from Git (The Version Control Repository)
Prerequisites
In order to start using Grails from Git you need to have the following:
An installation of Java 1.5 or higher and have set your JAVA_HOME variable to the install location
A Git client
Steps
Check out Grails from the Git repository
by running: git clone git://github.com/grails/grails-core.git
Set the GRAILS_HOME environment variable to CHECKOUT_LOCATION/grails-core
Add the $GRAILS_HOME/bin directory to your PATH environment variable
What happens next depends on which branch you are working on.
For the 2.0.x and the 'master' branch:
Go to the GRAILS_HOME directory and run: ./gradlew install
That's it! You can now start developing in Grails using your custom copy of Grails!
For the 1.3.x branch:
Go to the GRAILS_HOME directory and run: ./gradlew libs
Then from the GRAILS_HOME directory run: ./gradlew install
That's it! You can now start developing in Grails using your custom copy of Grails!
For the 1.2.x branch:
If you don't have Ant 1.7 (or later) installed, you will need to
set ANT_HOME to $GRAILS_HOME/ant
add $ANT_HOME/bin to your PATH environment variable
you may need to give the scripts in $ANT_HOME/bin execute permissions
Increase the java memory to 1024M by setting ANT_OPTS=-Xmx1024M
Go to the GRAILS_HOME directory and type ant jar to build Grails
That's it! You can now start developing in Grails using your custom copy of Grails!
Confirm your grails install by grails -version

How do I change the JAVA_HOME for ant?

I'm doing java work on a class server where I don't have root. Whenever I try to compile using ant, it points to the wrong directory (/usr/tomcat instead of /usr/tomcat/jre ).
One of the things we were told to do when setting up our user accounts was to add export JAVA_HOME=/usr/tomcat/jre to the .bashrc file. I don't know if that was supposed to take care of the problem but it doesn't seem to.
So, how can I change the JAVA_HOME property for ant but only for when I run ant?
EDIT:
echo $JAVA_HOME points to /usr/tomcat/jre
echo $JAVA_HOME\bin points to /usr/tomcat/jrebin
The problem is when I normally run ant I get this error:
Unable to locate tools.jar. Expected to find it in /usr/tomcat/lib/tools.jar
Buildfile: build.xml
compile:
[javac] Compiling 1 source file to /home/ejm244/build/classes
BUILD FAILED
/home/ejm244/build.xml:9: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
Total time: 0 seconds
You could create your own script for running ant, e.g. named ant.sh like:
#!/bin/sh
JAVA_HOME=</path/to/jdk>; export JAVA_HOME
ant $#
and then run your script.
$ chmod 755 ant.sh
$./ant.sh clean compile
or whatever ant target you wish to run
JAVA_HOME should point at where the JDK is installed not not a JRE.
So, if you type ls $JAVA_HOME what do you see?
if you do ls $JAVA_HOME/bin/ do you see javac?
If the first doesn't work then you don't have JAVA_HOME pointing at the right directory.
If the second doesn't work then you need to point JAVA_HOME at a JDK instead of a JRE.
Looking at the shell script for invoking ant, it is possible that the value for $JAVA_HOME set for your shell in .bashrc can be overridden in the files /etc/ant.conf, $HOME/.ant/ant.conf, and $HOME/.antrc. If you execute bash -x <path to ant script> it will emit debugging information which should help you track down where $JAVA_HOME is being overridden.
On my Windows 7 machine setting:
JAVA_HOME="C:\Program Files\Java\jdk1.6.0_18"
didn't work. But setting:
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_18
worked.
There are 2 ways of changing the compiler:
export JAVA_HOME=/path/to/jdk before you start Ant.
Set <javac exectuable="/path/to/javac">
Another option would be to add a respective tools.jar to the classpath, but this is usually used if Ant is started from another tools like Maven.
For more details on these (or other) options of changing Java Compiler in Ant, see this article for example.
Set the env var:
JAVACMD - full path of the Java executable. Use this to invoke a different JVM than JAVA_HOME/bin/java(.exe).
Reference: http://ant.apache.org/manual/running.html
Though the environment variable JAVA_HOME set correctly, the ant may use the configured JRE within the each build.xml or any build files.
To check what version of the JRE the ant is using, right click on the build file -> select the build ant which displays the details about the tasks to choose etc, select the JRE which you want to use.
Its advisable to use the project level settings or just at the workspace level.
JAVA_HOME needs to point to a JDK home if you're trying to compile code. Check to see if '/usr/tomcat/jre/bin/javac' exists. I doubt it does.
If you don't have a JDK, then you can work around it by getting the ECJ (eclipse compiler) library, dropping it into '~/.ant/lib' and adding a system property to the command-line to use that compiler - check the Ant manual for details.
http://ant.apache.org/
Set the JRE in the project (project properties -> Java Build Path-> Libraries, typically last entry), or global default in preferences (Java->Installed JREs) to a JDK, not a JRE.
When using Bash just try this:
$ export JAVA_HOME=/usr/tomcat/jre
When running ant from the shell, you don't need to export JAVA_HOME first, which would set that variable for your current shell and all future commands, instead use
user#host:~# JAVA_HOME=/path/to/jdk ant targets
You will need to change JAVA_HOME path to the Java SDK directory instead of the Java RE directory. In Windows you can do this using the set command in a command prompt.
e.g.
set JAVA_HOME="C:\Program Files\Java\jdk1.6.0_14"
try with this:
/usr/sbin/update-alternatives --config java
java_home always points to the jdk, the compiler that gave you the classes,
and the jre is thw way that your browser or whatever will the compiled classes so it must have matching between jdk and jre in the version.

Resources