I have a NetBeans Platform project build with Maven2. When I try to create a new platform module I get this strange error:
cd ~/src; JAVA_HOME=/usr/lib/jvm/jdk1.7.0/bin/java ~/netbeans-7.3/java/maven/bin/mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes...
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/jdk1.7.0/bin/java/bin/java
In ~/.bashrc I have definition of JAVA_HOME:
export JAVA_HOME="/usr/lib/jvm/jdk1.7.0"
export JDK_HOME="/usr/lib/jvm/jdk1.7.0"
There's no slash at the end, however maven appends /bin/java/bin/java to this path. I can build already existing module with Maven without problems, just when creating a new one it fails. Where does Maven get this JAVA_HOME?
EDIT:
maven settings:
$ mvn -version
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
Java version: 1.7.0_17
Java home: /usr/lib/jvm/java-7-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "3.2.0-39-generic" arch: "amd64" Family: "unix"
You're redefining JAVA_HOME on the command line to point to /usr/lib/jvm/jdk1.7.0/bin/java, which is wrong:
cd ~/src; JAVA_HOME=/usr/lib/jvm/jdk1.7.0/bin/java ...
Remove the JAVA_HOME=/usr/lib/jvm/jdk1.7.0/bin/java from the command line:
cd ~/src; ~/netbeans-7.3/java/maven/bin/mvn -DarchetypeGroupId=org.codehaus.mojo.archetypes...
netbeans takes the JAVA_HOME from the definition of the Java Platform in the IDE (See Tools/Java Platforms)
unless you select a custom platform, IDE uses the default one which is the one the IDE is running on.
All platforms need to be defined in the Tools/Java Platforms dialog and validation checks are in place to select the right folder.
Maybe something changed in time for you and the definition there is not correct?
the problem was with incorrect definition of JAVA_HOME in ~/.bash_profile
NetBeans integration of maven prefers:
System.getenv("JAVA_HOME")
before:
System.getProperty("java.home")
for linux find the mvn executalble file under netbeans's java/maven/bin folder and add
from="/bin/bin/java"
to="/bin/java"
JAVACMD="${JAVACMD/$from/$to}"
before the lines
if [ ! -x "$JAVACMD" ] ; then
echo "Error: JAVA_HOME is not defined correctly."
cheers
Related
When I try to execute the command
mvn clean javadoc:jar package
it shows
the JAVA_HOME environment variable is not defined correctly. This environment variable is needed to run this program.
NB: JAVA_HOME should point to a JDK, not a JRE.
I checked out the already asked question Unable to find javadoc command - maven and the solution I tried above were taken from this solution only. I am new to Ubuntu. How can I fix this?
Whereas when I run echo $JAVA_HOME it prints:
/usr/lib/jvm/java-11-openjdk-amd64
I also tried setting the JAVA_HOME to:
/etc/launchd.conf/java-11-openjdk-amd64
/usr/libexec/java-11-openjdk-amd64
/usr/libexec/java-11-openjdk-amd64/
When I run mvn -v, it prints:
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.10, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "5.8.0-45-generic", arch: "amd64", family: "unix"
And when I run echo $JAVA_HOME it prints:
/usr/lib/jvm/java-11-openjdk-amd64
Hmm..., probably the file doesn’t exist for running javadoc. Does the file /usr/lib/jvm/java-11-openjdk-amd64/bin/javadoc exist?
Please try:
sudo apt install openjdk-11-jdk
I would remove the above listed packages with pattern openjdk-11-.* (see this question) and install Java like this.
On my Mac (big Sur) I was getting the same problem. After reading this article ; this command worked for my enviroment:
export JAVA_HOME=$(/usr/libexec/java_home)
Before I start, let me tell you that I've been Googling for about an hour or two now, so please don't respond to this question saying "Hey! You know that there's plenty of answers on Google?"
Now to the question: whenever I run mvn clean package, I get the this error No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?. I've checked my Java versions, and these are the outputs.
Java JRE
java -version returned java version "1.8.0_181"
Java JDK
javac -version returned javac 1.8.0_181
Maven version
mvn -version returned
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T20:33:14+02:00)
Maven home: C:\Program Files\Apache\maven
Java version: 1.8.0_181, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jre1.8.0_181
Default locale: nl_NL, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
From what I found on Google, there should be a line saying Java Home or something followed by the JDK version and it's path. As you can see, It's not appearing here. I've tried setting the JAVA_HOME variable multiple times, and I verified that it works, by executing echo %JAVA_HOME, which returned it's proper path.
Any help?
EDIT
Output of echo %JAVA_HOME%: C:\Program Files\Java\jdk1.8.0_181
System variables:
Do you have JDK_HOME, JAVA_HOME and MAVEN_HOME environment variables set?
As #Chris311 says in his comment echo %JAVA_HOME or set in Windows will show if the environment variables was set and set correctly.
set JAVA_HOME
And yes, JAVA_HOME should point to JDK, not a JRE. For example, for my Windows Machine, it is JAVA_HOME=C:\Program Files\Java\jdk1.8.0_181.
Update
As we figured out, it did not work in the git bash console, but it worked in the command line. I tested mvn clean package myself, it seemed to be working. However, some commands that work in cmd do not work in git bash, for example set java_home or cd to a path with \ (I needed to use /).
I had the same issue('mvn clean install' was working on the cmd, but not in the Git Bash) and it was resolved by removing the following from the path variable in Environment variables
"C:\Program Files (x86)\Common Files\Oracle\Java\javapath"
while running maven clean I am getting the following error :
Error: Could not find or load main class $MAVEN_HOME
while doing mvn -version I got :
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T22:11:4
7+05:30)
**Maven home: D:\mavenSecurity\apache-maven-3.3.9\bin\..**
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_79\jre
Default locale: en_IN, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
I have set MAVEN_HOME = D:\mavenSecurity\apache-maven-3.3.9 in user variable in environment setting
Path in system variable in environment setting : D:\mavenSecurity\apache-maven-3.3.9\bin
Since I am getting other error previously so I have done the following also as mentioned in this post:
Eclipse error setting up Maven project for class exercise: Check $M2_HOME environment variable and mvn script match
-Dmaven.multiModuleProjectDirectory=$MAVEN_HOME
I have consulted other links but still I am getting the error while running MAVEN CLEAN in eclipse juno
This worked for me with the 3.3.9 version. The only difference is :
1) Add both M2_HOME and MAVEN_HOME variables in the Windows environment, and point it to your Maven folder (Note: I have added it to system variables)
2) Update PATH variable, append Maven bin folder – %M2_HOME%\bin, so that you can run the Maven’s command everywhere
Post output of mvn –version again if you face the issue. Also try running mvn clean from the command line and post the results.
configuring Maven on Eclipse. you have to tell eclipse where Maven has been installed so that it can use the Maven installation to build our projects.
Win 7 64 . Here is how i did my config.
When running the 'perform tests' command in Roo I get the following error:
createprocess error=2,the system cannot find the file specified.
Now, all the posts on the net suggest that maven should be in PATH. I did that, I rebooted, my maven installation path is in there along with my roo path and java path. I have ROO_HOME set, JAVA_HOME and M2_HOME.
The versions I use are:
Maven: 3.3.1
Roo: 1.3.1.RC1
Java: 1.8.0_45
When I run Maven from the commandline i get this:
X:\...>mvn -v
Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-13T21:10:27+01:00)
Maven home: X:\apache-maven-3.3.1
Java version: 1.8.0_45, vendor: Oracle Corporation
Java home: X:\Java\jdk1.8.0_45\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "dos"
Maven seems to be fully functional.
I also can start the roo console from the commandline:
X:\...> roo
1.3.1.RC1 [rev 4877cfb]
Welcome to Spring Roo. For assistance press CTRL+SPACE or type "hint" then hit ENTER.
roo> perform tests
CreateProcess error=2, The system cannot find the file specified
roo>
So my question is, does anybody know if this is a bug? Because I'm under the serious impression that it is. Posts that 'supposedly' solve this problem are 2y or older.
Thanks for the help!
Got the same problem.
Roo is searching for mvn.bat file in the maven's bin directory, but in the version 3.3.1, there is mvn.cmd only.
Try either renaming the mvn.cmd to mvn.bat in your maven bin directory (worked for me), or use older version of maven, for example 3.0.4.
Thanks for the suggestion! Instead of renaming though, if you use a recent version of Windows (10 in my case) you can create a symlink as well. Open admin command prompt > navigate to your maven bin folder > and execute the command:
mklink mvn.bat mvn.cmd
hint: I also do this if I need to swtich between maven versions, pointing my m2_home to a symlink and just switching the symlink when needed to point to the right place.
This appears to be a problem I do not see on linux or Windows machines. I have my environment setup with a JAVA_HOME derived from /usr/libexec/java_home. This is in my .bashrc file:
export JAVA_HOME=$(/usr/libexec/java_home -version 1.7)
which results in:
~/dev/Endeavor/endeavor-sdk$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home
However when I run Maven on my project, I get an error from the native2ascii plugin:
[ERROR] Failed to execute goal org.codehaus.mojo:native2ascii-maven-plugin:1.0-alpha-2-SNAPSHOT:native2ascii (default) on project dataAccessServices: Error starting Sun's native2ascii: -> [Help 1]
My investigation points to that I am using a JRE instead of a JDK. That's odd since I am clearly pointing to the JDK in my JAVA_HOME variable. However, here is the output of mvn -version:
~/dev/Endeavor/endeavor-sdk$ mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 03:44:56-0500)
Maven home: /usr/share/maven
Java version: 1.7.0_17, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.7.5", arch: "x86_64", family: "mac"
Notice the "Java home:" line indicates that the ${java.home} variable has been moved to the JRE instead of the JDK that the JAVA_HOME environment variable points to.
I have tried setting the JAVA_HOME in numerous places but I can't seem to find a way to get maven to use the JDK as the home and not the JRE.
UPDATE:
I found this that appears to indicate that this is expected behavior: Java_home in Maven
But that does not explain why the native2ascii plugin cannot find the JDK tool it needs.
I have removed the use of native2ascii since it was largely unnecessary. So, I am avoiding the problem at this point. However, if anyone has an idea as to why this behaves differently on different systems, please let me know.
Have you tried running mvm help:system that should print all environment variable values that are relevant to maven?
There has been lots of discussions on this matter and here Java_home in Maven you can find a real good answer.
In a nutshell: your configuration it's just right, it is just a matter of semantics. You can read further here: http://javahowto.blogspot.com/2006/05/javahome-vs-javahome.html