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

  • SEARCH
  • Home
  • 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 9265621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:07:00+00:00 2026-06-18T14:07:00+00:00

I need a variable in my archetype resource files that is a path to

  • 0

I need a variable in my archetype resource files that is a path to the directory where the new project is being generated. This StackOverflow post is from a guy who made his own plugin to do this.

Unfortunately, I can’t figure out how it was originally intended to run. If I run this command:

mvn \
com.example.build.maven:property-setter-maven-plugin:0.1:set-properties \
archetype:generate \
-DarchetypeGroupId=... -DarchetypeArtifactId=... -DarchetypeVersion=... -DartifactId=...

from an empty directory where I intend to create the new project from the archetype I get this error:

Goal requires a project to execute but there is no POM in this directory

This seems completely wrong to me. I’m trying to create a new maven project in this directory, there shouldn’t already be a pom.xml there. So, I looked up the phases run by maven-archetype-plugin and decided to instead run this plugin on <goal>archetype:generate</goal> and I removed the set-properties from the maven command I’m executing.

Now, when I run the archetype:generate command it generates an archetype, but none of the environment variables that I need exist, its as if the plugin is now doing absolutely nothing.

Does anybody know how I can get this to work?

  • 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-06-18T14:07:01+00:00Added an answer on June 18, 2026 at 2:07 pm

    First the simple answer:

    Is the custom plugin really needed? The ${basedir} variable should work in archetype resource files which corresponds to the base directory the archetype was run from.

    The root of the target project is ${basedir}/${artifactId}, so if my template pom.xml is the following:

    <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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>${groupId}</groupId>
        <artifactId>${artifactId}</artifactId>
        <version>${version}</version>
        <packaging>jar</packaging>
    
        <name>A custom project at base ${basedir}/${artifactId}</name>
    
    </project>
    

    Then the archetype-generated pom.xml will look something like:

    <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/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>galah</groupId>
        <artifactId>galah-artifact</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
    
        <name>A custom project at base /home/prunge/java/testing/galah-artifact</name>
    
    </project>
    

    (assuming I set the groupId, artifactId, version through the command line/prompt)


    But now let’s assume you need those environment variables for some other reason, not just the base directory of the project.

    From what I can tell, the property-setter-maven-plugin takes the current execution properties and puts them in environment variables. And you need the base directory

    To get the property-setter-maven-plugin to run, it needs modification since the original requires a project/POM to run as defined in the metadata.

    The original MOJO definition:

    /**
     * @goal set-properties
     * @phase validate
     * @since 0.1
     */
    public class PropertySetterMojo extends AbstractMojo
    {
        /**
         * @parameter default-value="${project}"
         * @parameter required
         * @readonly
         */
        private MavenProject project;
    
        /**
         *  @parameter expression="${session}"
         *  @readonly
         */
        private MavenSession session;
    
        /**
         * @parameter expression="${mojoExecution}"
         * @readonly
         * @required
         */
        protected MojoExecution execution;
    
        ...
    
    }
    

    To make it so this plugin can run without a project present, a couple of changes are needed:

    • The @requiresProject false, because this is true by default. Additional documentation is here.
    • There is a project field of type MavenProject and it is marked as @parameter required – this needs to be removed so that the MOJO can execute without a project. From a casual glance at the source code from the original post this field was not used so can be safely removed.

    So you’ll end up with something like:

    /**
     * @goal set-properties
     * @phase validate
     * @since 0.1
     * @requiresProject false 
     */
    public class PropertySetterMojo extends AbstractMojo
    {
        /**
         *  @parameter expression="${session}"
         *  @readonly
         */
        private MavenSession session;
    
        /**
         * @parameter expression="${mojoExecution}"
         * @readonly
         * @required
         */
        protected MojoExecution execution;
    
        ...
    
    }
    

    You can then run the command line as you did before:

    mvn \
    com.example.build.maven:property-setter-maven-plugin:0.1:set-properties \
    archetype:generate \
    -DarchetypeGroupId=... -DarchetypeArtifactId=... -DarchetypeVersion=... -DartifactId=...
    

    and property-setter-maven-plugin should be able to execute now.

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

Sidebar

Related Questions

In my application development, I concluded that I need this variable. IDictionary<string, IDictionary<Levels, IList<Problem>>>
I need a variable that is available from any function in my code, but
I need a variable to hold results retrieved from the database. So far this
In a javascript file (e.g. script.js) I need a variable that contains the absolute
I need a static variable that points to itself to use when referencing the
I have this fragment of Javascript. I need the variable highest_number later in the
I need a variable that shared between reduce tasks and each of reduce tasks
I need a variable expression that calls a sub dataset with a parameter attached.
I have a variable that I need to pass to a subroutine. It is
Do I only prefix var names with @ if I need that variable in

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.