[英]java- how to deploy a jar file which is on a remote machine-with some user defined arguments
I am pretty new to maven/ant hence please excuse me if my question sounds silly to you... 我对Maven / ant很陌生,因此,如果我的问题对您听起来很愚蠢,请原谅我...
In an application I am working on, I have to initialise a virtual machine (eg Amazon EC2 instance), then upload a JAR file to that machine and finally, run it-- each time I want to run it, the run-time arguments may be different. 在我正在处理的应用程序中,我必须初始化一个虚拟机(例如Amazon EC2实例),然后将JAR文件上传到该计算机,最后运行它-每次我想运行它时,都会运行时参数可能有所不同。
What is the best way of doing this? 最好的方法是什么? What frameworks/libraries (like maven or ant) will I require to be installed on that virtual machine, in addition to JRE, for this to work?
除了JRE,我还需要在该虚拟机上安装哪些框架/库(例如maven或ant)才能正常工作?
If you stick to Maven
, you can attack the jar uploading process to the install phase
as follows: 如果你坚持
Maven
,你可以攻击坛子上载过程中的install phase
如下:
pom.xml : pom.xml:
...
<plugins>
...
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<tasks>
<scp todir="${targetNode}:~/" trust="true" failonerror="true"
file="${project.build.directory}/${project.build.finalName}.jar" />
</tasks>
</configuration>
<executions>
<execution>
<id>upload</id>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.8.3</version>
</dependency>
</dependencies>
</plugin>
...
</plugins>
...
Then issue: 然后发出:
mvn clean install "-DtargetNode=user:pass@machine"
Optionally write a script that runs the uploaded jar on the target machine. (可选)编写一个脚本,在目标计算机上运行上载的jar。
Best way would be to create shell script that does all you need. 最好的方法是创建可以满足您所有需求的shell脚本。 If the machine is unix like, you can achieve all this with ssh, scp (uses ssh).
如果机器是unix之类的,则可以使用ssh,scp(使用ssh)来实现所有这些功能。
With ssh you can execute remote shell commands. 使用ssh可以执行远程shell命令。
Example (all_in_one.sh): 示例(all_in_one.sh):
args=$1
arg2=$2
etc.
ssh admin@amazon_instance << end
/home/admin/bin/startAmazonVM.sh $arg1
end
scp mylocal.jar admin@amazon_instance:/home/admin/server/libraries/
ssh admin@amazon_instance << end
$JAVA_HOME/bin/java -jar /home/admin/server/libraries/mylocal.jar $arg2
end
Then you can run eg all_in_one.sh (add >> output.txt to create execution output file, which you may then parse to verify the process) 然后,您可以运行例如all_in_one.sh(添加>> output.txt以创建执行输出文件,然后可以对其进行解析以验证过程)
If you are working on Windows, install Cygwin or MinGW, or use ant and spend some more, more time configuring tasks in it to do the things other tools do best. 如果您使用的是Windows,请安装Cygwin或MinGW,或使用ant并花费更多,更多的时间在其中配置任务以完成其他工具最擅长的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.