How to generate the jar file with Maven commands?

Asked

Viewed 648 times

0

I am in a Spring Boot project, I am managing to generate the jar file through the eclipse tool as you can see below;

inserir a descrição da imagem aqui

2 Stage;

inserir a descrição da imagem aqui

3 Stage;

inserir a descrição da imagem aqui

Last;

inserir a descrição da imagem aqui

But when I run through Maven it generates several errors as you can see below;

  mvn clean install
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/1.5.3.RELEASE/spring-boot-starter-parent-1.5.3.RELEASE.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.example:dockerTest:1.0.0-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.3.RELEASE from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version and 'parent.relativePath' points at no local POM @ line 5, column 10
 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project com.example:dockerTest:1.0.0-SNAPSHOT (C:\Users\re038022\Documents\workspace-spring-tool-suite-4-4.3.0.RELEASE\dockerTest\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.example:dockerTest:1.0.0-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.3.RELEASE from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version and 'parent.relativePath' points at no local POM @ line 5, column 10 -> [Help 2]
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

DESKTOP-LTE4439+resource@DESKTOP-LTE4439 MINGW64 /c/Users/re038022/Documents/workspace-spring-tool-suite-4-4.3.0.RELEASE/dockerTest

$  mvn package
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-parent/1.5.3.RELEASE/spring-boot-starter-parent-1.5.3.RELEASE.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.example:dockerTest:1.0.0-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.3.RELEASE from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version and 'parent.relativePath' points at no local POM @ line 5, column 10
 @
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project com.example:dockerTest:1.0.0-SNAPSHOT (C:\Users\re038022\Documents\workspace-spring-tool-suite-4-4.3.0.RELEASE\dockerTest\pom.xml) has 1 error
[ERROR]     Non-resolvable parent POM for com.example:dockerTest:1.0.0-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.3.RELEASE from/to central (https://repo.maven.apache.org/maven2): Received fatal alert: protocol_version and 'parent.relativePath' points at no local POM @ line 5, column 10 -> [Help 2]
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException

I’ve tried with mvn clean install and it didn’t work either, I don’t know what could be wrong, I need help.

This is my pom.xml file

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.example</groupId>
    <artifactId>dockerTest</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <name>dockerTest</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- mysql -->
<!--        <dependency> -->
<!--            <groupId>mysql</groupId> -->
<!--            <artifactId>mysql-connector-java</artifactId> -->
<!--            <scope>runtime</scope> -->
<!--        </dependency> -->

       <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.4-1200-jdbc4</version>
        </dependency>

        <!-- Migracoes - Flyway -->
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
        </dependency>

        <!-- Hibernate Java 8 Support -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-java8</artifactId>
        </dependency>

        <!-- Suporte do Jackson para as datas do Java 8 -->
        <dependency>
            <groupId>com.fasterxml.jackson.datatype</groupId>
            <artifactId>jackson-datatype-jsr310</artifactId>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.4</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
             <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
               <version>3.8.1</version>
                <configuration>
                    <fork>true</fork>
                    <executable>C:\Program Files\Java\jdk1.7.0_45\bin\javac.exe</executable>
                </configuration>
            </plugin>
        </plugins>
    </build>



</project>

I need to be able to generate the Jar file through the Maven commands. It is very important that I can do it through commands!

By the error you are saying that the problem is on line 5 of the pom.xml file that refers to this code snippet;

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

2 answers

0

Hello,

I noticed that you are using a specific Settings when generating by Eclipse

By command line you may be using another

Initially check that the java that is called by command line is the same one you call in Eclipse (run at the DOS prompt)

java -version

Then check if it’s the same Maven

mvn -version

Finally ensure that you are using the correct Settings.xml

 mvn --settings C:\Users\re038022\settings.xml clean install

If no error occurs the jar must be generated in the target folder with clean install

If you still have an error run the same command by passing the -X argument to see debug information

mvn -X --settings C:\Users\re038022\settings.xml clean install
  • there is no file Settings.xml in the re038022 folder

  • I believe that you must be using the onboard vesion of the Maven in the eclipse, you came to install the Maven "on the outside"??

  • installed yes, and so much so that I can execute Maven commands anywhere in MSDOS.

  • the command did not work even performing in the right file where the setteings.xml 'mvn --Settings C: Users re038022 Settings.xml clean install'

  • check the proxy configuration in Settings.xml as Jroger mentioned, maybe you are using a different proxy configuration in Eclipse

0

There is no error in your configuration, before packaging, you first need to solve your pom dependency problem. In the log you’re saying that Maven couldn’t get the dependency:

[ERROR] Non-resolvable Parent POM for com.example:dockerTest:1.0.0-SNAPSHOT: Could not transfer Artifact org.springframework.boot:spring-boot-Starter-Parent:pom:1.5.3.RELEASE from/to central (https://repo.maven.apache.org/maven2): Received fatal Alert: protocol_version and 'Parent.relativePath' points at no local POM@line 5, column 10 -> [Help 2]

Searching in the mavenrepository it exists, so it may be a problem to download the dependency and nothing else, check your proxy and if it is authenticated configure the Maven to authenticate.

http://maven.apache.org/ref/3.0/maven-model/maven.html#class_parent

Another thing is that the use of relativePath usually generates errors in the output and can be interpreted as false-positive ( not your case ), follows as documentation information of how the relativePath works:

The relative path of the Parent pom.xml file Within the check out. If not specified, it defaults to .. /pom.xml. Maven looks for the Parent POM first in this Location on the filesystem, then the local Repository, and lastly in the remote Repo. relativePath Allows you to select a Different Location, for example when your Structure is flat, or Deeper without an Intermediate Parent POM. However, the group ID, Artifact ID and version are still required, and must match the file in the Location Given or it will revert to the Repository for the POM. This Feature is only for Enhancing the Development in a local checkout of that project. Set the value to an Empty string in case you want to disable the Feature and Always resolve the Parent POM from the repositories.

One option is to run the package using the option -X that enables debug in the log:

mvn clean package -X

  • If I run this command 'Maven clean package -X' Maven does not recognize 'bash: Maven: command not found'

  • Sorry, it was a syntax error the command would be mvn clean package -X

Browser other questions tagged

You are not signed in. Login or sign up in order to post.