简体   繁体   English

java-如何使用一些用户定义的参数部署位于远程计算机上的jar文件

[英]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。

You likely won't need Ant/Maven deployed remotely. 您可能不需要远程部署Ant / Maven。

Can you instead ssh / scp onto that machine ? 您可以改为在该计算机上ssh / scp吗? Ant has sshexec and scp tasks to allow you to copy and run stuff remotely. Ant具有sshexecscp任务,可让您远程复制和运行内容。

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.

相关问题 java-如何在Windows命令行中运行JAR文件,该命令行的运行时参数包含“&lt;”和“&gt;”字符 - java- how to run JAR file in Windows command line which has run time arguments containing “<” and “>” chars 如何通过maven将java jar文件部署到远程服务器 - How to deploy a java jar file to remote server through maven 在Java中从远程计算机执行jar文件 - execute jar file from remote machine in java 如果用户计算机上没有安装Java,如何在JAR文件中包含JVM? - How to include a JVM in JAR file if Java is not installed on user machine? java-jar文件找不到资源 - java- jar file cannot find resources java-如何编写一个进程的代码,以拦截在远程计算机上运行的程序的输出流/知道远程程序已停止/完成时 - java- how to code a process to intercept the output streams of program running on remote machine/know when remote program has halted/completed java-在jar文件外部读取属性文件 - java- reading the properties file outside of jar file 如何在Netbeans内部署远程服务器上的jar文件? - How to Deploy a jar File on a remote server from within Netbeans? 我如何在远程服务器中部署jar文件 - how can i deploy the jar file in remote server jar中的哪个文件读取参数 - Which file in a jar reads arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM