How do I setup VSCODE to create Maven projects? - java

I recently installed Visual Studio Code and am now trying to create a Maven project. When I first tried to create a Maven project, I received an error about the JAVA_HOME setting, so I fixed that. Next I received an error saying it couldn't find an executable or script file in the Maven > Executable: Path folder. I disabled the setting named Maven > Executable: Prefer Maven Wrapper, and then I changed found the mvnw.cmd file and added the path to that folder to my settings (shown below):
C:\Users\user1\.vscode\extensions\vscjava.vscode-maven-0.21.4\resources\maven-wrapper
Now when I try to create the Maven project, I just get the following in TERMINAL window and no project is created:
>> cd "c:\Users\user1\Documents\Bidi\Source\Maven"
>> & "C:\Users\user1\.vscode\extensions\vscjava.vscode-maven-0.21.4\resources\maven-wrapper\" org.apache.maven.plugins:maven-archetype-plugin:3.1.2:generate -DarchetypeArtifactId="maven-archetype-quickstart" -DarchetypeGroupId="org.apache.maven.archetypes" -DarchetypeVersion="1.4"
>> "
Has anyone seen this problem and figured out how to fix it?

I was finally able to resolve the issue. After looking at Microsoft's troubleshooting page on GitHub here (https://github.com/microsoft/vscode-maven/blob/master/Troubleshooting.md), I searched for folders containing "apache-maven". I was then able to find the folder with the mvn file. I then entered the full path, including the file name in the maven.executable.path property and it worked. The full path was like this:
C:\Users\user1\.m2\wrapper\dists\apache-maven-3.6.3-bin\abc123abc123abc123XX\apache-maven-3.6.3\bin\mvn

Step 1 - Verify Java Installation on your Machine
Open console and execute the following java command.
OS Task Command
-Windows Open Command Console c:> java -version
-Linux Open Command Terminal $ java -version
-Mac Open Terminal machine:~ joseph$ java -version
Let's verify the output for all the operating systems −
If you do not have Java installed, install the Java Software Development Kit (SDK) from https://www.oracle.com/technetwork/java/javase/downloads/index.html. We are assuming Java 1.7.0.60 as installed version for this tutorial.
Step 2 - Set JAVA Environment
Set the JAVA_HOME environment variable to point to the base directory location where Java is installed on your machine. For example −
OS Output
Windows Set the environment variable JAVA_HOME to C:\Program Files\Java\jdk1.7.0_60
Linux export JAVA_HOME=/usr/local/java-current
Mac export JAVA_HOME=/Library/Java/Home
Append Java compiler location to System Path.
Verify Java Installation using java -version command as explained above.
Step 3 - Download Maven Archive
Download Maven 2.2.1 from https://maven.apache.org/download.cgi.
OS Archive name
Windows apache-maven-3.3.1-bin.zip
Linux apache-maven-3.3.1-bin.tar.gz
Step 4 - Extract the Maven Archive
Extract the archive, to the directory you wish to install Maven 3.3.1. The subdirectory apache-maven-3.3.1 will be created from the archive.
OS Location (can be different based on your installation)
Windows C:\Program Files\Apache Software Foundation\apache-maven-3.3.1
Linux /usr/local/apache-maven
Step 5 - Set Maven Environment Variables
Add M2_HOME, M2, MAVEN_OPTS to environment variables.
OS Output
Windows
Set the environment variables using system properties.
M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.3.1 M2=%M2_HOME%\bin MAVEN_OPTS=-Xms256m -Xmx512m
Linux
Open command terminal and set environment variables.
export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.1 export M2=$M2_HOME/bin
export MAVEN_OPTS=-Xms256m -Xmx512m
export M2=$M2_HOME/bin
export MAVEN_OPTS=-Xms256m -Xmx512m
Step 6 - Add Maven bin Directory Location to System Path
Now append M2 variable to System Path.
OS Output
Windows Append the string ;%M2% to the end of the system variable, Path.
Linux export PATH=$M2:$PATH
Mac export PATH=$M2:$PATH
Step 7 - Verify Maven Installation
Now open console and execute the following mvn command.
OS Task Command
Windows Open Command Console c:> mvn --version
Linux Open Command Terminal $ mvn --version
Finally, verify the output of the above commands, which should be as follows −

Related

Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java when i run gradle command in terminal

I am working in Ubuntu 16.04. I need to install gradle and the gradle is installed when i checked with sudo apt list --installed command but when i use gradle -version command it shows the following error,
JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java
In sudo vim /etc/environment file,
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/"
http_proxy="http://username:password#IP:port no/"
https_proxy="https://IP:port no/"
ftp_proxy="ftp://IP:port no/"
I don't know where i made mistakes. Please help me.
Thanks.
On a 64bit openSuse 64 42.1 box;
readlink -f $(which java)
provided;
/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/jre/bin/java
But;
export JAVA_HOME=/usr/lib64/jvm/jre-1.8.0-openjdk
is the path that worked and allowed java emulator to run.
So i think we have to manually browse our file system and see what path to choose.
Today I faced this problem. I am using the default java that comes with your linux distro (so in my case, linux mint).
$ whereis java
This command gave me
java: /usr/bin/java /usr/share/java
So, I opened /user/bin. There was a link to Java. I right clicked it and selected follow original link. This lead me to /usr/lib/jvm/java-11-openjdk-amd64/bin/java.
So now that I know where this java is, I opened my .bashrc file, and edited the JAVA_HOME.
So for my case,
## My Custom variables
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
This solved the problem.
Now if you are using some other java (say you downloaded from oracle and extracted the zip file ...), then you have to add that location. So for example, if your java is in /home/user/.sdkman/candidates/java/current, then
export JAVA_HOME=/home/user/.sdkman/candidates/java/current
export PATH=$JAVA_HOME/bin:$PATH
I see a mismatch. In your enviornment file the JAVA_HOME is set to "/usr/lib/jvm/java-8-openjdk-amd64/" and your mentioned that the error that you got relates to the JAVA_HOME as "/usr/lib/jvm/java-8-oracle/jre/bin/java"
If you JAVA is really installed in /usr/lib/jvm/java-8-oracle directory, then you need to ensure that the JAVA_HOME is set to that directory. And also your PATH reflects $JAVA_HOME/bin in it.
I typically install Oracle JDK/JRE separately in a separate directory such as /usr/local/jdk1.8.0 etc.
check the jvm installtion folder from Files
eg : /usr/lib/jvm/java-12-oracle
then in terminal run sudo nano /etc/environment and add the line
JAVA_HOME="/usr/lib/jvm/java-12-oracle"
Then open terminal and run
export JAVA_HOME="/usr/lib/jvm/java-12-oracle"

Unable to setup Maven in windows 7

I have installed JDk 8 and even dowloaded apache maven 3.3.3.Also I have set path for both Java and Maven but when I tried executing mvn --version command in command prompt then it is showing an error that "'mvn' is not recognized as internal or external command operable program or batch file"
Please follow the below steps in order to setup Maven on windows machine.
Please make sure to change your maven downloaded version. Hope you extracted in below location or you can do in any location and make sure to give correct path.
C:\Program Files\Apache Software Foundation\apache-maven-3.3.3
Then you need to set M2_HOME, M2, MAVEN_OPTS to environment variables.
M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.3.3
M2=%M2_HOME%\bin
MAVEN_OPTS=-Xms256m -Xmx512m
Done !!
Simply open new command prompt and check mvn -version
Assuming you are running on Windows, just define your M2_HOME variable to point to your maven installation folder and add %M2_HOME%\bin to your PATH variable.
This is a pretty decent tutorial: http://www.avajava.com/tutorials/lessons/what-is-maven-and-how-do-i-install-it.html
If you've followed the official installation instruction and it works when you specify mvn.bat, but not mvn then your PATHEXT environment variable needs to be adjusted:
set PATHEXT=.COM;.EXE;.BAT;.CMD
The command above is usually the default.
Steps to set-up Maven
Make sure JDK is installed, and JAVA_HOME variable is added as Windows environment variable.
Download the Maven zip file, for example : apache-maven-3.3.9-bin.zip. Unzip it to the folder where you want.
Assume you unzip to this folder – C:\Program Files\apache-maven-3.3.9
That’s all, just folders and files, installation is NOT required.
Add both M2_HOME and MAVEN_HOME variables in the Windows environment, and point it to your Maven folder.
Edit PATH variable, append Maven bin folder – %M2_HOME%\bin, so that you can run the Maven’s command everywhere.
Run mvn –version in the command prompt, if the below message is displayed the maven setup is done.
ENJOY CODING!!!

Given that NetBeans is installed, how can I use ant from the command-line (on Windows)?

I have NetBeans 8.0.2 installed on my Windows 7 (64-bit) machine. I have also the JDK installed (Java SE Development Kit 8 update 66 (64-bit)).
I want to run ant from the command line, but the closest I think I've come to getting it to run is the following:
java -jar "C:\Program Files\NetBeans 8.0.2\extide\ant\lib\ant.jar"
but I got the error
Error: Could not find or load main class org.apache.tools.ant.Main
I also tried the following, thinking that Main.class might be inside ant.jar, but got the same error:
java -cp "C:\Program Files\NetBeans 8.0.2\extide\ant\lib\ant.jar" -jar "C:\Program Files\NetBeans 8.0.2\extide\ant\lib\ant.jar"
I've spent at least an hour searching online and StackOverflow for the anser. The closest I've found is Compile NetBeans project from command line by using Ant, but it assumes that ant is accessible from the command line already.
To set up ant to work from the command line
Add C:\Program Files\NetBeans 8.0.2\extide\ant\bin to your PATH
Add the environment variable JAVA_HOME with the value C:\Program Files\Java\jdk1.8.0_66 (adjust this if you end up using a different version, of course).
Now that it is set up, simply use ant from the command line normally.
To rebuild the project, for example, simply do the following:
Open a new command prompt
Go to the project directory
Type ant clean jar

Cannot get Maven working on Windows 7 [duplicate]

I just installed Maven and added the \bin directory of maven to my path variables. When I try to use the mvn command in the Command Prompt I just get a message:
mvn: command not found
Everything else I found on here did not help yet.
Edit:
I used https://maven.apache.org/install.html to install maven.
SET PATH=%PATH%;C:\Program Files\Maven\apache-maven-3.5.0\bin\mvn.cmd
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
You have included the file in the path:
C:\Program Files\Maven\apache-maven-3.5.0\bin\mvn.cmd
That is not good. The PATH environment variable should only include a path to where files, like exe and cmd's can be found.
Adapt your PATH to read like this:
C:\Program Files\Maven\apache-maven-3.5.0\bin
(so remove the \mvn.cmd). Make sure to start a new command prompt to verify if your path settings are correct.
See How can I set user environmental variables (such as PATH) from a non-administrator account on Windows 7 to find the correct Windows dialog to adapt the settings among many more.
Following this tutorial by mkyong, I was able to get this to work on Windows 10 (v10.0.15063):
Install JDK and setup JAVA_HOME system variable
Download Maven zip, extract it and setup M2_HOME and MAVEN_HOME system variables to point to root maven folder (without \bin)
Update PATH system variable to include %M2_HOME%\bin (this is what will let you run "mvn" in Command Prompt).
Open Command Prompt (cmd.exe) and execute mvn -version
You can download Maven (apache-maven-3.5.0-bin.zip) here, if you don't have it already.
The Java SDK (jdk-8u144-windows-x64.exe) can be downloaded from Oracle here.
This is my working maven configuration on Windows 10. Was more cumbersome to configure on W10 than on WXP or W7.
I've faced the same problem. I installed Maven and added the \bin directory of maven to my path variables in System Variables, so I can only use MAVEN commands using admin rights (run cmd in windows as administrator)
I solved this by creating all under User variables (including the PATH variable).

how to run jar file on RHEL5?

I have made a jar file which i tested in windows and it works fine. now i want to test it for red hat enterprise linux 5. but i dont know how to run jar files in rhel5.
i've tried java -jar My.jar but it says bash: java: command not found. i've set JAVA_HOME variable as export JAVA_HOME=/root/jdk1.6.0_21 but still not working.
can anybody tell me how to run jar file in rhel5?
You need to set PATH variable , something like
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
replace /usr/java/jdk1.5.0_07/bin with path to your jdk's bin directory.
The problem is your terminal tries to find java command from the PATH , but it couldn't find it.
Update:
You need to setup global config in /etc/profile OR /etc/bash.bashrc file for all users:
# vi /etc/profile
Next setup PATH / JAVA_PATH variables as follows:
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
export PATH=$PATH:/usr/java/jdk1.5.0_07/bin
Top tip but slightly off topic.
1) Install your JDK in /usr/local/jdkX.X.X_XX/
2) Create a symbolic link /usr/local/java -> your chosen JDK installation
When you install new versions of java or if you want to revert to an older version, just change the symbolic link.

Categories

Resources