Cannot get Maven working on Windows 7 [duplicate] - java

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).

Related

how do i solve this Error injecting constructor, java.lang.NoClassDefFoundError: javax/crypto/SecretKey

i also tried the below mentioned steps:
check maven version by mvn -version in cmd
check prerequisites such as gmconstant.js, application.prop, jboss-deploymnet_structure.xml,pom file with others or follow the env setup document
check java version as 1.8.0_161 and ur maven version should be 3.6.2 or 3.6.3
if maven is not deploying try executing this command
Call mvn -Dbuild.version=Local -Doutput.dir="C:\jboss-eap-7.0\standalone\deployments" clean install
try getting the entire project folder from others and check in your environment
if setting your environmental variables, then give SET PATH=C in command prompt as administrator
deleting the files unders .m2 folder /repository
C:\Users\asophia.m2\repository
also added the below mention paths in environment variables
C:\Oracle\Middleware\jdk160_18\bin
C:\Program Files\Java\jre1.8.0_161
C:\Program Files\Java\jdk1.8.0_161
also set the path C:\Tools\apache-maven-3.6.2\bin in user variable
You have to add the encryption jar in C:\Program Files\Java\jdk1.8.0_161\jre\lib\ext or whatever jdk you are using and then register it as well.
Since you are using Oracle jdk, you probably need their jar (JCE).
https://www.oracle.com/java/technologies/java-archive-downloads-java-plat-downloads.html#JCE-1_2_2-G-JS
Quoting the documentation:
Installing Providers
In order to be used, a cryptographic provider must first be installed, then registered either statically or dynamically.
Static Registration
The configuration file is located in the following location:
Unix: /lib/security/java.security
Windows: \lib\security\java.security
You can check the documentation for a well detailed explanation:
https://docs.oracle.com/javase/7/docs/technotes/guides/security/crypto/CryptoSpec.html

VS Code Showing 'mvn' is not recognized as an internal or external command

I'm trying to create a maven project with VS Code but when I run the command it says :
'mvn' is not recognized as an internal or external command,operable program or batch file.
but mvn -version is running on command prompt
Environment varaible for User :
MAVEN_JOME : C:\apache-maven-3.6.1,
M2_HOME : C:\apache-maven-3.6.1,
JAVA_HOME : C:\Program Files\Java\jdk1.8.0_212\jre and
System Variables
path is set to C:\apache-maven-3.6.1\bin, C:\Program Files\Java\jdk1.8.0_212\bin for maven and java respectively.
The command I'm running to create the project is:
mvn archetype:generate -DgroupId=com.cs.test-project -DartifactId=test-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false The Reference to Command
And the VS Code Reference to Command
The same command is running in Command prompt and it created the project successfully on Desktop.
I fixed this problem by simply restarting VSCode as I had set my PATH variable while my VSCode was running so the changes were not reflected to the VSCode integrated terminal until I restarted it.
It's kindy counterintuitive as path has to be pointed to the actual mvn command, instead to a M2_PATH folder. Also once properly pointed, a new error will be shown if your environment is missing proper jdk within JAVA_HOME. The error is trown by maven. Maven plugin is kinda stupid as it will ignore your default JDK configured within settings.json (java.home or/and java.configuration.runtimes properties) and will happly NOT set java for maven. You have to configure it specificly for maven plugin as this:
"maven.executable.path": "c:\\apache-maven-3.8.1\\bin\\mvn",
"maven.terminal.customEnv": [{
"environmentVariable": "JAVA_HOME",
"value": "c:\\openjdk-1.8.0_232-redhat",
}]
Of course, both paths should be pointed to proper folders/files in your environment.
The way I fixed was by changing the exec path in Vs Code settings from CMD to Powershell.
Open
settings -> features -> terminal
Change the windows exec path from cmd to where you have PowerShell.
For example: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Windows exec setting
On Tuesday Oct. 25, 2022 while trying to solve the same problem, I went through all of these previous solutions for Windows and finally had to resort to the official installation docs:
Installing Apache Maven
Unzipped the download and located the bin directory and manually added that directory location to my: System Properties>Advanced>Environment Variables>'Path'
For good measure, restart the computer.

Gradle not found java class path [duplicate]

I am using javadoc doclets with gradle, so I need to use the package tools.jar, which is in the lib folder from the jdk (1.6.0_26 in my case).
The point is that gradle does not take it automatically, so I was adding that tools package to my libs folder, and then adding it to dependencies.gradle .
Now I want to take it directly from my JDK home into my dependencies.gradle. Is there a way to do that? I have tried the next in my dependencies.gradle:
compile files("${System.properties['java.home']}/lib/tools.jar")
But it does not find it while compiling.
I had this problem when I was trying to run commands through CLI.
It was a problem with system looking at the JRE folder i.e.
D:\Program Files\Java\jre8\bin. If we look in there, there is no Tools.jar, hence the error.
You need to find where the JDK is, in my case: D:\Program Files\Java\jdk1.8.0_11, and if you look in the lib directory, you will see Tools.jar.
What I did I created a new environment variable JAVA_HOME:
And then you need to edit your PATH variable to include JAVA_HOME, i.e. %JAVA_HOME%/bin;
Re-open command prompt and should run.
Found it. System property 'java.home' is not JAVA_HOME environment variable. JAVA_HOME points to the JDK, while java.home points to the JRE. See that page for more info.
Soo... My problem was that my startpoint was the jre folder (C:\jdk1.6.0_26\jre) and not the jdk folder (C:\jdk1.6.0_26) as I thought(tools.jar is on the C:\jdk1.6.0_26\lib folder ). The compile line in dependencies.gradle should be:
compile files("${System.properties['java.home']}/../lib/tools.jar")
I got the same error using Eclipse trying to execute a Gradle Task. Every time I run a command (i.e. war) the process threw an exception like:
Could not find tools.jar. Please check that C:\Program Files\Java\Jre8" is a valid JDK install.
I tried the solution listed in this post but none of them solved this issue. Here my solution :
Go to the "Gradle Task" view
Right Click on the task you want to execute
Select Open Gradle Run Configuration
In the tab "Java Home" select your local JDK repository then click OK
Run again, Enjoy!
I just added a gradle.properties file with the following content:
org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_45
I had a similar case using Ubuntu. The machine had only the JRE installed. So, I just executed the command below to install the JDK.
sudo apt install openjdk-8-jdk
In macOS Big Sur
The issue happens because of the environment variable JAVA_HOME is not correctly set in macOS Big Sur.
Step 1 - Confirm that you have issue with JAVA_HOME by printing its value in the terminal. You will most likely get an empty string.
echo $JAVA_HOME
Step 2 - Find the correct path on your machine
/usr/libexec/java_home -V
Copy that path associated with "Java SE 8" which usually looks like /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
Step 3 - Edit .zshenv using nano
nano ~/.zshenv
Step 4 - Add the path from step 2 to the file as follows
export JAVA_HOME=YOUR_JAVA_PATH
example:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home
Step 5 - Source the updated .zshenv file to activate the environment variable
source ~/.zshenv
Step 6 - Print to confirm the path
echo $JAVA_HOME
I was struggling as well for this Solution. Found a better way to it with Gradle as described here.
We can get the JVM/JDK information from Gradle itself.
dependencies {
runtime files(org.gradle.internal.jvm.Jvm.current().toolsJar)
}
So simple.
In CentOS7 the development package will install tools.jar. The file is not present in java-1.8.0-openjdk
sudo yum install java-1.8.0-openjdk-devel
Add this to gradle.properties:
org.gradle.java.home=C:\Program Files\Java\jdk1.8.0_91
My solution on Mac:
add this line to gradle.properties:
org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk1.8.0_271.jdk/Contents/Home
not this one:
org.gradle.java.home=/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
you can open the last home directory and will find that there is no lib/tools.jar file existence, so change the path to JavaVirtualMachines/jdk1.8.0_271.jdk and it works for me.
By the way, in the terminal, I echo the $JAVA_HOME and it gets the first path, not the second one, I think this is why my Gradle cannot work properly.
With Centos 7, I have found that only JDK has tools.jar, while JRE has not. I have installed the Java 8 JRE(yum install java-1.8.0-openjdk), but not the JDK(yum install java-1.8.0-openjdk-devel).
Installing the latter solves the problem. Also, remember to set JAVA_HOME.
It may be two years too late, but I ran into the same problem recently and this is the solution I ended up with after finding this post:
import javax.tools.ToolProvider
dependencies {
compile (
files(((URLClassLoader) ToolProvider.getSystemToolClassLoader()).getURLs()),
...
}
}
It should work if java.home points to a directory that's not under the JDK directory and even on Mac OS where you'd have classes.jar instead of tools.jar.
On windows 10, I encounter the same problem and this how I fixed the issue;
Access Advance System Settings>Environment Variables>System
Variables
Select PATH overwrite the default
C:\ProgramData\Oracle\Java\javapath
With your own jdk installation that is JAVA_HOME=C:\Program Files\Java\jdk1.8.0_162
On my system (Win 10, JRE 1.8.0, Android Studio 3.1.2, Gradle 4.1) there is no tools.jar in the JRE directory (C:\Program Files\Java\jre1.8.0_171).
However, I found it in C:\Program Files\Android\Android Studio\jre\lib and tried setting JAVA_HOME=C:\Program Files\Android\Android Studio\jre
That works (for me)!
What solved it for me was the following:
found tools.jar in C:\Program Files\Android\Android Studio\jre\lib
copy paste to C:\Program Files (x86)\Java\jre1.8.0_271\lib
ran the code again and it worked.
If you use terminal to build and you have this error you can point to jdk bundled with android studio in your gradle.properties file:
org.gradle.java.home=/usr/local/android-studio/jre
Linux
Open /etc/environment in any text editor like nano or gedit and add the following line:
JAVA_HOME="/usr/lib/jvm/open-jdk"
Windows
Start the System Control Panel applet (Start - Settings - Control
Panel - System).
Select the Advanced tab.
Click the Environment
Variables button.
Under System Variables, click add button, then past the following lines:
in Variable Name : JAVA_HOME
in Variable Value : C:\Program Files\Java\jdk1.x.x_xxx
where x.x_xxx jdk version you can get your jdk version from here C:\Program Files\Java
Under System Variables, select Path, then click Edit,then click new button then past the following line:
%JAVA_HOME%/bin;
This worked for me:
I was getting message
Execution failed for task ':app:compileDebugJavaWithJavac'.
Could not find tools.jar. Please check that C:\Program Files\Java\jre1.8.0_121 contains a valid JDK installation.
In Android Studio, check your SDK Location.
File, Project Structure, SDK Location, JDK Location.
Example: C:\android-studio\android-studio\jre
Copy the tools.jar file in the C:\android-studio\android-studio\jre\lib folder into the C:\Program Files\Java\jre1.8.0_121\lib folder.
Retry.
Like other answers I set org.gradle.java.home property in gradle.properties file. But path with \ separators did not work (building on windows 10):
Java home supplied via 'org.gradle.java.home' is invalid. Invalid
directory: C:Program FilesJavajdk1.8.0_65
So instead of
org.gradle.java.home=C:\Program Files\Java\jdk1.8.0_65
i had to use
org.gradle.java.home=C:/Program Files/Java/jdk1.8.0_65
then the build was successful
Problem is that project is build with JRE instead of JDK and since I was building it from eclipse this also worked:
In Window>Preferences>Gradle>Arguments specify Workspace JRE and specify your JDK.
In Window>Preferences>Java>InstalledJREs specify your JDK as default
In my case (Windows 10) after Java update I lost my Enviroment Variables, so I fixed added the variables again, based in the following steps https://confluence.atlassian.com/doc/setting-the-java_home-variable-in-windows-8895.html
I solved problem on this way:
download file tools-1.8.0.jar on http://www.java2s.com/Code/Jar/t/Downloadtools180jar.htm
unzip file and rename to tools.jar
copy to C:\Program Files\Java\jre1.8.0_191\lib folder
Retry
Put in gradle.properties file the following code line:
org.gradle.java.home=C:\\Program Files\\Java\\jdk1.8.0_45
Example image
Use this with modern versions of gradle:
def compiler = javaToolchains.compilerFor { languageVersion = JavaLanguageVersion.of(java.sourceCompatibility.majorVersion) }.get()
implementation compiler.metadata.installationPath.files('lib/tools.jar')
Did you make sure that tools.jar made it on the compile class path? Maybe the path is incorrect.
task debug << {
configurations.compile.each { println it }
}
Adding JDK path through JAVA_HOME tab in "Open Gradle Run Configuration" will solve the problem.
Could not find tools.jar
MacOS
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile
And restart Shell
I've tried most of the top options but it seems that I had something wrong with my environment setup so they didn't help. What solved the issue for me was to re-install jdk1.8.0_201 and jre1.8.0_201 and this solved the error for me. Hope that helps someone.
For me this error ocurred after trying to use audioplayers flutter library.
To solve i got tools.jar of the folder:
C:\Program Files\Android\Android Studio\jre\lib
and pasted on
C:\Program Files\Java\jre1.8.0_181\lib.
After this the build worked fine.
My Android Studio Version: 4.2.1
The "tools.jar" is provided by Oracle JDK which is required by android studio for compilation - I have faced this issue after updating android studio to latest version in my PC.
To Resolve the issue follow below steps:
In Android studio File -> Project Structure -> SDKs (Under Platform Settings)
A) Add JDK path by pressing '+' symbol in middle pane if suppose JDK/JDK home path is not present in the middle pane already (Middle pane also contains the Downloaded Android SDK's)
B) Java sdk will be usually present/installed in the path 64 bit => "C:\Program Files\Java\jdk1.X.Y_ABC" (In my PC it is 1.8.0_202) or 32 bit => "C:\Program Files (x86)\Java\jdk1.X.Y_ABC"
If suppose you don't have JDK installed in your PC,
please download and install from Oracle Java website
https://www.oracle.com/java/technologies/javase/javase-jdk8-downloads.html
Set JDK and JRE Path(Download both from webpage mentioned in step 2) in system environment variable
A) Press windows key type "Edit the system environment variables" and open the application
B) Go to Advanced -> Environment Variables Under system variables add JAVA_HOME and JRE_HOME as below
Set Windows system environment variable
Add jdk lib path on the Path environment variable under user variables (this step is required only if the error not resolves with the previous steps)
C:\Program Files\Java\jdk1.X.Y_ABC\lib
For Windows add JDK home path to the Gradle property file as org.gradle.java.home.
If you don't have gradle.properties file then create a new one and add
Ex: org.gradle.java.home=C:\Program Files\Java\jdk1.8.0_241

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!!!

How to install Apache Ant?

I want to install SMSlib (http://smslib.org/) in installation instruction (http://code.google.com/p/smslib/wiki/Installation).
In here I must install Apache Ant, but I didn't understand how to do that.
I already download Apache Ant 1.7.1 , read manual (http://ant.apache.org/manual/index.html)
In here I must have RPM version from jpackage.org right? I already go to http://www.jpackage.org/ after that what must I do? I already try (http://mirrors.dotsrc.org/jpackage/1.7/generic/free/repodata/) and (http://www.jpackage.org/browser/browse.php?jppversion=1.7) but too many link. I don't know witch one must I download
If you're on Windows, you can use WinAnt, a Windows installer for Apache Ant that I made.
Step 1: Download and install
Download Ant. Go to the Ant homepage and click to download the binary. Because we’re talking about Windows, choose to download the ZIP file rather than any of the others. Scroll down to where it says “Current release of Ant” and click on the ZIP filename.
Once downloaded, unzip the file. You’ll now need to choose a permanent home for Ant on the computer. c:\java\ant is often used, but you can put it wherever you want.
Step 2: Set environment variables
For Windows XP: To set environment variables on Windows XP, right click on My Computer and select Properties. Then go to the Advanced tab and click the Environment Variables button at the bottom.
For Windows 7: To set environment variables on Windows 7, right click on Computer and select Properties. Click on Advanced System Settings and click the Environment Variables button at the bottom.
The only environment variable that you absolutely need is JAVA_HOME, which tells Ant the location of your JRE.
If you’ve installed the JDK, this is likely
c:\Program Files\Java\jdk1.x.x\jre
on Windows XP and
c:\Program Files(x86)\Java\jdk1.x.x\jre
on Windows 7. You’ll note that both have spaces in their paths, which causes a problem. You need to use the mangled name[3] instead of the complete name. So for Windows XP, use C:\Progra~1\Java\jdk1.x.x\jre and for Windows 7, use C:\Progra~2\Java\jdk1.6.0_26\jre if it’s installed in the Program Files(x86) folder
That alone is enough to get Ant to work, but for convenience, it’s a good idea to add the Ant binary path to the PATH variable.
This variable is a semicolon-delimited list of directories to search for executables. To be able to run ant in any directory, Windows needs to know both the location for the ant binary and for the java binary. You’ll need to add both of these to the end of the PATH variable. For Windows XP, you’ll likely add something like this:
;c:\java\ant\bin;C:\Progra~1\Java\jdk1.x.x\jre\bin
For Windows 7, it will look something like this:
;c:\java\ant\bin;C:\Progra~2\Java\jdk1.x.x\jre\bin
Done
Once you’ve done that and applied the changes, you’ll need to open a new command prompt to see if the variables are set properly. You should be able to simply run ant and see something like this:
Buildfile: build.xml does not exist!
Build failed
That means Ant is installed properly and is looking for a build.xml file.
Source: http://www.nczonline.net/blog/2012/04/12/how-to-install-apache-ant-on-windows/
You can follow these instrunctions-
1)Download the latest version of ant from http://ant.apache.org/bindownload.cgi
2)Unzip and save it to your C:\ directory as ant.
3)Add the bin directory to your PATH environment variable.
4)Add the ANT_HOME environment variable set to C:\ant.
you can use following commands to set ANT_HOME variable
C:>set ANT_HOME=C:\ant
C:>set JAVA_HOME=C:\jdk
C:>set PATH=%ANT_HOME%\bin;%JAVA_HOME%\bin
C:>ant -version
Apache Ant version 1.8.1 compiled on April 30 2010
if you have java installed on your machine
5)Add the ANT_OPTS environment variable set to -Xmx256M.
This is all you need to install ant on your machine.
1) Download "apache-ant-1.8.4-bin.zip" from "http://ant.apache.org/bindownload.cgi"
2) Unzip it and copy "apache-ant-1.8.4" in "c:\Program Files"
3) Right Click "My Computer" -> properties -> Advanced -> Environment variables -> Edit variable "PATH" and append value "C:\Program Files\Java\jdk 1.7.0_04\bin;C:\Program Files\apache-ant-1.8.4\bin" and Click "OK".
4) open cmd and type "ant" for checking.
the installation of ant and smslib is pretty simple. All you need to do is extract it to some directory. Export the path in case of Linux or set the ANT_HOME\bin to the PATH variable to access it from any directory in the shell. ANT_HOME is the root directory where ant is installed.
For SMSLib Download the zip file and this link should guide you on a step by step basis
Sound's like you're using Linux. If so, the easiest way would be to use a package management frontend like Synaptic and install ant in there.
Its very simple just install Apache ant installer for windows give on [link][1]
[1]: http://code.google.com/p/winant/ and all is set.No need to set Environment variables.It will automatically do every thing for you.
You can install Apache Ant with only single command on Ubuntu:
sudo apt install ant
Check the version of ant installed with:
ant -version

Categories

Resources