Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Since I found this via google as well, i want to share my deployment and undeployment solution for tomcat 7</p> <p>-) as <a href="https://stackoverflow.com/users/145989/ondra-zizka" title="ondra-zizka">ondra-zizka</a> pointed out it is as easy as doing a Put request to the correct URL tough the URL has changed under tomcat7 to /manager/text/deploy?path=&amp;update=</p> <p>&lt;context-do-deploy-to&gt; needs to start with a forward slash e.g: /deployMe</p> <p>-) you might need to set permissions for accessing manager app add this to TOMCAT_HOME/conf/tomcat-users.xml</p> <p>note: the tomcat doc warns you not to give the same user access to more than one role</p> <pre><code>&lt;role rolename="manager-gui"/&gt; &lt;role rolename="manager-script"/&gt; &lt;role rolename="manager-jmx"/&gt; &lt;user username="tomcat" password="s3cret" roles="manager-gui,manager-script,manager-jmx"/&gt; </code></pre> <p>-) sample code for deploying a web app to an apache tomcat</p> <pre><code>package deployment; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.auth.AuthScope; import org.apache.http.auth.UsernamePasswordCredentials; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.CredentialsProvider; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.entity.ContentType; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; public class DeployManager{ static CredentialsProvider credsProvider = new BasicCredentialsProvider();; public static void main(String args[]) throws ClientProtocolException, IOException{ /* * warning only ever AuthScope.ANY while debugging * with these settings the tomcat username and pw are added to EVERY request */ credsProvider.setCredentials(AuthScope.ANY,new UsernamePasswordCredentials("tomcat", "s3cret")); // deploy(); // undeploy(); } private static void deploy() throws ClientProtocolException, IOException { String url = "http://localhost:8080/manager/text/deploy?path=/deployMe&amp;update=true"; File file = new File ("deployMe.war") ; HttpPut req = new HttpPut(url) ; MultipartEntityBuilder meb = MultipartEntityBuilder.create(); meb.addTextBody("fileDescription", "war file to deploy"); //"application/octect-stream" meb.addBinaryBody("attachment", file, ContentType.APPLICATION_OCTET_STREAM, file.getName()); req.setEntity(meb.build()) ; String response = executeRequest (req, credsProvider); System.out.println("Response : "+response); } public static void undeploy() throws ClientProtocolException, IOException{ String url = "http://localhost:8080/manager/text/undeploy?path=/deployMe"; HttpGet req = new HttpGet(url) ; String response = executeRequest (req, credsProvider); System.out.println("Response : "+response); } private static String executeRequest(HttpRequestBase requestBase, CredentialsProvider credsProvider) throws ClientProtocolException, IOException { CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); InputStream responseStream = null; String res = null; HttpResponse response = client.execute(requestBase) ; HttpEntity responseEntity = response.getEntity() ; responseStream = responseEntity.getContent() ; BufferedReader br = new BufferedReader (new InputStreamReader (responseStream)) ; StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { sb.append(line); sb.append(System.getProperty("line.separator")); } br.close() ; res = sb.toString(); return res; } } </code></pre> <p>-) maven dependencies</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt; &lt;artifactId&gt;httpclient&lt;/artifactId&gt; &lt;version&gt;4.3&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt; &lt;artifactId&gt;httpclient&lt;/artifactId&gt; &lt;version&gt;4.3&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.httpcomponents&lt;/groupId&gt; &lt;artifactId&gt;httpmime&lt;/artifactId&gt; &lt;version&gt;4.3&lt;/version&gt; &lt;/dependency&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload