Maven in OSX Keeps Compiling with Java 1.5 - java

I have a code that I'm working on from 2 different location, a Win7 machine and an OSX.
When worked on using Win7 machine, I don't need to bother about which java version that Maven compiles, I just need to set the PATH variable. If I'm on Java 5, it compiles against Java 5, if I'm on Java 7, it compiles against Java 7. No problem there.
Different case for my OSX machine. Now this is the exact same set of codes.
My Java version
[Mac-Pro] ~/apache-maven/apache-maven-3.1.1/conf $
p01ntbl4nk> java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)
My Maven version
[Mac-Pro] ~/apache-maven/apache-maven-3.1.1/conf $
p01ntbl4nk> mvn -version
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 23:22:22+0800)
Maven home: /Users/p01ntbl4nk/apache-maven/apache-maven-default
Java version: 1.7.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.1", arch: "x86_64", family: "mac"
Both shows the same java version. Java 7u60.
But when I run mvn clean compile on my codes, I am getting this "try-with-resource is not supported in -source1.5"
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project archival-client: Compilation failure
[ERROR] /Users/p01ntbl4nk/GitRepositories/GenericArchival/root/archival-client/src/main/java/org/si/genericArchival/client/App.java:[140,6] error: try-with-resources is not supported in -source 1.5
[ERROR] -> [Help 1]
[ERROR]
I've checked, I don't have any reference in my main maven settings.xml or in any of the pom.xml in the modules that would indicate to use sourve version 1.5
To fix this, I would have to add the following to all my pom.xml
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
But this would mean that the maven modules are no longer adaptable to the java version of the underlying platform.
Am I missing anything?

Well, you already have your answer, but here it is definitively.
http://maven.apache.org/plugins/maven-compiler-plugin/
Also note that at present the default source setting is 1.5 and the
default target setting is 1.5, independently of the JDK you run Maven
with. If you want to change these defaults, you should set source and
target as described in Setting the -source and -target of the Java
Compiler.

Related

Maven Compilation Failure. No compiler is provided in this environment [Mac OS]

Maven suddenly stopped compiling with the error below. It was working this morning and I'm not sure what caused this.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project ExampleProject: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
Basic Information:
OS: Mac
Machine: MacBook Pro
Java: 1.8.0_201 (jdk8)
Maven: 3.8.1
What I tried:
Checked for existence of Java compiler
$ javac -version
javac 1.8.0_201
Check $JAVA_HOME : I got /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home, which is correct for Mac OS according to Maven's installation instructions
Added mvn to PATH before compiling
Reinstalled Maven 3.8.1
Reinstalled JDK8 and reset JAVA_HOME & added mvn to PATH again before compiling
Added sudo to my command. In fact before adding sudo, I was facing some sorta "failed to delete something" error.
Restarting my laptop without using the "Reopen windows...." option.
Adding the compiler option to pom.xml(I didn't need this when it was working this morning)
Running mvn -v give me the output below
Maven home: /opt/apache-maven-3.8.3
Java Version: 1.8.0_201, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.8.0_201.jdk/Contents/Home/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"
Running java -version gave me the output below:
java version "1.8.0_201"
Java (TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot (TM) 64-Bit Server VM (build 25.201.b09, mixed mode)
Additional Info:
I am not using any IDE like Eclipse/IntelliJ/NetBeans. Just purely on terminal. Please base your answers on this.
It seems like there are 2 versions of Maven on my system, probably due to the reinstall. But prior to the reinstall, this problem already started
Reference (I've tried the solutions in here too)
https://roufid.com/no-compiler-is-provided-in-this-environment/
Edit
I have already made sure that JAVA_HOME points to the JDK and not the JRE by consulting Maven's documentation
Maven needs javac to compile your project. Can you try javac -version and see if your able to get an output.
$ javac -version
javac 1.8.0_201
If not set your JAVA_HOME to JDK not to JRE. C:\Program Files\Java\jdk1.8.0_202
If you are still getting this error, try opening another terminal for the environment variable to reflect. And try.
Regards

checkstyle plugin throwing major.minor 52 error on maven package, development env problem

I believe this is an issue with my development environment since I was able to build this jar before I needed switch to a new laptop.
I need to build this jar with java version 1.7 due to production environment requirements.
In the pom.xml I have the properties
<properties>
<checkstyle.version>8.10.1</checkstyle.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
bash-3.2$ java -version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
bash-3.2$ mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 1.7.0_80, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"
When I run:
mvn package -DbuildNum=1.0.0-SNAPSHOT
It fails with the output:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check (compile) on project syn-dap-hadoop: Execution compile of goal org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check failed: An API incompatibility was encountered while executing org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0:check: java.lang.UnsupportedClassVersionError: com/puppycrawl/tools/checkstyle/api/CheckstyleException : Unsupported major.minor version 52.0
Changing my JAVA_HOME to java 1.8 allows it to build properly, but I need it to be built in 1.7 for the environment it runs in.
Usually, it is no problem to build with JDK 1.8 for Java 1.7. The resulting artifacts will run on a Java 1.7 environment just fine.
If you don't want this, you need to downgrade your checkstyle plugin to a version that still support Java 1.7.

mvn -version on command line showing different version of Java

I played around with jenv today, to setup Java 1.8 as global version and 1.7 for one project locally. Since then mvn command in the global locations is showing java version 12 -
SandeepanNath:current sandeepan.nath$ mvn -version
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:47+05:30)
Maven home: /Users/sandeepan.nath/.sdkman/candidates/maven/current
Java version: 12.0.1, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk-12.0.1.jdk/Contents/Home
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.3", arch: "x86_64", family: "mac"
Whereas Java version is showing as expected -
SandeepanNath:.ssh sandeepan.nath$ java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
I tried uninstalling and installing maven via sdkman again, on Mac. Although it did not download it fresh. I am still getting the same error.
How do I fix this?
probably your answer might already be here: https://stackoverflow.com/a/7033062/4424668
I guess, you have set up a JAVA_HOME environment variable at some point, which points to a Java 12-Installation.
What might actually be the solution to your specific problem (Jenv + Maven) is written here: https://stackoverflow.com/a/37466252/4424668
You might need to enable the maven Plugin for Jenv by calling jenv enable-plugin maven. Afterwards, Maven should consider the version activated by Jenv.
Edit:
Since you actually use SDKMAN für managing maven candidates, you might consider using SDKMAN for Java Candidates as well. Anyhow, maybe the maven plugin does not actually fix your SDKMAN maven candidates. An even easier solution may be to enable the export-plugin instead, which actually sets the Environment Variable directly. Have a look about that on the Github-Page of Jenv: https://github.com/jenv/jenv

Maven: Fatal error compiling: invalid target release: 1.8

We just upgraded the project from jdk 1.6 to jdk 1.8. While building the project in my machine, i'm getting following error.
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-compiler-plugin:3.3:compile
(default-compile) on project exception: Fatal error compiling: invalid
target release: 1.8 -> [Help 1]
Here is the maven compiler plugin which is been used
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
I looked at the many post and most of them were related with not having the correct version configured for java_home. I verified all of these aspects and couldn't find any of them alarming.
Java version -
qadeersmsiphone:main pdubey$ java -version
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Maven Version -
qadeersmsiphone:main pdubey$ mvn -version
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 08:22:22-0700)
Maven home: /usr/share/maven
Java version: 1.8.0_51, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.5", arch: "x86_64", family: "mac"
and I checked that while building the project maven uses jdk 1.8
qadeersmsiphone:main pdubey$ mvn install -debug
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 08:22:22-0700)
Maven home: /usr/share/maven
Java version: 1.8.0_51, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.5", arch: "x86_64", family: "mac"
[INFO] Error stacktraces are turned on.
[DEBUG] Reading global settings from /usr/share/maven/conf/settings.xml
[DEBUG] Reading user settings from /Users/pdubey/.m2/settings.xml
[DEBUG] Using local repository at /Users/pdubey/.m2/repository
[DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/pdubey/.m2/repository
[INFO] Scanning for projects...
UPDATE: I could get it working by removing the
maven-compiler-plugin in pom file (Ideally, i don't want to do this). And i also observed that even if i
remove this plugin, maven by default downloads the 3.3 version of
compiler plugin in my local repo. I'm not sure what's wrong in this
plugin although source and target appears to be correct.
Check the java and Javac version - My Java version was 1.8.0_51
$ java -version
java version "1.8.0_51"
But javac version was pointing to old jdk 1.7.0_67
$ javac -version
javac 1.7.0_67
There are couple of thing which we should try -
Ensure that symbolic link is pointing to correct jdk. If not, remove existing link and create new one for your jdk
cd /System/Library/Frameworks/JavaVM.framework/Versions/
rm CurrentJDK
ln -s /Library/Java/JavaVirtualMachines/<jdk version>.jdk/Contents/ CurrentJDK
In /Library/Java/Extension, i had a tools.jar. I believe, this was from old jdk.
cd /Library/Java/Extensions
-rw-r--r-- 1 root admin 15286304 Jan 14 2015 tools.jar
Remove this
sudo rm -rf /Library/Java/Extensions
point 2 did the trick for me :)
Sometimes this problem is related to a JAVA_HOME used by maven.
In my particular case I tried to start an install target and had an exact the subj message.
Then I just tried an mvn -version command and I realized that it uses jdk7
Then I run in a console set JAVA_HOME=C:\Java\jdk8 (my jdk path, so your own could be different)
Then typed mvn clean install test and it worked just fine at last
Good luck!
Same issue here, but I was using run configurations inside Eclipse when maven kept throwing this error. Fixed by setting the right JDK version here:
I had the same issue:
> java -version
java version "1.8.0_111"
>javac -version
javac 1.7.0.6
I checked the Path in System variables, and the jdk was not updated to jdk 8.
After I updated the path with the right jdk it worked.
In cent os we can use alternatives to switch the version.
alternatives --config javac
alternatives --config java
But MAVEN uses JAVA_HOME.
And this JAVA_HOME can be possible to a link.
Either we have to point the JAVA_HOME manually to new jdk folder, OR manually remove/delete the link and create a new same link again from above answers.
From alternatives we can get the path of jdk
First of all, it is definitely versions issue.
In my situation:
java -version showed the result
java version "1.8.0_172"
and javac -version was showing
javac 1.8.0_172
BUT: Maven uses JAVA_HOME environment variable to get your JDK version to build a project and run it's a plugin. So the way how we have to check it is
echo %JAVA_HOME%
Which in my situation was
jdk1.7.0_172
So simply change the path to the variable will solve the issue.
Hope it will save time to someone.

Cannot access DisposableBean and cannot access InitialzingBean

I'm trying to compile the oVirt open source project on fedora core 21,
java -version
openjdk version "1.8.0_20"
OpenJDK Runtime Environment (build 1.8.0_20-b26)
OpenJDK 64-Bit Server VM (build 25.20-b23, mixed mode)
I am getting the following errors:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project builtin: Compilation failure: Compilation failure:
[ERROR] /home/jenkins/workspace/ovirt-engine_master_find-bugs_merged_nomvn/ovirt-engine/backend/manager/modules/builtin-extensions/src/main/java/org/ovirt/engine/extensions/aaa/builtin/kerberosldap/utils/ipa/SimpleAuthenticationCheck.java:[61,25] error: cannot access InitializingBean
[ERROR] /home/jenkins/workspace/ovirt-engine_master_find-bugs_merged_nomvn/ovirt-engine/backend/manager/modules/builtin-extensions/src/main/java/org/ovirt/engine/extensions/aaa/builtin/kerberosldap/LDAPTemplateWrapper.java:[145,31] error: cannot access DisposableBean
mvn -version shows :
mvn -version
Apache Maven 3.2.2 (NON-CANONICAL_2014-06-19T11:19:24_mockbuild; 2014-06-19T11:19:24+00:00)
On fedora core18 it works -
Apache Maven 3.0.4 (rNON-CANONICAL_2013-04-08_07-49_mockbuild; 2013-04-08 10:49:23+0300)
Maven home: /usr/share/maven
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.9.11-200.fc18.x86_64", arch: "amd64", family: "unix"
The spring that is being used is aligned to 3.1.1.RELEASE from what I can see
In both the machines.
Can you give a hand? I know I'm using code that implements InitialzingBean and DisposableBean, but still - if same spring version, how come it does not compile
we had this problem and we had installed JDK 1.8. When we installed JDK 1.7 then this issue disappeared. Try it, maybe it is your case :)

Categories

Resources