How to get Maven project basedir() from my Java code?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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 aPropertiesinstance in code.in /src/main/resources, create a file called project.properties, containing
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
PropertiesinstanceAn alternative would be to process some source files and do substitution in there by hooking into the
process-sourcesphase, but that’s not likely to be easy to explain.