Ant is unable to find a javac compiler - java

I am trying to build some binaries of an application. When i am trying to make the build, I am getting this:
BUILD FAILED
/home/.../ant-build.xml:84: 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.
It is currently set to "/usr/lib/jvm/java-8-openjdk-amd64/jre"
The application requires java 7, and i have it installed but i had it along java 8. The build requires for tools.jar which is located in java 7 only, therefore after several attempts i uninstalled java 8. However, when I am trying make again, i get the same error, even though i don't have java8 installed at all!
I set the JAVA_HOME properly:
$ echo $JAVA_HOME
/usr/lib/jvm/java-7-openjdk-amd64/
I doubt i need the path but i set that one up just in case as well :
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-7-openjdk-amd64/bin
I'm running out of ideas here :P any help would be appreciated.
Also something maybe important, I had to add the repo manually to get java-7 otherwise it wasnt able to locate the package. Thats when i got double jdk-s.

I guess you are calling the JAVAC command from any other source/tool like Jenkins/Bamboo/Teamcity. Make sure you have set the environment variable of that tool. usually it lies in the manage tool option.
I was facing same issue while using Jenkins.If you don't set up an environment variable in tool from which you are making a call it take your
"/usr/lib/jvm/java-8-openjdk-amd64/jre" so go and set the the env variable JAVA_HOME of you tools. attaching screen shot of Jenkins issue. Go to Manage Jenkins -->configure system --> environment variables and set you java_home path.
Cheers

I just encountered the same situation.
That is because JAVA_HOME is not correctly set in sudo environment.
I added export JAVA_HOME=/path/to in /root/.bashrc, and eventually it was built right.

It seems that you are using javac of java8 with JAVA_HOME or CLASS_PATH pointing to java7.
You can use which java to check that.
export JAVA_HOME=/lib/jvm/java-7-openjdk-amd64
export export ${PATH}=${JAVA_HOME}:/bin:${PATH}`

Related

How to get the JDK path in Gradle within Android Studio?

In order to build some Android projects, it's necessary to set the environment variable JAVA_HOME. (See this Stack Exchange question and flutter bug report.)
This is the case for a project I'm working on. I would like to change the Gradle file so it is not necessary to set JAVA_HOME.
Is there any way for Gradle to get the path to the JDK used by the enclosing Android Studio process (or for the process to pass in the JDK without user intervention)? This should work when JAVA_HOME had not been set.
you can define a task in your_project_path/app/build.gradle
task javaHome {
println "JAVA_HOME:" + System.getProperty("java.home")
}
run task:
./gradlew -q app:javaHome
RESULT:
JAVA_HOME:/usr/lib/jvm/java-8-openjdk-amd64/jre
There are generally two options available:
a) Edit the gradle.properties file and define which JDK you want to use:
org.gradle.java.home=(path to JDK home)
There it cannot be set dynamically, because it's an egg/hen problem.
And it might also fail on other computers, because the path may vary.
But one can pass it as command-line option:
./gradlew -Dorg.gradle.java.home=$JAVA_PATH
For reference: Build Environment.
b) However, one can also add an export JDK_HOME statement on top of file gradlew. Came up with a shell script, which can at least detect the default JDK install on Linux (Android Studio runs on JRE):
tmp=`which java`
export JAVA_HOME=${tmp::-9}
echo $JAVA_HOME
/usr/java/jdk1.8.0_172
Of course, one also would have to consider no JDK being present at all:
/usr/bin/which: no java in ...
Generally, this assumes a default JDK had been set with alternatives, as a package manger usually would do; eg yum install jdk1.8.0_102.x86_64. The problem here is, that there is no easy way to identify which JDK path to use on Windows, because Windows has no which command and one would likely have to read from the registry. A helper PS script or executable could look up the value and truncate as required, called from file gradlew.bat. There still may be other ways to get the path.

Eclipse unable to locate Java in Ubuntu

While I am trying to install the Payara server on my Ubuntu machine after putting the path of the Payara/glassfish server when I try to put the java location whatever i give as path is considered as error. I use Oracle java 10 and as I put the value "/usr/lib/java/jdk-10.0.1/" it says its not a jdk. Path for Java 10 has been properly set in ~/.bashrc as
export JAVA_HOME=/usr/lib/java/jdk-10.0.1/
export PATH="$PATH:JAVA_HOME/bin"
Why is this behaving in this way? Can anybody suggest me a way out.
try export PATH=$PATH:${JAVA_HOME}/bin
Your shell is interpreting JAVA_HOME as string, you forgot a $ before JAVA_HOME in the export PATH line to make it interpret as a variable.

using evosuite from command line

When I try to use the EvoSuite testing tool from the command line, I get the following error:
Fatal crash on main EvoSuite process. Class using seed 1428172877144. Configuration id : null
java.lang.RunTimeExceptionConfiguration:Did not manage to automatically find tools.jar. Use –Dtools_jar_location = <path> properly
at org.evosuite.runtime.agent.ToolsJarLocator.getLoaderForToolsJar<ToolsJarLocator.java:71> ~[evosuite-0.1.1.jar:na]
at org.evosuite.Evosuite.parseCommandLine<Evosuite.java:152> ~[evosuite-0.1.1.jar:na]
at org.evosuite.Evosuite.main<Evosuite.java:304> ~[evosuite-0.1.1.jar:na]
Could someone help me with this?
Make sure you use your JDK to run Evosuite, not the JRE. That may mean either going into the JDK /bin dir and running from there or fully quantifying the executable java binary file when you run (JDK..../bin/java.exe on windows for example).
Copy the tools.jar from JDK to your JRE lib folder...it worked for me..The problem, its not able to find the tools.jar.
As pointed out by Makoto, you need to use a -D option. Note: no space between variable name and assigned value, ie -Dx=v is OK, whereas -Dx = v is wrong. So:
java -jar evosuite-0.1.1.jar -Dtools_jar_location="C:\Program Files\Java\jdk1.7.0_75\lib"

jnetpcap library unable to build on ubuntu 12.04

I am trying to install JNetPcap and followed the instructions given at here. At step 12, I am unable to run the ant command and i see the error
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-6-sun/bin/java
As I am able to run Java classes from eclipse or from command line I don't think if it's a problem with JAVA_HOME.
echo $PATH shows
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-6-sun/bin
Kindly let me know if am missing something here.
thanks in advance
Neither running java from the command line or running eclipse will require JAVA_HOME to be set. However, the build procedure you are trying to use ant, and ant often does require JAVA_HOME to be set appropriately. (It actually depends on the version of ant that you are using. The use of JAVA_HOME is typically in the wrapper script for ant.)
Just set it.
JAVA_HOME should probably be set to /usr/lib/jvm/java-6-sun ... based on what you gave said PATH to.
However, it is also possible that the problem is that your PATH is incorrect. Or that you have (somehow) managed to get the owner/group/permissions on your Java install incorrect, such that the java command isn't executable.
Check that running java -version displays the installed Java version.
Repeat with /usr/lib/jvm/java-6-sun/bin/java -version.

Setting my JAVA_HOME variable for Hadoop

I have tried setting my JAVA_HOME variable for Hadoop to no avail.
My Java runtime is in /usr/bin/java, but Hadoop keeps trying to access it in /usr/bin/java/bin/java.
I have set the JAVA_HOME in my .bash_profile and in bin/hadoop, but neither works. I am guessing that some other path setter is overriding this. Is this a known problem and what can be done about it?
A couple of other things I tried:
echo $JAVA_HOME from the hadoop script
add $JAVA_HOME to the conf/hadoop-env.sh
In your case:
JAVA_HOME = /usr
The code assumes that the executable is located at:
$JAVA_HOME/bin/java
It's unlikely your Java installation is in /usr/bin/java.
The executable may be there, or may just be a link to the executable in your installation.
IMO it's cleaner to use your actual Java JDK/JRE directory and use that instead: that's what JAVA_HOME is supposed to be.
Using Hadoop is quite a bit more complicated than setting an environment variable correctly; you may be in for a rough road. Consider something like Kiji's Bento Box to ease initial setup.

Categories

Resources