Maven & JDK 1.7 on Mac - macos

When I try to compile a project with Maven I get the following error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project webserverlog: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project webserverlog: Compilation failure
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
My JAVA_HOME is pointing to the JDK:
$ echo $JAVA_HOME
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
$ $JAVA_HOME/bin/javac -version
javac 1.7.0_25
javac: no source files
Usage: javac <options> <source files>
I'm not sure why Maven adds '/jre' to the end of JAVA_HOME, but looking at some other posts this doesn't seem to be the problem:
$ mvn --version
Apache Maven 3.0.4 (r1232337; 2012-01-17 18:44:56+1000)
Maven home: /Users/jerry/dev/springsource/apache-maven-3.0.4
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.4", arch: "x86_64", family: "mac"
I've searched for a solution to this problem and tried different things for the last couple of days, but can't find anything that works. I've seen some threads with a similar problem, but none of the suggestions worked for me.
Does anyone know how to solve this? Any help greatly appreciated...

You should assign the real path to the JDK to the JAVA_HOME variable instead of leaving the CurrentJDK literal. For some reason in Mac OS X the CurrentJDK is not pointing to the actual one regarding Maven. Try something like this in your .profile but replacing you actual jdk folder name:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home

FYI, one cause of "no source files" is lack of disk space wherever tmp points.
Looks like maven and javac store some items in TEMP/TMP/TMDIR and if that director doesn't exist, lacks space, lacks permissions then you can see that problem. at least we did on windows and I suspect it'll happen on better operating systems too.

Related

Is there an examples of a JHipster Oracle 11g implementation around?

Is there an examples of a JHipster Oracle 11g implementation around?
I thought I had everything set up correctly, but still not able to run ./mvnw without the application throwing errors. Unfortunately not a lot is available on the specific error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project cdp: Compilation failure: Compilation failure:
[ERROR] error reading /Users/millera/.m2/repository/io/github/jhipster/jhipster-framework/3.0.3/jhipster-framework-3.0.3.jar; zip END header not found
I initially thought this was an issue with Maven on my system, but it seems to be working for other things, and if I run mvn --version I get back:
Maven home: /usr/local/Cellar/maven/3.6.2/libexec
Java version: 11.0.4, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"
It's an issue with your maven local repository which for some unknown reason has a corrupted jar of jhipster-framework.
Try cleaning it up with rm -rf /Users/millera/.m2/repository/io/github/jhipster and restart your app with ./mvnw.

Maven reading settings.xml from wrong place

I am new to Maven and Ubuntu. I am having trouble building maven projects. When I run the mvn clean -X command I can see the below DEBUG logs.
[DEBUG] Reading global settings from /space/user/programs/apache-maven-3.5.3/conf/settings.xml
[DEBUG] Reading user settings from ?/.m2/settings.xml
[DEBUG] Reading global toolchains from /space/user/programs/apache-maven-3.5.3/conf/toolchains.xml
[DEBUG] Reading user toolchains from ?/.m2/toolchains.xml
[DEBUG] Using local repository at /space/user/git/receiver/?/.m2/repository
I have following settings in .bashrc file
export JAVA_HOME=/space/user/programs/jdk1.8.0_162
export M2_HOME=/space/user/programs/apache-maven-3.5.3
export MAVEN_HOME=/space/user/programs/apache-maven-3.5.3
And I have settings.xml file in /home/user/.m2 folder
Why maven is not picking /home/user/.m2/settings.xml? What is it that I am missing here please? If you need any further information please let me know and I will update the question.
I am using Ubuntu 16.04.
UPDATE:
Output of mvn --version command
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T19:49:05Z)
Maven home: /space/user/programs/apache-maven-3.5.3
Java version: 1.8.0_162, vendor: Oracle Corporation
Java home: /space/user/programs/jdk1.8.0_162/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "4.13.0-37-generic", arch: "i386", family: "unix"
UPDATE:
Overriding settings on command line like this mvn --settings /home/user/.m2/settings.xml clean -X works fine. But this is not the solution I want.
The solution was to use 64-bit JDK on a 64-bit system. I somehow copied 32-bit JDK, and this was the problem. It worked as expected with a 64-bit runtime.
This question helped me solve the issue - Java: System.getProperty("user.home") returns "?"
Note: your linux machine might have both a 32-bit and a 64-bit version of the JVM installed. Even Java 11. #Newbee is correct that this can cause weird maven behavior that they described. Check your alternatives to see which one is being pointed at (for CentOS / RHEL machines):
ls -l /etc/alternatives/java_sdk_11
sudo alternatives --display java_sdk_11
sudo alternatives --config java_sdk_11

Maven Build failure in Jenkins

While running a build in Jenkins Maven is complaining about JDK. I know very well that it's some challenge with env variables. I have set JAVA_HOME to JDK installation path but no luck. I have searched the whole web and know that other people have faced this but their solution isn't working for me. Any help would be really appreciated !
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
FYR, my maven version output.
root#zarvis:~# mvn -version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T17:27:37+05:30)
Maven home: /usr/local/apache-maven-3.3.3
Java version: 1.7.0_101, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "3.19.0-31-generic", arch: "amd64", family: "unix"
JAVA_HOME is set but not sure why maven appends it with JRE.
root#zarvis:~# echo $JAVA_HOME
/usr/lib/jvm/java-1.7.0-openjdk-amd64
Thanks in advance !
Try adding JDK_HOME to your path

Maven cannot find tools.jar w/ proper JAVA_HOME

I am having some trouble building a Maven project on my Windows machine. I have set my JAVA_HOME environment variable and Maven finds it.
Here are come results from a few executions:
'which mvn'
/cygdrive/c/Program Files/Apache/apache-maven-3.0.5/bin/mvn
'mvn -version'
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 05:51:28 0800)
Maven home: C:\Program Files\Apache\apache-maven-3.0.5
Java version: 1.6.0_45, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_45\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 8", version: "6.2", arch: "amd64", family: "windows"
Note: It does find the proper JAVA_HOME path here!
Building w/ Maven:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.
0.2:compile (default-compile) on project sportbukkit-api: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR] C:\Program Files\Java\jre6\..\lib\tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.
As you can see, for some reason it is looking in the completely wrong directory. Please let me know if any more info is needed or if you know how to fix this! Thank you!
Try setting your JAVA_HOME to C:\Program Files\Java\jdk1.6.0_45 instead of C:\Program Files\Java\jdk1.6.0_45\jre

maven unable to find java compiler

I'm new to maven. I just joined a new company and they use maven for all their projects.
I set up the company's server for maven dependencies.
I'm using Fedora.
For most of the projects everything goes well. For some of them I get this error when running mvn compile:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project xlayer: Fatal error compiling: Error while executing the external compiler. Error while executing process. Cannot run program "java -classpath "${env.M2_REPO}/org/eclipse/jdt/core/3.4.2.v_883_R34x/core-3.4.2.v_883_R34x.jar" org.eclipse.jdt.internal.compiler.batch.Main -sourcepath "src/main"" (in directory "/home/es/ion_projects/XLayer"): error=2, No such file or directory -> [Help 1]
I looked several hours on the web, nothing would do.
PATH and JAVA_HOME are correctly set.
Running mvn --version gives:
Apache Maven 3.0.4 (rNON-CANONICAL_2013-01-22_13-18_mockbuild; 2013-01-22 14:18:29+0100)
Maven home: /usr/share/maven
Java version: 1.7.0_17, vendor: Oracle Corporation
Java home: /home/es/kit/jdk1.7.0_17/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.8.3-103.fc17.i686", arch: "i386", family: "unix"
UPDATE:
In the pom.xml (of parent, but that is not important), the maven-compiler-plugin defined the executable as
java -classpath "${env.M2_REPO}/org/eclipse/jdt/core/${org.eclipse.jdt.core.version}/core-${org.eclipse.jdt.core.version}.jar" org.eclipse.jdt.internal.compiler.batch.Main -sourcepath "src/main"
in order to use the Eclipse compiler instead of sun's comiler. This worked for developpers using windows. On linux, maven tries to execute "java -classpath ...." as a single command, which does not exist.
I am still loking for a solution. the only hack I found was to put the executable "java -classpath ..." in an executable file on my machine and put the name of that file in the tag on maven.

Resources