Search code examples
javawindowseclipsemavenmaven-3

Maven 3.0.4 error on Windows 8 x64: Usage: java [-options] class [args...]


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.


Solution

  • 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: