0

Looks like this has been a repeating challenge to set up maven, but I'm also having my own challenges on this...! I'm a newbie to maven and java, would appreciate any help here!

Here's my current set up on MacOS v10.15.7

As maven suggested I first define my JAVA_HOME (not set by default in OSX)

cd ~
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile
echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/openjdk-12.0.2.jdk/Contents/Home

echo $PATH
/Users/byc/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin

Then I went on downloading Maven 3.6.3 and created the folder at /Users/byc/Downloads/apache-maven-3.6.3, ran the following

export PATH=/Users/byc/Downloads/apache-maven-3.6.3/bin:$PATH
mvn --verison
-bash: mvn: command not found

When I ran mvn -e I got the following. Does it mean Maven isn't binding to $PATH properly?

mvn -e
[INFO] Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.059 s
[INFO] Finished at: 2020-12-01T19:03:43Z
[INFO] ------------------------------------------------------------------------
[ERROR] No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]
org.apache.maven.lifecycle.NoGoalSpecifiedException: No goals have been specified for this build. You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy.
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:97)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:567)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoGoalSpecifiedException
byc
  • 121
  • 10
  • 1
    No, it means that you didn't tell Maven to _do_ anything, like `mvn compile`. – chrylis -cautiouslyoptimistic- Dec 01 '20 at 20:21
  • 1
    Maven has a specific set of goals that you specify one or more with each execution. The goals available can be influenced by "plugins" that execute are associated with specific steps in the lifecycle. The simplest goal is "clean"; `mvn clean` removes specific types artifacts from your workspace that could be download or generated later in the build process. – Dr Dave Dec 01 '20 at 21:23

1 Answers1

1

Several things:

  1. I'm not sure why Maven documentation continues to tell people to set JAVA_HOME. This is unnecessary, provided that javac (yes, javac, not sure why) is in your path (which usually means java as well is in your path). The source code confirms it.
  2. You misspelled version as verison which is why you received -bash: mvn: command not found.
  3. You specified neither a Maven lifecycle phase nor a plugin goal so Maven didn't know what to do.
Laird Nelson
  • 15,321
  • 19
  • 73
  • 127
  • 1
    (Finally note that `/usr/libexec/java_home` is the best way on macOS to find out where the root of a particular JDK installation is.) – Laird Nelson Dec 01 '20 at 21:30
  • alas to typos! it is up and running now `mvn -version. Apache Maven 3.6.3 Maven home: /Users/byc/Downloads/apache-maven-3.6.3 Java version: 12.0.2, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/openjdk-12.0.2.jdk/Contents/Home Default locale: en_GB, platform encoding: UTF-8 OS name: "mac os x", version: "10.15.7", arch: "x86_64", family: "mac"` – byc Dec 01 '20 at 21:56
  • interesting re your point on `javac`...what does it use for? I do have several JDK going on due to past installation. `/usr/libexec/java_home` has pointed me to the current one :) – byc Dec 01 '20 at 22:00
  • @byc I am guessing without any information that the test for `javac` instead of `java` is to see if Maven has access to a JDK versus a JRE. I further speculate that this is for historical, no longer relevant reasons: perhaps the `maven-compiler-plugin` was more tightly integrated into Maven core than it is now, and perhaps at some point in the distant past it needed to shell out to `javac`. Or, you know, typos. – Laird Nelson Dec 02 '20 at 04:06
  • it seems very unlikely but do I need to run `export PATH=/Users/byc/Downloads/apache-maven-3.6.3/bin:$PATH` every time I want to use maven? mvn -v was working happily yesterday, but today I'm seeing the old friend again `mac:bin byc$ mvn -version -bash: mvn: command not found` :( – byc Dec 02 '20 at 17:11
  • and this... `mac:bin byc$ mvn -B archetype:generate -DgroupId=fr.myGroupId -DartifactId=MyApplication -Dpackagename=fr.myGroupId -DarchetypeArtifactId=maven-archetype-quickstart -bash: mvn: command not found` – byc Dec 02 '20 at 17:13
  • Are you asking a question about how `PATH` works in Unix-derived systems? If so, yes, your `PATH` must contain `mvn` in order for the operating system to find `mvn`, and interactive `PATH` edits in one session do not persist to another session. There are many ways to make them persist that are outside the scope of this question. Look for basic introductory Linux/Unix/Mac tutorials to help with this. – Laird Nelson Dec 02 '20 at 17:18