KLP
KLP

Reputation: 71

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

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.

Upvotes: 7

Views: 25724

Answers (3)

sreeni
sreeni

Reputation: 9

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>

Upvotes: -1

felipecrp
felipecrp

Reputation: 1069

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

Upvotes: 7

DDeMartini
DDeMartini

Reputation: 337

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/

Upvotes: 2

Related Questions