maven generating pom file - maven

I use maven 3.0.3 and have tried to generate pom for third-party jar like this:
mvn install:install-file -Dfile=cobra.jar -DgroupId=com.cobra
-DartifactId=cobra -Dversion=0.98.4 -Dpackaging=jar -DgeneratePom=true
According to link below it should generate proper pom.xml and install artifact in the repo.
http://maven.apache.org/plugins/maven-install-plugin/examples/generic-pom-generation.html
Meanwhile, it returns such a error:
[ERROR] The goal you specified requires a project to execute but there
is no POM in this directory (D:\cobra-0.98.4\lib). Please verify you
invoked Maven from the correct directory. -> [Help 1]
Why is it asking for pom.xml while it should generate pom.xml?

This is an old question, but was a serious PITA for me for a few minutes, so I thought I'd share:
I just ran into this problem, and I believe that the issue is probably platform-dependent. The real tip-off was that the solution from Cyril's answer wasn't working as expected: despite my specification of -DgroupId=com.xyz and -DartifactId=whatever on the command-line and the corresponding entry in the POM file, the jar was installed in the local repo under com/whatever.
This led me to experiment with quoting command-line arguments, and the eventual correct result from formatting the command-line like this (after deleting the POM file):
mvn install:install-file "-Dfile=cobra.jar" "-DgroupId=com.cobra" "-DartifactId=cobra" "-Dversion=0.98.4" "-Dpackaging=jar" "-DgeneratePom=true"
Some of the quoting is doubtless redundant, but better safe than sorry, right? I happen to be running Vista on this computer, and would not be surprised if this problem were specific to this OS version...by the way, this was with Maven v3.0.4.

Are you sure that you are executing the install-file goal? I checked your command and it works for me, but when I place a blank install :install-file (maybe you have this typo) the install goal would be used which needs a pom.xml.
Try to use the -X parameter to get more debug information:
-X,--debug Produce execution debug output
My system
Maven
c:\>mvn -version
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: C:\progs\apache-maven-3.0.3
Java version: 1.6.0_21, vendor: Sun Microsystems Inc.
Java home: c:\Program Files (x86)\Java\jdk1.6.0_21\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows"
Install Plugin
c:\>mvn -Dplugin=install help:describe
Name: Maven Install Plugin
Description: Copies the project artifacts to the user's local repository.
Group Id: org.apache.maven.plugins
Artifact Id: maven-install-plugin
Version: 2.3.1
Goal Prefix: install
This plugin has 3 goals:
install:help
Description: Display help information on maven-install-plugin.
Call
mvn install:help -Ddetail=true -Dgoal=<goal-name>
to display parameter details.
install:install
Description: Installs the project's main artifact in the local repository.
install:install-file
Description: Installs a file in the local repository.
For more information, run 'mvn help:describe [...] -Ddetail'

I found a bypass. You need to create a simple pom.xml like this :
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.cobra</groupId>
<artifactId>cobra</artifactId>
<version>0.98.4</version>
</project>
It's not perfect but it's worked for me. If you find a better way to do that, I'm interested.
My config :
$mvn -version
Apache Maven 3.0.3 (r1075438; 2011-02-28 18:31:09+0100)
Maven home: /usr/local/maven
Java version: 1.6.0_20, vendor: Sun Microsystems Inc.
Java home: /usr/local/jdk1.6.0_20/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-25-generic-pae", arch: "i386", family: "unix"
$mvn -Dplugin=install help:describe
...
Name: Maven Install Plugin
Description: Copies the project artifacts to the user's local repository.
Group Id: org.apache.maven.plugins
Artifact Id: maven-install-plugin
Version: 2.3.1
Goal Prefix: install
...

Try to run it on cmd.exe or execute cmd command before the mvn command.

Using maven version 3.6.3, this worked for me to generate pom file in my chosen directory:
C:<MyChosenDir> mvn archetype:generate "-DgroupId=com.mycompany.app" "-DartifactId=my-app" "-DarchetypeArtifactId=maven-archetype-quickstart" "-DarchetypeVersion=1.4" "-DinteractiveMode=false"

just go under your project directory where you can find your pom.xml file then execute the same command ! it works for me ;)

If you are having trouble with the command line version of Maven, you might want to try the M2E plugin for eclipse. It is far more user friendly for people without very much experience with Maven.

It worked for me when I changed Powershell to Cygwin. Powershell is somehow parsing the command line argument incorrectly.

I had that error when I was using maven in Windows, what worked for me was opening the cmd and not the PowerShell.
Apparently certain errors appear when you don't do it with the cmd.
I hope it works.

If you are getting this error during jenkins pipeline setup , Then the error is we are placing git repository without .git in jenkins git url blank .Generally we put website url of git repo but we need to place clone url of git repo.Insert .git (cloned url) to website url , Simply insert git clone url.

Related

Maven reading settings.xml from wrong place

I am new to Maven and Ubuntu. I am having trouble building maven projects. When I run the mvn clean -X command I can see the below DEBUG logs.
[DEBUG] Reading global settings from /space/user/programs/apache-maven-3.5.3/conf/settings.xml
[DEBUG] Reading user settings from ?/.m2/settings.xml
[DEBUG] Reading global toolchains from /space/user/programs/apache-maven-3.5.3/conf/toolchains.xml
[DEBUG] Reading user toolchains from ?/.m2/toolchains.xml
[DEBUG] Using local repository at /space/user/git/receiver/?/.m2/repository
I have following settings in .bashrc file
export JAVA_HOME=/space/user/programs/jdk1.8.0_162
export M2_HOME=/space/user/programs/apache-maven-3.5.3
export MAVEN_HOME=/space/user/programs/apache-maven-3.5.3
And I have settings.xml file in /home/user/.m2 folder
Why maven is not picking /home/user/.m2/settings.xml? What is it that I am missing here please? If you need any further information please let me know and I will update the question.
I am using Ubuntu 16.04.
UPDATE:
Output of mvn --version command
Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-24T19:49:05Z)
Maven home: /space/user/programs/apache-maven-3.5.3
Java version: 1.8.0_162, vendor: Oracle Corporation
Java home: /space/user/programs/jdk1.8.0_162/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "4.13.0-37-generic", arch: "i386", family: "unix"
UPDATE:
Overriding settings on command line like this mvn --settings /home/user/.m2/settings.xml clean -X works fine. But this is not the solution I want.
The solution was to use 64-bit JDK on a 64-bit system. I somehow copied 32-bit JDK, and this was the problem. It worked as expected with a 64-bit runtime.
This question helped me solve the issue - Java: System.getProperty("user.home") returns "?"
Note: your linux machine might have both a 32-bit and a 64-bit version of the JVM installed. Even Java 11. #Newbee is correct that this can cause weird maven behavior that they described. Check your alternatives to see which one is being pointed at (for CentOS / RHEL machines):
ls -l /etc/alternatives/java_sdk_11
sudo alternatives --display java_sdk_11
sudo alternatives --config java_sdk_11

Maven fails to connect to repositories (I think)

I started doing this tutorial, on win 8.1.
I downloaded JDK8 and Maven.
I set up Maven (added mvn to PATH, set JAVA_HOME).
Output from mvn --version:
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T18:41:47+02:00)
Maven home: C:\apache\apache-maven-3.3.9\bin\..
Java version: 1.8.0_122-ea, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_122\jre
Default locale: en_US, platform encoding: Cp1255
OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "dos"
Created folder for the project.
tried to run this command (copy-paste from the tutorial, ignore the line breaks in SO): mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp -DarchetypeGroupId=org.apache.maven.archetypes -DinteractiveMode=false -DgroupId=com.example.employees -DartifactId=employees-app -DarchetypeVersion=1.0
output from command: pastebin
summary of the output: No plugin found for prefix 'archetype' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the
repositories [local (C:\Users\yogevl\.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
Answers in SO assumes I have a proxy. I don't, I checked it here. Plus, I am able to get to the repo using Chrome.
Another answer advised to run the cmd as an Administrator. I did - same result.
I also followed the link at the end of the output:
Don't think so, because I copy-pasted from the toturial.
Ditto.
Ditto.
Not sure about this one - the settings.xml is the default file. Do I need to change it?
Same as 1-3.
Thank you for your help!
After reading the comments here, the solution was to update the cacerts file, since it was lacking the proper certificate for the Maven repo (thanks I-LOVE-2-REVIVE for the answer and the link).
So, if you have the same problem I had, here some things:
This article will guide you how to add the certificate to the cacerts file (Again, thanks I-LOVE-2-REVIVE for the link). Make sure you add the certificate for the repo you need.
Remember that each jdk/jde manages a different certificate list.
The keytool is located at %JAVA_HOME%\bin (at first I thought it was a linux shell tool, it's not).
Insert appropriate proxy settings to your file ~/.m2/settings.xml (On Windows probably C:\Users\you\.m2\settings.xml):
<settings>
...
<proxies>
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username></username> <!-- perhaps empty, ask admin -->
<password></password>
<host>proxy.your.company.com</host>
<port>8080</port>
<nonProxyHosts>localhost|other.server.com</nonProxyHosts>
</proxy>
</proxies>
...
</settings>

maven-resources-plugin:2.5 - Cannot create resource output directory

I occasionally receive this error when I build my project with
>mvn --version
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 15:51:28+0200)
Maven home: ...\apache-maven-3.0.5
Java version: 1.6.0_45, vendor: Sun Microsystems Inc.
Java home: ...
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
and the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.5:resources
(default-resources) on project project-name: Cannot create resource output directory:
path\to\project\code\project-name\target\classes -> [Help 1]
Note: this happens sometimes, and it is not related to the code. It can happen in one of two consecutive builds - one after the other, against exactly the same source code.
Does anyone have any idea how to avoid it completely? It tends to interrupt quite a time-consuming build :-/
On Windows, there reasons for being unable to create a folder are:
Some other process is deleting this folder at the same time
You don't have permissions to access this folder
The folder is on a network share
Network shares are notoriously unreliable on Windows. Don't use them for any automated tasks. Always build projects with all files residing on a local hard disk.
If you use Maven and Eclipse to build at the same time, you should configure them to use different target folders. See https://stackoverflow.com/a/54366009/34088
Your POM should look like this:
<project>
...
<build>
<outputDirectory>${basedir}/${target.dir}/classes</outputDirectory>
<testOutputDirectory>${basedir}/${target.dir}/test-classes</testOutputDirectory>
</build>
<properties>
<target.dir>target</target.dir>
</properties>
<profiles>
<profile>
<id>eclipse-folders</id>
<properties>
<target.dir>target-eclipse</target.dir>
</properties>
</profile>
</profiles>
...
All that's left is to enable the profile eclipse-folders in the IDE.
Disable the automatic build of your IDE (Eclipse or IntellJ IDEA or whatever). It will conflict with the Maven build.
I experience this issue every time I run the command while I have the output folder or the parent folder opened in Windows Explorer.
If I move one level above the parent, the build ends successfully.
For me the reason for this was only being in said folder with my git bash while building. Ensure that you don't happen to have the said folder open in any other program.
I had the exact same issue when trying to run the First Cup tutorial.
I fixed it by simply closing NetBeans and running it as administrator (via right click).
In my case the parent directory inside which maven was trying to create a directory was root, so I did a sudo chown -R : /path/to/directory to change permissions before rerunning the mvn command.
In my case, I opened the jar in 7zip and I opened the target folder. I run my application and received this error. After closing 7zip, the application run fine and build successfully.
You can use the following in pom.xml
<build>
<directory>${project.basedir}/target1</directory>
</build>
My issue was resolved when I gave mvn clean command from windows coammandprompt

Broadleaf commerce Adding maven home in build.properties file

I am trying to run the Broadleaf Demosite project in eclipse. I have setup the Demosite by following the instructions from the
Getting started guide from broadleaf site. The default code in the build.properties file inside the Demosite maven parent project shows this,
#required
maven.home=/usr/share/maven
#optional
jrebel.path=/usr/lib/jrebel/jrebel.jar
As maven.home is required to start up the server and so now that I have downloaded and extracted the maven 3.0.4 in C:\Users\admin\Downloads\apache-maven-3.0.4\lib.
What is the path I have to specify in the maven.home line in the properties file,
Should it be something like this?
maven.home=C:\User\admin\apache-maven-3.0.4\lib
Maven is shipped into a .zip archive. So unzip maven where do you want. Let's say somewhere like :
C:\User\admin\apache-maven-3.0.4\
then set into your build.properties
maven.home=C:/User/admin/apache-maven-3.0.4
and this should work.
I just changed the maven.home to point to the path like this,
maven.home==/Users/admin/Downloads/apache-maven-3.0.4
Download maven and extract it wherever you want in you computer. Set the path to that directory using command prompt,
C:\Users\admin>set PATH="c:\Users\admin\downloads\apache-maven-3.0.4\bin";%PATH%
Now I'm able to start the jetty server in eclipse with BUILD SUCCESS.
UPDATE:
As the above solution only works for once and you need to run that command every-time you restart the system. For it to work always you have to set the PATH environment variable for maven. Look at How to install maven in Windows? for a permanent solution. Once installed run the following to check if you have installed maven correctly and to check other variables are properly set.
CMD PROMPT
C:\Users\admin>mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 14:14:56+0530)
Maven home: c:\Users\admin\Downloads\apache-maven-3.0.4\bin\..
Java version: 1.6.0_32, vendor: Sun Microsystems Inc.
Java home: C:\Program Files\Java\jdk1.6.0_32\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
C:\Users\admin>
If all the above works fine then in the properties file, you have to specify the maven home directory which in my case was,
C:/Users/admin/Downloads/apache-maven-3.0.4
Sometimes the single forward slash(/) doesn't work in Windows, so replace it with double-forward slash(//) and that should work.
Default value in build.properties file:
#required
maven.home=/usr/share/maven
You have to follow the below format:-
#required
maven.home=C://Program Files//apache-maven-3.0.5-bin//apache-maven-3.0.5

Maven not working?

Initially I used maven with proxy and it was working fine. Now I don't need the proxy, so I edited the settings.xml to not use proxy. After that, Maven does not connect to the Internet to download repos. I tried reinstalling, but still getting the same problem. I even tried IDEs like eclipse and IDEA but the problem was still there. How do I resolve this?
mvn --version
Apache Maven 2.2.1 (rdebian-8)
Java version: 1.6.0_24
Java home: /usr/lib/jvm/java-6-openjdk-i386/jre
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux" version: "3.2.0-31-generic-pae" arch: "i386" Family: "unix"
mvn archetype:generate -DgroupId=org.sonatype.mavenbook.simple -DartifactId=simple -DpackageName=org.sonatype.mavenbook -Dversion=1.0-SNAPSHOT
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] org.apache.maven.plugins: checking for updates from central
Nothings happens after this.
All things considered, my initial thought is this is a connection issue since it fails to work after removing the proxy settings. Are you able to ping or curl the repository being scanned?

Resources