Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6713321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:21:58+00:00 2026-05-26T08:21:58+00:00

How to get Maven project basedir() from my Java code?

  • 0

How to get Maven project basedir() from my Java code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:21:59+00:00Added an answer on May 26, 2026 at 8:21 am

    According to maven doc, there’s a maven property ${project.basedir}

    If you include a properties file in your resources, which has the ${project.basedir} placeholder, and enable filtering for the resources plugin, you will find that there’s a build time substitution of the basedir into the properties file. You can then load this using a Properties instance in code.

    in /src/main/resources, create a file called project.properties, containing

    my.basedir=${project.basedir}
    

    Then, in the POM, enable filtering for /src/main/resources, as outlined in the maven resources filtering documentation linked above.

    Then, in code, at runtime, load the properties file into a Properties instance

    Properties props = new Properties();
    props.load(this.getClass().getResourceAsStream("project.properties"));
    String myBasedir = props.get("my.basedir");
    

    An alternative would be to process some source files and do substitution in there by hooking into the process-sources phase, but that’s not likely to be easy to explain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any to get the entire remote repository, say from http://repo1.maven.org/maven2/ , to
I run a simple CXF maven project http://cxf.apache.org/docs/using-cxf-with-maven.html , and get error below [INFO]
In my Maven project, I have the following code in the main method: FileInputStream
How do I get IntelliJ to auto-configure the Scala facet in a Maven project
I have a hierarchical maven project, from which I am trying to build a
Previous I issued a question on how to change Maven project vesion from command
I need to profile a java application for a customer. It's an eclipse/maven project,
Is it possible to get an instance of org.apache.maven.project.MavenProject or some other object form
I am trying to compile a maven project, but I systematically get the following
To Maven gurus out there: I'm trying to package non-java project artifacts (.NET) into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.