【发布时间】:2019-09-29 15:09:47
【问题描述】:
我正在使用一个 shell 脚本,它接收用户的输入并将其发送到 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 代码中使用 ???????
【问题讨论】: