how to change Maven default project output directory? - java

Hello everyone:
I need help , I'm new to maven. when I try to run my first maven command
in Windows 7 like:
mvn archetype:generate \
-DgroupId=com.helloworld.test \
-DpackageName=com.helloworld.test \
-Dpackage=com.helloworld.test \
-DartifactId=hello
and it succeed, and here is an output:
[INFO] project created from Archetype in dir: C:\Windows\system32\helloworld
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
my question is: how to change the default output directory ? like:
d:\maven\project\helloworld
thank you very much.

Either execute command from target directory or pass -Dbasedir=/path/to/dir

Related

Maven Sonarqube plugin: Unable to execute SonarQube: Fail to get bootstrap index from server

I'm having an headache setting up the sonarqube maven plugin for a project.
So I have a sonarqube instance let's say on https://sonarqube.mycompany.software. I test many projects on this instance, it's working well since months.
I also have other projects that use the maven plugin (but use another docker image to run)
I start a new project, and of course I want to add to my automatic pipeline that checks the code with sonarqube.
Everything runs perfectly when I execute the maven plugin on my machine, with the OpenJdk-8:
$ mvn org.jacoco:jacoco-maven-plugin:0.8.5:prepare-agent clean test package
$ mvn sonar:sonar -Dsonar.projectKey=projectname -Dsonar.host.url=https://sonarqube.mycompany.software -Dsonar.login=youwishyouknew
[... Lots of output ...]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.891 s
[INFO] Finished at: 2020-05-07T18:03:00+02:00
[INFO] ------------------------------------------------------------------------
Then I try to execute the exact same command with docker on the server (where the pipeline will run), using the maven:3.6.3-jdk-8 image, I get this error:
$ docker run -v `pwd`/m2cache:/root/.m2 -v `pwd`/sonarcache:/root/.sonar/cache -v`pwd`:`pwd` -w`pwd` maven:3.6.3-jdk-8 mvn sonar:sonar -Dsonar.projectKey=projectname -Dsonar.host.url=https://sonarqube.mycompany.software -Dsonar.login=youwishyouknew
[INFO]
[INFO] ---------------------------< software.mycompany:projectname >----------------------------
[INFO] Building projectname 2.3.0
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- sonar-maven-plugin:3.7.0.1746:sonar (default-cli) # projectname ---
[INFO] User cache: /root/.sonar/cache
[ERROR] SonarQube server [https://sonarqube.mycompany.software] can not be reached
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.286 s
[INFO] Finished at: 2020-05-07T16:06:22Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.7.0.1746:sonar (default-cli) on project projectname: Unable to execute SonarQube: Fail to get bootstrap index from server: Broken pipe (Write failed) -> [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/MojoExecutionException
When I Execute this, absolutely nothing is happening in the Sonarqube logs (nothing moves at all in any log, while when I run it on my machine I find everything I expect to find.)
Furthermore, if I try to curl the sonarqube server from the docker image, it works! Tried with ping too.
$ docker run -v `pwd`/m2cache:/root/.m2 -v `pwd`/sonarcache:/root/.sonar/cache -v`pwd`:`pwd` -w`pwd` maven:3.6.3-jdk-8 curl https://sonarqube.mycompany.software
<!doctype html><html lang="en"><head><meta http-equiv="content-type" content="text/html; charset=UTF-8" charset="UTF-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"><link rel="apple-touch-icon" href="/apple-touch-icon.png"><link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png"><link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png">
[... And a lot more output ... ]
It responds with the sonarqube index page as I expect.
As far as I can see, there is no proxy setting in the docker maven image.
This is quite frustrating.
Has anybody any clue on what is going on here and how to fix this?
[EDIT] So I've tried many things, and one worked: using another docker image. In particular, I've tried all the available maven jdk-8 images available here: https://hub.docker.com/_/maven, and one actually worked, while all other failed: maven:3.6.3-ibmjava-8.
It looks like a java-8 related problem, since all JDK 11 images instead do work as expected. Unfortunately the project is in Java 8 and everything breaks when upgrading the JVM :-)
I leave this here as a work-around, but still, I would like to know why it fails with other docker images and how to fix this in the future.
I had this issue too with maven and gradle sonarqube analysis, i have only this issue with jdk8-u252+.
Maven 3.6.3 official image have jdk8-u262.
For me, with maven 3.5.2 it's ok (jdk-u232).
For the root cause, it could be the javax.net.ssl new features shipped in u252 : https://www.oracle.com/java/technologies/javase/8u251-relnotes.html

IDEA maven goal returns 'Process finished with exit code 1'

in Eclipse I do this :
and it works :
but in IDEA :
all I get is this :
I don't understand why it's not launching correctly.
I've done the same in Eclipse and IDEA :
Created project with
mvn archetype:generate -DarchetypeGroupId=org.ninjaframework -DarchetypeArtifactId=ninja-servlet-jpa-blog-archetype
cd MY_INSTALLED_PROJECT
mvn clean install
mvn ninja:run
And finally, imported project as a Maven project
And now I'm clueless. Anyone know what I'm doing wrong?
Update : 2018-01-30, still haven't found the solution!
I don't have an answer, but did narrow down the problem. Seems the combination of using Maven 3.5.x (I tested with 3.5.0 and 3.5.2) with JIdea. Here's the command line generated by JIdea to perform "clean" lifecycle:
C:\Dev\GitHub\cas-server>C:\Dev\JavaTools\jdk1.8.0_131\bin\java -Dmaven.home=C:\Dev\JavaTools\apache-maven-3.5.2 -Dclassworlds.conf=C:\Dev\JavaTools\apache-maven-3.2.1\bin\m2.
conf -Didea.launcher.port=7535 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.1.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Dev\JavaTools\apache-maven-3.2.1\boot\plexus-classworlds-2.5.1.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.1.5\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=13.1.5 -X clean
Here I changed just the maven.home to point to Maven 3.2.1 folder, but left all other maven path references pointing at Maven 3.5.2. That works:
C:\Dev\GitHub\cas-server>C:\Dev\JavaTools\jdk1.8.0_131\bin\java -Dmaven.home=C:\Dev\JavaTools\apache-maven-3.2.1 -Dclassworlds.conf=C:\Dev\JavaTools\apache-maven-3.5.2\bin\m2.conf -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.1.5\bin" -Dfile.encoding=UTF-8 -classpath "C:\Dev\JavaTools\apache-maven-3.5.2\boot\plexus-classworlds-2.5.2.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 13.1.5\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=13.1.5 clean
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building cas-overlay 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # cas-overlay ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.390 s
[INFO] Finished at: 2018-02-26T15:12:06-05:00
[INFO] Final Memory: 6M/123M
[INFO] ------------------------------------------------------------------------
Add flag
-X
It's verbose mode.
And check maven settings (settings.xml) in Intellij IDEA.
Preferences / Maven / User Settings file

Running Maven project in Netbeans

Is there any way I can run Maven project in Netbeans not in a Maven way? Netbeans do it automatically but I just want to run program normally, as a typical Java project (to save time). I want output to look like this:
run:
Hello world!
BUILD SUCCESSFUL (total time: 0 seconds)
instead of this:
cd C:\Users\mbrnw_000\Documents\NetBeansProjects\mavenproject1; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.7.0_15" "\"C:\\Program Files\\NetBeans 7.3\\java\\maven\\bin\\mvn.bat\"" "-Dexec.args=-classpath %classpath pl.mbrnwsk.mavenproject1.App" "-Dexec.executable=C:\\Program Files\\Java\\jdk1.7.0_15\\bin\\java.exe" process-classes org.codehaus.mojo:exec-maven-plugin:1.2.1:exec
Scanning for projects...
------------------------------------------------------------------------
Building mavenproject1 1.0-SNAPSHOT
------------------------------------------------------------------------
[resources:resources]
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory C:\Users\mbrnw_000\Documents\NetBeansProjects\mavenproject1\src\main\resources
[compiler:compile]
Nothing to compile - all classes are up to date
[exec:exec]
Hello world!
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 1.143s
Finished at: Fri May 03 16:27:09 CEST 2013
Final Memory: 6M/107M
------------------------------------------------------------------------
by turning on Compile on Save in project properties. However please note that in 7.4 (upcoming version) all execution will already be done by Maven exclusively.

Craftbukkit: mvn clean install error

I am fairly new to UNIX and i am trying to use CraftBukkit to run my Minecraft Server.
This is what I did:
$ git clone git://github.com/Bukkit/CraftBukkit.git
$ cd CraftBukkit
$ mvn clean install
This is the error I get...
sam#qntm:~/CraftBukkit$ mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building CraftBukkit
[INFO] task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /home/sam/CraftBukkit/target
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 133 source files to /home/sam/CraftBukkit/target/classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
Unable to locate the Javac Compiler in:
/usr/lib/jvm/java-6-openjdk/jre/../lib/tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.
Unable to locate the Javac Compiler in:
/usr/lib/jvm/java-6-openjdk/jre/../lib/tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Tue Feb 08 17:42:57 MSK 2011
[INFO] Final Memory: 12M/151M
[INFO] ------------------------------------------------------------------------
Apologies if there is a really simple and obvious solution.
ensure that your JAVA-HOME variable is set to proper path. Here is described how to set it properly http://www.cyberciti.biz/faq/linux-unix-set-java_home-path-variable/

Does this Maven plugin really have an invalid descriptor?

COMMAND:
mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate -DarchetypeGroupId=org.beardedgeeks -DarchetypeArtifactId
=gae-eclipse-maven-archetype -DarchetypeVersion=1.1.2 -DarchetypeRepository=http://beardedgeeks.googlecode.com/svn/repository/release
s
OUTPUT:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Internal error in the plugin manager getting plugin 'org.apache.maven.plugins:maven-archetype-plugin': Plugin 'org.apache.maven
.plugins:maven-archetype-plugin:2.0-alpha-4' has an invalid descriptor:
1) Plugin's descriptor contains the wrong group ID: net.kindleit
2) Plugin's descriptor contains the wrong artifact ID: maven-gae-plugin
3) Plugin's descriptor contains the wrong version: 0.5.9
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Wed Jun 09 20:48:35 CEST 2010
[INFO] Final Memory: 3M/15M
[INFO] ------------------------------------------------------------------------
I have a hard time believing this Maven plugin has an invalid descriptor since other people seem to be using it with no problem. Am I doing something wrong?
Can't reproduce your problem, the following command works fine for me (copied & pasted from GAE + Eclipse + Maven Archetype):
mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate \
-DarchetypeGroupId=org.beardedgeeks \
-DarchetypeArtifactId=gae-eclipse-maven-archetype \
-DarchetypeVersion=1.1.2 \
-DarchetypeRepository=http://beardedgeeks.googlecode.com/svn/repository/releases
Tested with Maven 2.2.1:
$ mvn -version
Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)
Java version: 1.6.0_20
Java home: /usr/lib/jvm/java-6-sun-1.6.0.20/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux" version: "2.6.32-22-generic" arch: "i386" Family: "unix"
I often experience problems with crappy metadata in my local repository. This kind of error usually vanishes after I do
rm -Rf my/home/dir/.m2/repository/net/kendleit/maven-gae-plugin
but actually the reason why it works with Pascal is that Pascal uses this url http://beardedgeeks.googlecode.com/svn/repository/releases whereas you use this url http://beardedgeeks.googlecode.com/svn/repository/release (an s is missing, hence there's a 404)
do the rm as mentioned above and then run again with the correct url
EDIT: sorry there is actually a trailing s I didn't see. I take everything back, but still: try to delete the metadata in your local repo
Reason:
the GAV (groupid, artifactid, version) in Nexus (consequently in local repository and in the pom.xml) is not the same as the one in the jar file in \META-INF\maven\plugin.xml
This usually happens when you upload manually the plugin artifact in your own Nexus (or any other maven enterprise repository)
Solution:
download the jar, see what are the GAV values in plugin.xml
upload the jar on Nexus, passing as GAV the information from the plugin.xml
Update the pom.xml accordingly
Make sure to remove from Nexus the old inconsistent artifact.

Categories

Resources