Maven 3.0.4 error on Windows 8 x64: Usage: java [-

2019-07-02 14:23发布

问题:

This is my first post on this forum. I have a problem with Maven 3. OS: Windows 8 Professional RTM.

If I run any maven command (whatever) I always get the following answer:

Usage: java [-options] class [args...] (to execute a class) or java [-options] -jar jarfile [args...] (to execute a jar file)

where options include: -server to select the "server" VM -hotspot is a synonym for the "server" VM [deprecated] The default VM is server.

-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
              A ; separated list of directories, JAR archives,
              and ZIP archives to search for class files.
-D<name>=<value>
              set a system property
-verbose[:class|gc|jni]
              enable verbose output
-version      print product version and exit
-version:<value>
              require the specified version to run
-showversion  print product version and continue
-jre-restrict-search | -jre-no-restrict-search
              include/exclude user private JREs in the version search
-? -help      print this help message
-X            print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
              enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
              disable assertions
-esa | -enablesystemassertions
              enable system assertions
-dsa | -disablesystemassertions
              disable system assertions
-agentlib:<libname>[=<options>]
              load native agent library <libname>, e.g. -agentlib:hprof
                see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
              load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
              load Java programming language agent, see java.lang.instrument

-splash:<imagepath>
              show splash screen with specified image

I used Google and forum search but the only results were a different problem: it was a problem on environment variables (most of them ending the path with an additional slash).

If I execute java -version I get:

java version "1.6.0_35" Java(TM) SE Runtime Environment (build 1.6.0_35-b10) Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)

If I execute javac -version I get:

javac 1.6.0_35

The Maven verssion I am using is 3.0.4. These are the environment variables I added (I added M2_HOME and MAVEN_HOME because I am not sure about which one is the right variable):

CATALINA_OPTS=%MAVEN_OPTS%
CLASSPATH=%JAVA_HOME%\src.zip;%JAVA_HOME%\lib\tools.jar;
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_35
M2_HOME=d:\software\apache-maven-3.0.4
MAVEN_HOME=d:\software\apache-maven-3.0.4
MAVEN_OPTS=-Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m
PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin;d:\software\eclipse;%M2_HOME%\bin

The path environment variable has more paths but I just pasted here the paths I added for my final year project.

Thanks in advance for your help.

回答1:

The only environment variables you need to set are:

JAVA_HOME=C:\Program Files\Java\jdk1.6.0_35
MAVEN_HOME=D:\software\apache-maven-3.0.4
PATH=%PATH%;%MAVEN_HOME%\bin;%JAVA_HOME%\bin

Note, use D: instead of d:



回答2:

I use apache-maven-3.3.1 and see the same problem with Alberto I tested and found that the error may happen when you run command on directory like: "C:\" "D:\" "E:\"... Should go to at lease 1 folder like: "D:\TestApp"



回答3:

Try to change JAVA_HOME="C:\Program Files\Java\jdk1.6.0_35"



回答4:

I created a folder P:\projects.

I ran mvn inside that folder. mvn ran as expected.

I changed directory to P:\ to run mvn. mvn blurted out the error with the java usage advisory as depicted in this question.

I found, by tearing the mvn.bat apart, that Maven cannot accept the JVM property

"-Dmaven.multiModuleProjectDirectory=P:\"

when it's value is the root folder of a device.

I have not tried in Linux yet.

BTW, I also found that mvn has an error message that has a bad spelling. The error message is "multiModuleProjectDirectory propery not defined". At first I had dyslexically read, "multiModuleProjectDirectory not properly defined."



回答5:

>I found that Maven cannot accept the JVM >property 
>
>
>"-Dmaven.multiModuleProjectDirectory=P:\"
>
>when it's value is the root folder of a device.

Any directory other than c:\ as the current directory and now...

mvn -v works.