Search code examples
javawrappertomcat8tomcat-manager

Java wrapper class/library for Tomcat manager


I am wondering if there is a simple wrapper class/library for the Tomcat Manager application. I am writing a script to deploy my war to a remote instance of Tomcat (hosted on AWS).

I know I can directly use HTTP to communicate with the manager script interface, but I thought this would be a common problem, so I do not want to re-invent the wheel. I found a python solution here, and this question talks about using curl, but I can't find a java solution (which is funny, Tomcat is used by Java developers, not bash developers!) Can someone please point me in the right direction?


Solution

  • I found what I needed in this answer. I can use the Tomcat Ant library. In order to do so, all I need is the catalina-ant.jar from $CATALINA_HOME/lib in my project's dependencies.

    org.apache.catalina.ant.DeployTask task = new org.apache.catalina.ant.DeployTask();
    task.setUrl("http://localhost:8084/manager");
    task.setUsername("managerLogin");
    task.setPassword("managerPassword");
    task.setPath("/UrlToYourDeploadingProject");
    task.setWar(new File("c:/Project.war").getAbsolutePath());
    task.execute();