Как передать аргумент maven из сценария оболочки - PullRequest
2 голосов
/ 12 мая 2019

Я использую сценарий оболочки, который принимает ввод от пользователя и отправляет его в maven pom.xml и далее этот аргумент, используя код Java.

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>

Это мойJava-код

   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

Так как я могу передать аргумент $ pswd в maven pom.xml, и этот же аргумент будет использоваться в коде Java ?????

Ответы [ 2 ]

0 голосов
/ 13 мая 2019
   That is the right way
  /bin/su $USER -c "${JAVA} -jar ${JAR} $pswd"
0 голосов
/ 12 мая 2019

Вы должны передать аргументы до -jar:

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