How to pass argument to maven from shell script

Shubham Goswami :

I am using a shell script that takes input from the user and sends it to maven pom.xml and further this argument using by java code.

And this the steps

1) Shell script is 

   #!/bin/bash
   ### Input password as hidden charactors ###
   read -s -p "Enter Password: "  pswd
   # passing this argument that called my java code.
   /bin/su $USER -c "${JAVA} -jar ${JAR}" $pswd

2) how can I pass the argument $pswd in my maven pom.xml

     <build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <mainClass>com.abc.abcd.abcde.server.pswd.Password</mainClass>
            </transformer>
          </transformers>
          <filters>
            <filter>
              <artifact>*:*</artifact>
              <excludes>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
              </excludes>
            </filter>
          </filters>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

This is my java code

   public final class Password
  {

    private Password()
   {
   }

   public static void main(final String[] args)
   {
    System.out.println(args[0]);
   }
   }
Enter Password: Exception in thread "main" 
java.lang.ArrayIndexOutOfBoundsException: 0

So how can I pass the $pswd argument to maven pom.xml and the same argument will use in Java code ?????

inkognitto :

You should pass arguments before -jar:

/bin/su $USER -c "${JAVA} $pswd -jar ${JAR}"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=157269&siteId=1