尝试通过Gradle和Jenkins在Tomcat 7服务器上部署Spring App时出现HTTP 401错误

时间:2022-09-13 21:51:14

I'm doing my best to make this up as I go, so feel free to point out any and all stupid things you see. I've installed Tomcat 7 (on a machine running OS X Mavericks) and changed the port from 8080 to 80, so I can just use http://localhost/app.

我正在尽我所能去做,所以你可以随意指出你看到的任何和所有愚蠢的事情。我安装了Tomcat 7(在运行OS X Mavericks的机器上)并将端口从8080更改为80,所以我可以使用http:// localhost / app。

Everything above functions properly if I simply drop my .war file in the /webapps directory. I then downloaded Jenkins and placed its .war file inside /webapps as well, allowing me to access the web interface at http://localhost/jenkins.

如果我只是将.war文件放在/ webapps目录中,那么上面的所有功能都能正常运行。然后我下载了Jenkins并将其.war文件放在/ webapps中,允许我访问http:// localhost / jenkins的web界面。

My plan was to use Jenkins to pull my repo from bitbucket, build it, and then deploy it to the Tomcat server. The cloning and building portions work flawlessly, but deploying is a different story...

我的计划是使用Jenkins从bitbucket中取出我的repo,构建它,然后将它部署到Tomcat服务器。克隆和构建部分完美无缺,但部署是一个不同的故事......

Here's the log from Jenkins:

这是詹金斯的日志:

:processResources
:classes
:war
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build

BUILD SUCCESSFUL

Total time: 14.437 secs
Build step 'Invoke Gradle script' changed build result to SUCCESS
Deploying /var/root/.jenkins/jobs/MyApp/workspace/build/libs/workspace.war to container Tomcat 7.x Remote
ERROR: Publisher hudson.plugins.deploy.DeployPublisher aborted due to exception
org.codehaus.cargo.container.ContainerException: Failed to redeploy [/var/root/.jenkins/jobs/MyApp/workspace/build/libs/workspace.war]
    at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:195)
    at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:64)
    at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:90)
    at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:77)
    at hudson.FilePath.act(FilePath.java:914)
    at hudson.FilePath.act(FilePath.java:887)
    at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:77)
    at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:47)
    at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:785)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:757)
    at hudson.model.Build$BuildExecution.post2(Build.java:183)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:706)
    at hudson.model.Run.execute(Run.java:1703)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:231)
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost/manager/text/list
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
    at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:504)
    at org.codehaus.cargo.container.tomcat.internal.TomcatManager.list(TomcatManager.java:622)
    at org.codehaus.cargo.container.tomcat.internal.TomcatManager.getStatus(TomcatManager.java:635)
    at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:176)
    ... 16 more
java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost/manager/text/list
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
    at org.codehaus.cargo.container.tomcat.internal.TomcatManager.invoke(TomcatManager.java:504)
    at org.codehaus.cargo.container.tomcat.internal.TomcatManager.list(TomcatManager.java:622)
    at org.codehaus.cargo.container.tomcat.internal.TomcatManager.getStatus(TomcatManager.java:635)
    at org.codehaus.cargo.container.tomcat.internal.AbstractTomcatManagerDeployer.redeploy(AbstractTomcatManagerDeployer.java:176)
    at hudson.plugins.deploy.CargoContainerAdapter.deploy(CargoContainerAdapter.java:64)
    at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:90)
    at hudson.plugins.deploy.CargoContainerAdapter$1.invoke(CargoContainerAdapter.java:77)
    at hudson.FilePath.act(FilePath.java:914)
    at hudson.FilePath.act(FilePath.java:887)
    at hudson.plugins.deploy.CargoContainerAdapter.redeploy(CargoContainerAdapter.java:77)
    at hudson.plugins.deploy.DeployPublisher.perform(DeployPublisher.java:47)
    at hudson.tasks.BuildStepMonitor$3.perform(BuildStepMonitor.java:45)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:785)
    at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:757)
    at hudson.model.Build$BuildExecution.post2(Build.java:183)
    at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:706)
    at hudson.model.Run.execute(Run.java:1703)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
    at hudson.model.ResourceController.execute(ResourceController.java:88)
    at hudson.model.Executor.run(Executor.java:231)
Finished: FAILURE

If I were to guess, I would say the issue lies within my tomcat-users.xml file. I have tried every combination and permutation of roles, users, etc. that were suggested elsewhere. Just for reference, here's what it looks like now:

如果我猜,我会说问题出在我的tomcat-users.xml文件中。我已经尝试了其他地方建议的角色,用户等的每种组合和排列。仅供参考,现在看来是这样的:

<?xml version='1.0' encoding='cp1252'?>
<tomcat-users>
  <role rolename="manager-script”/>
  <user username="tomcat" password="s3cret" roles="manager-script”/>
</tomcat-users>

Any help would be greatly appreciated. Most of the other questions refer to Maven plugins and such, but even sifting through those provided me with no real solutions.

任何帮助将不胜感激。大多数其他问题都是指Maven插件等,但即使筛选那些也没有给我提供真正的解决方案。

2 个解决方案

#1


0  

401 means "Unauthorized".
  1. Try to check your credentials.
  2. 尝试检查您的凭据。
  3. Last time when I deploy my app to Tomcat7 I use this link:

    上次当我将我的应用程序部署到Tomcat7时,我使用此链接:

    localhost/manager/text/html
    
  4. Can you deploy this app without jenkins only using gradle ?

    您是否可以仅使用gradle在没有jenkins的情况下部署此应用程序?

  5. Very simple (temporary) solution is (if you deploy app on the same machine) is to copy war in Tomcat ${catalina.home}/webapps directory. When war is copied Tomcat expand this to desired url. Then you need to restart is to be sure that all caches is clear.
  6. 非常简单(临时)的解决方案(如果你在同一台机器上部署应用程序)是在Tomcat $ {catalina.home} / webapps目录中复制war。当复制war时,Tomcat将其扩展为所需的url。然后你需要重新启动是为了确保所有缓存都清楚。

#2


0  

In my case, we simply had to update the Jenkins deploy plugin.

就我而言,我们只需要更新Jenkins部署插件。

#1


0  

401 means "Unauthorized".
  1. Try to check your credentials.
  2. 尝试检查您的凭据。
  3. Last time when I deploy my app to Tomcat7 I use this link:

    上次当我将我的应用程序部署到Tomcat7时,我使用此链接:

    localhost/manager/text/html
    
  4. Can you deploy this app without jenkins only using gradle ?

    您是否可以仅使用gradle在没有jenkins的情况下部署此应用程序?

  5. Very simple (temporary) solution is (if you deploy app on the same machine) is to copy war in Tomcat ${catalina.home}/webapps directory. When war is copied Tomcat expand this to desired url. Then you need to restart is to be sure that all caches is clear.
  6. 非常简单(临时)的解决方案(如果你在同一台机器上部署应用程序)是在Tomcat $ {catalina.home} / webapps目录中复制war。当复制war时,Tomcat将其扩展为所需的url。然后你需要重新启动是为了确保所有缓存都清楚。

#2


0  

In my case, we simply had to update the Jenkins deploy plugin.

就我而言,我们只需要更新Jenkins部署插件。