Variable pom.xml that shows the location of the file

Asked

Viewed 210 times

-1

I use Ubuntu 18.04.

My project is on an NTFS partition.

I need to know which variable shows the location the pom.xml file is in.

I’m using the ${basic} variable, but it’s not showing where the pom.xml file is..

It is showing the directory: /home/Gustavo/. m2/Repository/

The strange thing is that this variable works in Windows 10

1 answer

0


Try to use the

${project.basedir} 

https://cwiki.apache.org/confluence/display/MAVEN/Maven+Properties+Guide

You can try to print the variables to check.

I put an example on Github. Just run the mvn clean install and check the properties.txt file.

I tested on Ubuntu 20.04 and worked as expected.

<?xml version="1.0" encoding="UTF-8"?>
<project>
...
    <build>
        <plugins>
            <plugin>
                <groupId>ru.yaal.maven</groupId>
                <artifactId>write-text-files-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <charset>UTF-8</charset>
                    <files>
                        <file>
                            <path>properties.txt</path>
                            <lines>
                                <line>=== JAVA PROPERTIES ===</line>
                                <line>Java vendor: ${java.vendor}</line>
                                <line>Java version: ${java.version}</line>
                                <line>Java home: ${java.home}</line>
                                <line>=== OS ENVIRONMENT ===</line>
                                <line>User dir: ${env.HOME}</line>
                                <line>=== MAVEN SETTINGS.XML ===</line>
                                <line>Offline: ${settings.offline}</line>
                                <line>=== Maven Properties Guide ===</line>
                                <line>Description:                          ${project.description}</line>
                                <line>project.basedir:                      ${project.basedir} </line>
                                <line>project.build.directory:              ${project.build.directory}</line>
                                <line>project.build.outputDirectory:        ${project.build.outputDirectory}</line>
                                <line>project.build.testOutputDirectory:    ${project.build.testOutputDirectory}</line>
                                <line>project.build.sourceDirectory:        ${project.build.sourceDirectory}</line>
                                <line>project.build.testSourceDirectory:    ${project.build.testSourceDirectory}</line>
                                <line>project.build.finalName:              ${project.build.finalName}</line>
                                <line>project.version:                      ${project.version}</line>
                                <line>settings.localRepository:             ${settings.localRepository}</line>
                                <line>basic:                                ${basic}</line>
                            </lines>
                        </file>
                    </files>
                </configuration>
                <executions>
                    <execution>
                        <id>write-text-files</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>write-text-files</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
  • Hi Rafael, I’ve done it. The strange thing is that these variables work in Windows 10. My environment is Linux 18.04 LTS, and the eclipse I use has the same version (Oxygem March 2018)

  • I updated the answer. I ran the test on Linux and it worked correctly. Maybe your pom.xml has some configuration that is changing the root of the project. Check the example I put in the reply and say what it prints in your environment.

  • I followed your instructions Rafael and the variables are pointing to the right place: (project.basedir: /media/Gustavo/New volume/GIT/systems/Commons/Commons-ejb). But I can’t concatenate this variable with another URL in the systemPath property in dependencies in Ubuntu 18, only fucks in Windows 10. Follow the pom.xml line: <systemPath>${project.basedir}.. /.. /Commons/target/Commons-0.0.1.jar</systemPath>

  • What is the folder structure of your Gustavo project?

  • i have a COMMONS-EJB project that is on the way: /media/Gustavo/New volume/GIT/systems/Common/Commons-ejb. This project has a dependency on another COMMONS project that is on the following path: /media/Gustavo/New volume/GIT/systems/Commons/Commons

  • In the eclipse I opened the "Effective pom" tab and it is showing in systemPath the following path: <systemPath>/media/Gustavo/New volume/GIT/Common/Systems/Commons-ejb.. /.. /Commons/target/Commons-0.0.1.jar</systemPath>. It is not recognizing the characters ".. /.. /" to go back 2 folders. The strange thing is that in Windows 10 works

  • @Gustavomenezes From your report I think your problem is actually to work with dependencies in Maven. I updated the Github project with a project with this structure that you’re looking for. Import the project and look at the pom’s <modules> structure and how they relate. systempath is only indicated in cases where a dependency is not available in some Maven repository. To use dependencies within the same structure you can use the reference directly in pom.xml.

  • Hi Rafael, really these dependencies are not in the Maven repository, because they are company codes where I work and the owners do not want it to be available there.

  • the "Common" directory is just an operating system folder, serves only for organizing the files on the computer. From what I saw on Github you used this "Commons" as a Maven project to group COMMONS and COMMONS-EJB, right?

  • i saw the "systemPath" property in "dependencies", in "Effective pom" when the pom.xml file is in windows. It has the following path: <systemPath>D: GIT Common Systems Commons-ejb.. /.. /Commons/target/Commons-0.0.1.jar</systemPath>. I think the problem is caused by the way Windows and Ubuntu manage their file folders, "/" bars on Linux and counter bars on Windows ""

  • Take a look at the Github project once again. I did it here on my Linux(Ubuntu 20.04) and it worked. <groupid>br.com.rafaelchagasb</groupid> <artifactId>apache-Commons</artifactId> <version>0.0.1</version> <Scope>system</Scope> <systemPath>${project.basedir}/.. /Commons/Commons-lang3-3.10.jar</systemPath> </dependency>

  • Good evening Rafael! Thank you so much for your help, it worked!!!

Show 7 more comments

Browser other questions tagged

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