我正在使用一个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代码中使用?????
答案 0 :(得分:0)
您应在-jar
之前传递参数:
/bin/su $USER -c "${JAVA} $pswd -jar ${JAR}"
答案 1 :(得分:0)
That is the right way
/bin/su $USER -c "${JAVA} -jar ${JAR} $pswd"