Maven - How to create a pom.xml for java project through command line
Asked Answered
O

3

5

Currently working on a work training on Maven. I've never used it before and the training is very limited. One of the assessments is asking me to do the following using command line.

  1. Create a new Directory in a local storage.
  2. Place the downloaded project in this directory and create maven build file(pom.xml).**
  3. In pom.xml file create a project element, In project element create default elements such as modelVersion,groupId,artifactId,packaging,version,name for project

Its the number 2 I can't seem to get write. I know how to create a new maven project using command line(below), however when I try to create the pom.xml for a project, it doesn't work.

    mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

Any help would be great thanks.

Olia answered 29/11, 2017 at 14:19 Comment(3)
If you create a project from an archetype you already have pom.xmlEntente
The project wasn't made from an archetype. It's just a java scr folder with two java files.Olia
I think the step 2 is just about creating an empty pom.xml file.Auroraauroral
N
5

You can run mvn archetype:generate without parameters. Maven will ask about your project and generate the POM.

Nila answered 22/6, 2020 at 20:37 Comment(2)
I got the following error when running the command as-is, for Maven version 3.8.4: [ERROR] 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 repositoriesAsteria
#60124530 - This solved the error.Asteria
S
2

I solved a similar problem by creating an empty Maven project, then taking that default (basically a template) pom.xml and modifying it to my project's configuration.

What I did was start by creating a pom.xml wrapper that looked like this:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 

</project>

Then I added the specifics of my project like this:

<modelVersion>4.0.0</modelVersion>
<groupId>com.ingeniigroup.stratux</groupId>
<artifactId>AvMet</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>
<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

[...]

Once I had done that, maven handled the build just fine.

I wrote a blog entry that has some more background if you need it: http://blog.daviddemartini.com/configure-maven-pom-xml-to-build-integrated-executable-jar-fat-jar/

Seleta answered 29/11, 2017 at 15:35 Comment(1)
What does the modelVersion tag refer to? (I cannot access your blog from my current domain.)Asteria
S
-1

4.0.0

<groupId>com.practicemaven</groupId>
<artifactId>com.practicemaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>com.practicemaven</name>
<url>http://maven.apache.org</url>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <systemPropertyVariables>
                    <browser>edge</browser>
                    <env>amazonqaurl</env>
                    <Team>High5</Team>
                </systemPropertyVariables>
                <suiteXmlFiles>
                    <suiteXmlFile>src/main/resources/amazontest.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <executions>
                <execution>
                    <id>attach-sources</id>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>


    </plugins>

</build>

<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.14.3</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.14.0</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>4.1.0</version>
    </dependency>

</dependencies>
Skinned answered 31/8 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.