How do I set an active Spring boot profile on the command line using "spring-boot:run"? - spring-boot

I'm using Maven 3.8 and Spring Boot 1.5. I'm using Windows PowerShell, for whatever that's worth. How do I start my Spring Boot project and set an active profile on the command line? I tried
> mvn -Dspring-boot.run.profiles=dev spring-boot:run
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.247 s
[INFO] Finished at: 2022-07-25T16:06:50-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase ".run.profiles=dev". 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]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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/LifecyclePhaseNotFoundException
but the "-Dspring-boot.run.profiles=dev" switch doesn't seem to be right.

In Windows PowerShell, try using
mvn spring-boot:run --define spring-boot.run.arguments="--spring.profiles.active=dev"

-Dspring-boot.run.profiles=dev is for Spring Boot 2.x
You should use -Dspring.profiles.active=dev for Spring Boot 1.x
Docs: Spring Boot 1.5 Reference

Related

Error when running docker and maven from shell script

I can run the following line from the command line with correct results:
docker run --rm -v $PWD/java-app:/app -v /root/.m2/:/root/.m2/ -w /app maven:3-alpine mvn -B -DskipTests clean package
Based on the previous command, I created the following script:
echo "******************"
echo "***Building jar***"
echo "******************"
docker run --rm -v $PWD/java-app:/app -v /root/.m2/:/root/.m2/ -w /app maven:3-alpine "$#"
To run that script, I use the following line:
./jenkins/build/mvn.sh mvn -B -DskipTests package
And I obtain the following output:
******************
***Building jar***
******************
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.071 s
[INFO] Finished at: 2021-04-21T19:03:56Z
[INFO] Final Memory: 13M/381M
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "package
[ERROR] ". 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]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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/LifecyclePhaseNotFoundException
Any clues?
The reason was I was creating the script with a Windows editor. That introduced a bad character in the file.

The console gives me " No goals have been specified for this build"

I'm trying to run my first spring boot application however the console gives me an error saying that "No goals have been specified for this build"
below is the console error, also I'm not sure if the tomcat server will run or not.
The last thing, why the console didn't return "Spring" logo
C:\Users\mmaksoud\.jdks\openjdk-14.0.1\bin\java.exe -Dmaven.multiModuleProjectDirectory=C:\Users\mmaksoud\Desktop\demo "-Dmaven.home=D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1\plugins\maven\lib\maven3" "-Dclassworlds.conf=D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1\plugins\maven\lib\maven3\bin\m2.conf" "-Dmaven.ext.class.path=D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1\plugins\maven\lib\maven-event-listener.jar" "-javaagent:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1\lib\idea_rt.jar=53196:D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1\bin" -Dfile.encoding=UTF-8 -classpath "D:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.6.0.jar" org.codehaus.classworlds.Launcher -Didea.version2020.1
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.135 s
[INFO] Finished at: 2020-04-17T16:44:51+02:00
[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]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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

Maven installing plugin

[INFO] `Scanning for projects`...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] `Building MVNDEMO 0.0.1-SNAPSHOT`
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] `BUILD FAILURE`
[INFO] ------------------------------------------------------------------------
[INFO] `Total time: 0.099 s
[INFO] Finished at: 2019-04-25T12:29:22+05:30
[INFO] Final Memory: 5M/123M`
[INFO] ------------------------------------------------------------------------
[ERROR] Unknown lifecycle phase "testcases". 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]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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]
You called something like mvn testcases, which is not a valid Maven phase.
If you want to build, use mvn clean install.

Maven configuration for Multi Module Project

I am creating a multi-module project with Spring Boot, the project will have 3 modules: moduleA, moduleB and moduleC.
I am following this tutorial https://spring.io/guides/gs/multi-module/#scratch
in the root directory I've created the 3 directories: moduleA, moduleB and moduleC
I've run mvn -N io.takari:maven:wrapper
after I've run sudo ./mvnw and here the result:
MacBook-Pro-de-calzada:multi-module-project-example nunito$ sudo ./mvnw
/Users/nunito/Development/J2EE/workspace-sts-3.8.4.RELEASE/multi-module-project-example
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.066 s
[INFO] Finished at: 2017-04-24T20:03:37+02:00
[INFO] Final Memory: 7M/245M
[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]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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
MacBook-Pro-de-calzada:multi-module-project-example nunito$
and executing ./mvnw clean install
/Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/multi-module-project-example
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.062 s
[INFO] Finished at: 2017-04-24T22:38:20+02:00
[INFO] Final Memory: 8M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/multi-module-project-example). Please verify you invoked Maven from the correct directory. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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/MissingProjectException
MacBook-Pro-de-calzada:multi-module-project-example nunito$
You need to have a pom.xml file in order to run ./mvnw clean install.
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/multi-module-project-example).
Have a look at Maven Configuration for Multi Module Project and Maven Configuration for Library in the tutorial. There you will find the necessary pom.xml files.
There are two things :
For running any maven project , the very basic and first requirement is you must have a pom.xml . Absence of this file will throw you the error :
[ERROR] The goal you specified requires a project to execute but there
is no POM in this directory
(/Users/calzada/Development/J2EE/workspace-sts-3.8.4.RELEASE/multi-module-project-example).
Please verify you invoked Maven from the correct directory. -> [Help
1]
In the tutorial https://spring.io/guides/gs/multi-module/#scratch it is mentioned that you should have the pom.xml file , please refer this section ▶Maven Configuration for Multi Module Project

Maven gives a error when trying to execute the "mvn build" command

When I run my maven project through "run as "==> "Maven build" in my eclipse IDE,the error what is shown in the under img happened.
![enter image description here][1]
My JDK version is:1.7.0_76
Maven version is:3.3.1
echo %JAVA_hOME%=D:\work\Java\jdk1.7.0_76
echo %M2_HOME%=D:\work\apache-maven-3.3.3
In my eclipse IDE My maven setting like the under img:![enter image description here][2]![enter image description here][3]
My project's build path is ![enter image description here][4]
This is because this project is an old project compiled with JDK1.6,so,I choose the installed jdk1.6. But when run as maven build,the error like picture 1 happened!
Help me ,pls!
The error is 【[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.084 s
[INFO] Finished at: 2015-07-11T01:15:18+08:00
[INFO] Final Memory: 5M/154M
[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]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[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
】
If you select Run As → Maven build an Eclipse Run Configuration is used (see menu Run → Run Configurations...). In case of a Maven Build at least one appropriate goal (e.g. one of Maven's built-in lifecycles) has to be specified in its Goals: field.

Resources