I need to find a war file in the java-code and upload it to tomcat8. I do not understand how this is done. I looked at the official website, or did not understand anything, or nothing. That is, somewhere on the disk is the file C: \ test \ test.war I find it in another application and I want to upload it to the server. I don’t want to do this with my hands, as I automate the process. rest api could not

Who can tell or give an example of how to upload a specific file to the server in java?

  • one
    You can put the file on a remote server via FTP or SFTP, in the folder webapps/ , as a regular file. Or via HTTP via the Tomcat manager interface . But the easiest option without java code is curl. - enzo

2 answers 2

In java-code there is no war-file. You compile your java-code, add the WEB-INF folder with web.xml and pack it in war instead of jar.

This can be done either in the IDE, or by various collectors (Maven, Gradle, Ant, etc.) For more information, see here: https://ru.wikipedia.org/wiki/WAR_(%D1%82%D0%B8% D0% BF_% D1% 84% D0% B0% D0% B9% D0% BB% D0% B0)

or google by "war file structure java"

When you receive a war file (for example myapp.war), it needs to be closed. This can be done by throwing it into the webapps folder.

  • @Rsstam I corrected the question. that's not what i wanted - senior pomidor
  • @SeniorAutomator I don’t know how in tomkate, in JBoss / WildFly, you can, among other things, upload it through the admin console (web), but it is even more difficult to automate than throw the file into the SSH folder - Russtam

apache-tomcat-8.0.26 \ conf \ tomcat-users.xml add a user who has rights to deploy

 <role rolename="manager-gui"/> <role rolename="manager-script"/> <user username="admin" password="admin" roles="manager-gui"/> <user username="tomcat" password="admin" roles="manager-script"/> 

manager-gui - for access to the admin-script admin area for deployment.

further http: // localhost: 8080 / manager / text / deploy? path = / foo & war = file: C : \ workflow \ calendar-1.1.war

log: OK - Deployed application at context path / foo

here is the link