I am having the below issue when I run my maven build in eclipse. I saw many posts like this but i still can't solve this problem .Mine may be a little more specific, I know that my JAVA_HOME is pointed to java6, and that is because I am working on another application which uses java 6. The application in which I am running into issues uses Java 8
[ERROR] COMPILATION ERROR : [INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in: C:\Program Files\Java\jre1.8.0_92\..\lib\tools.jar Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required). .In most cases you can change the location of your Java installation by setting the JAVA_HOME environment variable. [INFO] 1 error
<br>[INFO] -------------------------------------------------------------
<br>[INFO] ------------------------------------------------------------------------
<br>[INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------
<br>[INFO] Total time: 11:53 min [INFO] Finished at: 2016-08-18T16:52:13+05:30
<br>[INFO] Final Memory: 11M/141M
<br>[INFO] ------------------------------------------------------------------------
<br>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project
Compilation failure [ERROR] Unable to locate the Javac Compiler in: [ERROR] C:\Program Files\Java\jre1.8.0_92\..\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).
<br>[ERROR] In most cases you can change the location of your Java [ERROR] installation by setting the JAVA_HOME environment variable.
[ERROR] -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile
How can I resolve this problem without installing java 8 as it may may make changes to my JAVA_HOME etc which would make my other application to not run. Is there a way to get the JDK folder without running the .exe (p.s I already tried the 7zip method)
Please suggest
If you have the jdk8 then you can open cmd, run the command in this window to modify the JAVA_HOME set JAVA_HOME=<jdk8 path>. This will modify the JAVA_HOME env variable only for this instance of the cmd session and not for the whole OS. Now run the maven build command from this window and it wont fail.
If you wanna run the build from eclipse, then in eclipse try going to Windows --> Preferences --> Java --> Installed JREs --> click Add button --> Sel Standard VM and click next --> put in values for 'JRE Home' as path till the jdk folder and 'JRE Name' as java8 or whatever you wish --> click Finish.
Now right click the project of you interest --> click properties --> Java Compiler --> Tick 'Enable project specific settings' --> and select 1.8 here.
If 1.8 is not visible here, go to Java Build Path --> Add Library --> JRE System Library --> Alternate JRE --> select jdk8 --> Finish
Looking at the path in that error (C:\Program Files\Java\jre1.8.0_92\..\lib\tools.jar) you've installed the Java Runtime Environment (JRE).
To compile java you need the Java Development Kit (JDK) which contains the tools the maven plugin needs.
You can change your maven-compiler-plugin configurations to your JAVA_HOME.
Just go to eclipse window->preferences->type maven->and you could see something like template click on that and look for javac compiler, just go there and change to whatever java version you have.
<configuration>
<!-- http://maven.apache.org/plugins/maven-compiler-plugin/ -->
<source>${cursor}1.6</source>
<target>1.6</target>
</configuration>
Without java8 and without .exe file you can't go ahead with your requirement.
Hope it's useful.
from your error log it says that
[ERROR] Unable to locate the Javac Compiler in: [ERROR] C:\Program Files\Java\jre1.8.0_92\..\lib\tools.jar
paste this code in your pom.xml inside build tag and make sure you add dependencies properly and please change your java version accordingly
this will only work if you have something wrong in your pom.xml.
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_HOME}/bin/javac</executable>
<compilerVersion>1.8</compilerVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.2</version>
<configuration>
<jvm>${JAVA_HOME}/bin/java</jvm>
<forkMode>once</forkMode>
</configuration>
</plugin>
</plugins>
note your JAVA_HOME must point like this
C:\Program Files\Java\jdk1.8.0_65
edit
There must be various reasons like
your pom is not getting path to java home
your java home is not set
you are using jre instead of jdk in your IDE
You can download the version of the JDK without installer.
Then specify a JDK 1.8 as source and target in the compiler configuration of the pom.xml with which you have your problem. in this way you don't need changing your JAVA_HOME :
<build>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerVersion>1.8</compilerVersion>
<fork>true</fork>
<executable>D:\jdk1.8\bin\javac</executable>
</configuration>
</plugin>
<build>
I followed steps in the below link to get the portable JDK:
http://bgasparotto.com/convert-jdk-exe-zip/
Related
I see lots of answers to this question but they don't work for me. I installed Visual Studio Code, latest version of Java and Maven on my PC and I was able to successfully build my application with Maven on the PC. I then went through the same steps on my Mac and I get this error.
Fresh versions of Macos, Visual Studio Code, Maven and Java. Like all the others have said, I added these lines to the properties section of my pom.xml file:
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Still get the same error. Here is the relevant output from the mvn build:
alberts-mbp:com.versabuilt.rushmore.process albertyoungwerth$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ---------< com.versabuilt.rushmore.process:VersaBuiltProcess >----------
[INFO] Building VersaBuilt Process 0.2.18
[INFO] -------------------------------[ bundle ]-------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.2:resources (default-resources) # VersaBuiltProcess ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.6.0:compile (default-compile) # VersaBuiltProcess ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 10 source files to /Users/albertyoungwerth/rushmore/com.versabuilt.rushmore.process/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] Source option 6 is no longer supported. Use 7 or later.
[ERROR] Target option 6 is no longer supported. Use 7 or later.
[INFO] 2 errors
I have also restarted Visual Studio Code to no avail.
The last build system I used was called make, so it's been a while since I debugged a build process. I don't remember make dumping 62Kb of debug output either...
Anywho, searching for the keyword "source" (clue being that was one of the tags I was supposed to add) got me to this in the maven debug output:
[DEBUG] (f) source = 1.6
Ahaaa! the source compiler version had not changed like I asked it to with the edit in my original question! I'll bet the maven folks changed the location of the xml tag! Sure enough, searching for 1.6 in the pom.xml file I find this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
I changed the source and target tag values to 1.8 and it worked! I also tried deleting the source and target tags in the build plugins scope and left in the maven.compiler.source/target values set to 1.8 and that also worked.
So moral of the story, be careful of extra source or target tags in your pom.xml file!
Actually, I too faced the above error message, after adding this to property file, Error got resolved. :)
property need to be added in pom.xml
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
I corrected this problem by matching the jdk between my IDE and the pom.xml file.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Sometimes changing from Kotlin to java or inverted.
You can also change or java version to a higher one.
At least that worked for me.
Changing maven compiler version in pom file solved my issue.
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target>
go to your project properties and go to sources.
then in Source/binary format it will be JDK 5 or 6 etc.
but click and make it the higher version.
you are done.:)
I am trying to deploy a java jar to heroku with heroku maven plugin.
I am using java 11 so I have added system.properties in the root folder(where pom.xml is present) and set java.runtime.version=11. However it doesn't seem to be working !
My plugin :
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<includeTarget>false</includeTarget>
<includes>
<include>${project.build.directory}/${project.build.finalName}.jar</include>
</includes>
<processTypes>
<web>java $JAVA_OPTS -jar ${project.build.directory}/${project.build.finalName}.jar</web>
</processTypes>
</configuration>
</plugin>
When I do git push heroku master it starts build process using jdk 8.
remote: Building source:
remote:
remote: -----> Java app detected
remote: -----> Installing JDK 1.8... done
remote: -----> Installing Maven 3.6.2... done
remote: -----> Executing Maven
remote: $ mvn -DskipTests clean dependency:list install
Eventually build fails with error :
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project ImpactHub_bot: Fatal error compiling: invalid flag: --release ->
How do I set jdk verison to 11 ? I have also tried adding ${java.version} to configuration but it didn't help
That's exactly how you are specifying the Java version, see: https://devcenter.heroku.com/articles/java-support#specifying-a-java-version
You can specify a Java version by adding a file called
system.properties to your application.
Set a property java.runtime.version in the file:
java.runtime.version=11
I used it in my project as well and it is working.
Make sure your system.properties is saved as All Files. Furthermore it should be at the root folder of your git repo.
It might have a .txt ending. If that fails open a Support Ticket with Heroku.
After adding module-info.java files to my project my checkstyle plugin start failing with:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check
(default-cli) on project email: Failed during checkstyle
configuration: NoViableAltException occurred during the analysis of
file
/home/xxx/IdeaProjects/blynk-server/server/notifications/email/src/main/java/module-info.java.
unexpected token: module -> [Help 1]
I tried
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>
However, it failed with:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check
(default-cli) on project blynk: Failed during checkstyle
configuration: cannot initialize module
BeforeExecutionExclusionFileFilter - Unable to instantiate
'BeforeExecutionExclusionFileFilter' class, it is also not possible to
instantiate it as
com.puppycrawl.tools.checkstyle.checks.annotation.BeforeExecutionExclusionFileFilter
What is the correct way for skipping module-info.java files during checkstyle for maven-checkstyle-plugin?
Not sure why the Checkstyle filter is not working (this reported bug seems very similar to yours and it was fixed in version 7.3.0, so maybe you need to update Checkstyle).
Anyway the Maven excludes element is also supposed to do this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<excludes>**/module-info.java</excludes>
</configuration>
</plugin>
More in the plugin goal documentation.
BeforeExecutionExclusionFileFilter was added in Checkstyle 7.2.
But the maven-checkstyle-plugin version 3.0.0 (which is the latest version as of 2018-04-01) uses Checkstyle 6.18 by default.
"Checkstyle" and "Checkstyle Maven Plugin" are different things and have different release cycles.
You may want to upgrade the Checkstyle version as follows:
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version> <!-- Checkstyle Plugin version -->
<!-- ... Configuration, Executions ... -->
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.8</version> <!-- Checkstyle version -->
</dependency>
</dependencies>
</plugin>
After that, BeforeExecutionExclusionFileFilter as well as other newer Checkstyle features (e.g. new checks) will be recognized.
Though this doesn't possibly qualify as an answer. Yet being too long to fit in comment, just to keep a note of the track that the maven-checkstyle-plugin is in:-
The last release of the was version 2.17 on 15-Oct-2015 which was almost 2 years back.
The current trunk of maven-plugins points to an ongoing work within the plugin in its 3.0.0-SNAPSHOT version which might mean we can soon expect a org.apache.maven.plugins:maven-checkstyle-plugin:3.0.0 sometime in near future and which would understand the module-info.java as a class.
This doesn't align with the Java+9+-+Jigsaw doc that specifies the list of modules and plugins that are being upgraded to support JDK-9.
I have Java version 1.8.111 installed and the initial error message after running mvn3 install was as below.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-toolchains-plugin:1.1:toolchain (default) on project myfile: Cannot find matching toolchain definitions for the following toolchain types:
[ERROR] jdk [ vendor='sun' version='1.6' ]
[ERROR] Please make sure you define the required toolchains in your ~/.m2/toolchains.xml file.
To resolved this, I've updated my toolchains.xml to version 1.8.111 but still getting the same error. I've also tried after running mvn3 clean and successfully cleaned but still getting the same error.
Could anyone pinpoint where this version 1.6 is fetched from?
I checked JAVA_HOME already, it's set to 1.8.
Can anyone explain how maven calls Java version?
Appreciate your help.
Below is my toolchains.xml
Your application is expected to be built with JDK 1.6 and to locate it Maven is looking for definition of [ vendor='sun' version='1.6' ] within toolchains.xml in your {home}/.m2/ directory (see eg this maven guide). You just need to point to it and all should be good.
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>1.6</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>/Library/Java/JavaVirtualMachines/jdk1.6.X_XX.jdk/Contents/Home</jdkHome>
</configuration>
</toolchain>
</toolchains>
While running mvn install on a fragment project in Eclipse I got this error:
${fragment name} cannot be installed in this environment because its filter is not applicable.
Using Eclipse-PlatformFilter: (osgi.os=macosx) in the Manifest breaks the build.
Here's the output surrounding the key error (IDs/directory names redacted):
[INFO] Resolving dependencies of MavenProject: ${fragmentID}:4.3.0-SNAPSHOT # ${fragmentDir}/pom.xml
[INFO] {osgi.os=linux, org.eclipse.update.install.features=true, osgi.arch=x86_64, osgi.ws=gtk}
[ERROR] Cannot resolve project dependencies:
[ERROR] Problems resolving provisioning plan.:
[ERROR] ${fragment name} cannot be installed in this environment because its filter is not applicable.
[ERROR]
[ERROR] See http://wiki.eclipse.org/Tycho/Dependency_Resolution_Troubleshooting for help.
The link (http://wiki.eclipse.org/Tycho/Dependency_Resolution_Troubleshooting) doesn't help.
I found a few similar errors on the internet (component X cannot be installed in this environment because its filter is not applicable), but they all apply to instances where it's downloaded software and there's either no solution or the solution isn't applicable to my case.
Grateful for any help!
Edit:
I found that using Eclipse-PlatformFilter: (osgi.os=macosx) in the host plugin works, and also Eclipse-PlatformFilter: (| (osgi.os=macosx) (osgi.os=linux) (osgi.os=win32) ) in the fragment works. It seems that the build goes through each environment set in an ancestor pom, and it breaks when the fragment doesn't apply for any one of those environments.... surely there's some flag I could set to prevent that?
Tycho builds for all the operating system environments configured through the POM. There is currently no way to automatically filter these environments to what is configured as Eclipse-PlatformFilter. So when building a fragment only for a certain operating system, you need to manually override the <environments> configuration from your parent POM in the POM of the fragment:
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<environments>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>