Java 从 Netbeans 启动 Tomcat 失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22225764/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 14:25:58  来源:igfitidea点击:

Starting of Tomcat failed from Netbeans

javaapachetomcatnetbeans

提问by liquide

I have problem with starting Apache Tomcat 6 from Netbeans IDE 7.4 (on 7.3 version I had the same troubles. Other people mentioned that this problem exist also in other versions, like 8.0 etc).

我在从 Netbeans IDE 7.4 启动 Apache Tomcat 6 时遇到问题(在 7.3 版本上我遇到了同样的问题。其他人提到这个问题也存在于其他版本中,例如 8.0 等)。

What did I do:

我做了什么:

  • remove installed Tomcat 7 (without removing it, I had the same difficulties)
  • add new server, downloaded from Apache Tomcat website (version apache-tomcat-6.0.39, with other version I had the same problems)
  • my server location: D:\apache-tomcat-netbeans
  • system variable CATALINA_HOME: D:\apache-tomcat-netbeans
  • system variable JAVA HOME: C:\Program Files\Java\jdk1.7.0_51\
  • tomcat user: I let netbeans creating new user, called tomcat with password tomcat. When I open {tomcat}\conf\tomcat-users.xml file after adding server, there is info about my user:

    < user password="tomcat" roles="manager,admin" username="tomcat"/ >

  • 删除已安装的 Tomcat 7(不删除它,我遇到了同样的困难)
  • 添加新服务器,从 Apache Tomcat 网站下载(版本 apache-tomcat-6.0.39,其他版本我也有同样的问题)
  • 我的服务器位置:D:\apache-tomcat-netbeans
  • 系统变量 CATALINA_HOME: D:\apache-tomcat-netbeans
  • 系统变量JAVA HOME:C:\Program Files\Java\jdk1.7.0_51\
  • tomcat 用户:我让 netbeans 创建新用户,名为 tomcat,密码为 tomcat。添加服务器后打开 {tomcat}\conf\tomcat-users.xml 文件时,有关于我的用户的信息:

    <user password="tomcat" roles="manager,admin" username="tomcat"/ >

When I now click "start", I got "Starting of Tomcat failed".

当我现在单击“开始”时,我得到“ Tomcat 启动失败”。

My suspicions:

我的怀疑:

  • I'm working on Windows 7 as administrator, so I think this is not a problem with privileges to files.
  • Disabling proxy didn't helps.
  • Logs: There is only one log file created: localhost.2014-03-06.log and it is totally empty.
  • Starting Netbeans "as administrator" didn't helps.
  • From command line everything is all right, I have no problems with starting in normal or debug mode (catalina.bat jpda startor startup.bat)
  • 我正在以管理员身份在 Windows 7 上工作,所以我认为这不是文件权限的问题。
  • 禁用代理没有帮助。
  • 日志:只创建了一个日志文件:localhost.2014-03-06.log,它完全是空的。
  • “以管理员身份”启动 Netbeans 没有帮助。
  • 从命令行一切正常,我在正常或调试模式下启动没有问题(catalina.bat jpda startstartup.bat

采纳答案by Sudeepta

It affects at least NetBeans versions 7.4 through 8.0.2. It was first reported from version 8.0 and fixed in NetBeans 8.1. It would have had the problem for any tomcat version (confirmed for versions 7.0.56 through 8.0.28).

它至少会影响 NetBeans 版本 7.4 到 8.0.2。它首先从 8.0 版报告并在 NetBeans 8.1 中修复。对于任何 tomcat 版本(7.0.56 到 8.0.28 版本已确认),它都会有问题。

Specifics are described as Netbeans bug #248182.

具体描述为Netbeans bug #248182

This problem is also related to postings mentioning the following error output:

此问题也与提及以下错误输出的帖子有关:

'127.0.0.1*' is not recognized as an internal or external command, operable program or batch file.

'127.0.0.1*' 不是内部或外部命令,也不是可运行的程序或批处理文件。

For a tomcat installed from the zip file, I fixed it by changing the catalina.batfile in the tomcat bindirectory.

对于从 zip 文件安装的 tomcat,我通过更改catalina.battomcatbin目录中的文件来修复它。

Find the bellow configuration in your catalina.batfile.

在您的catalina.bat文件中找到波纹管配置。

:noJuliConfig
set "JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%"

:noJuliManager
set "JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER%"

And change it as in below by removing the double quotes:

并通过删除双引号将其更改如下:

:noJuliConfig
set JAVA_OPTS=%JAVA_OPTS% %LOGGING_CONFIG%

:noJuliManager
set JAVA_OPTS=%JAVA_OPTS% %LOGGING_MANAGER%

Now save your changes, and start your tomcat from within NetBeans.

现在保存您的更改,并从 NetBeans 中启动您的 tomcat。

回答by Sampath T

For NetBeans to be able to interact with tomcat, it needs the user as setup in netbeans to be properly configured in the tomcat-users.xmlfile. NetBeans can do so automatically.

为了让 NetBeans 能够与 tomcat 交互,它需要在tomcat-users.xml文件中正确配置 netbeans 中的设置用户。NetBeans 可以自动执行此操作。

That is, within the tomcat-users.xml, which you can find in ${CATALINA_HOME}/conf, or ${CATALINA_BASE}/conf,

也就是说,在 中tomcat-users.xml,您可以在${CATALINA_HOME}/conf、 或 中找到${CATALINA_BASE}/conf

  1. make sure that the user (as chosen in netbeans) is added the script-managerrole
  1. 确保为用户(在 netbeans 中选择)添加了script-manager角色

Example, change

例子,改变

<user password="tomcat" roles="manager,admin" username="tomcat"/>

To

<user password="tomcat" roles="manager-script,manager,admin" username="tomcat"/>
  1. make sure that the manager-scriptrole is declared
  1. 确保manager-script已声明角色

Add

添加

<role rolename="manager-script"/>

Actually the netbeans online-help incorrectly states:

实际上,netbeans 在线帮助错误地指出:

Username - Specifies the user name that the IDE uses to log into the server's manager application. The user must be associated with the manager role. The first time the IDE started the Tomcat Web Server, such as through the Start/Stop menu action or by executing a web component from the IDE, the IDE adds an admin user with a randomly-generated password to the tomcat-base-path/conf/tomcat-users.xmlfile. (Right-click the Tomcat Web server instance node in the Services window and select Properties. In the Properties dialog box, the Base Directory property points to the base-dirdirectory.) The admin user entry in the tomcat-users.xmlfile looks similar to the following: <user username="idea" password="woiehh" roles="manager"/>

用户名 - 指定 IDE 用于登录服务器管理器应用程序的用户名。用户必须与经理角色相关联。IDE 首次启动 Tomcat Web 服务器时,例如通过“开始/停止”菜单操作或从 IDE 执行 Web 组件,IDE 会向tomcat-base-path/conf/tomcat-users.xml文件中添加一个带有随机生成密码的管理员用户。(在“服务”窗口中右键单击 Tomcat Web 服务器实例节点并选择“属性”。在“属性”对话框中,“基本目录”属性指向该base-dir目录。)tomcat-users.xml文件中的 admin 用户条目类似于以下内容:<user username="idea" password="woiehh" roles="manager"/>

The role should be manager-script, and not manager.

角色应该是manager-script,而不是manager

For a more complete tomcat-users.xmlfile:

更完整的tomcat-users.xml文件:

<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  <role rolename="manager-script"/>
  <role rolename="manager-gui"/>
  <user password="tomcat" roles="manager-script" username="tomcat"/>
  <user password="pass" roles="manager-gui" username="me"/>
</tomcat-users>

There is another nice posting on why am I getting the deployment error?

还有另一个很好的帖子关于为什么我会收到部署错误?

回答by YoYo

This affects:

这会影响:

  • All versions of Tomcat starting from 8.5.3 onwards.
  • All versions of Netbeans up to 8.1 (It is fixed in Netbeans 8.2).
  • 从 8.5.3 开始的所有 Tomcat 版本。
  • Netbeans 最高 8.1 的所有版本(在 Netbeans 8.2 中已修复)。

This is because Netbeans does not 'see' that tomcat is started, although it started just fine.

这是因为 Netbeans 没有“看到”tomcat 已启动,尽管它启动得很好。

I have filed Bug #262749 with NetBeans.

我已经向NetBeans提交了Bug #262749

Workaround

解决方法

In the server.xmlfile, in the Connectorelement for HTTP/1.1, add the following attribute: server="Apache-Coyote/1.1".

server.xml文件中的ConnectorHTTP/1.1 元素中,添加以下属性:server="Apache-Coyote/1.1".

Example:

例子:

<Connector
  connectionTimeout="20000"
  port="8080"
  protocol="HTTP/1.1"
  redirectPort="8443"
  server="Apache-Coyote/1.1"
/>

Cause

原因

The reason for that is that prior to 8.5.3, the default was to set the server header as Apache-Coyote/1.1, while since 8.5.3 this default has now been changed to blank. Apparently Netbeans checks on this header.

原因是在 8.5.3 之前,默认是将服务器标头设置为Apache-Coyote/1.1,而从 8.5.3 开始,此默认值现在已更改为空白。显然 Netbeans 会检查此标头。

Maybe in the future we can expect a fix in netbeans addressing this issue.

也许将来我们可以期待在 netbeans 中解决这个问题。

I was able to trace it back to a change in documentation.

我能够将其追溯到文档中的更改。

Tomcat 8.5:

雄猫 8.5

"Overrides the Server header for the http response. If set, the value for this attribute overrides any Server header set by a web application. If not set, any value specified by the application is used. If the application does not specify a value then no Server header is set."

"覆盖 http 响应的服务器标头。如果设置,此属性的值将覆盖由 Web 应用程序设置的任何服务器标头。如果未设置,则使用应用程序指定的任何值。如果应用程序未指定值,则未设置服务器标头。”

Tomcat 8.0:

雄猫 8.0

"Overrides the Server header for the http response. If set, the value for this attribute overrides the Tomcat default and any Server header set by a web application. If not set, any value specified by the application is used. If the application does not specify a value then Apache-Coyote/1.1 is used. Unless you are paranoid, you won't need this feature."

"覆盖 http 响应的服务器标头。如果设置,此属性的值将覆盖 Tomcat 默认和 Web 应用程序设置的任何服务器标头。如果未设置,则使用应用程序指定的任何值。如果应用程序没有指定一个值,然后使用 Apache-Coyote/1.1。除非你是偏执狂,否则你不需要这个功能。”

That explains the need for explicitly adding the server attribute since version 8.5.3.

这解释了自 8.5.3 版以来需要显式添加服务器属性的原因。

回答by Yan Pak

Also, it is very likely, that problem with proxy settings.

此外,很可能是代理设置的问题。

Any who didn't overcome Tomact starting problrem, - try in NetBeans choose No Proxyin the Tools -> Options -> General tab.

任何没有克服 Tomact 启动问题的人, - 在 NetBeans 中尝试在工具 -> 选项 -> 常规选项卡中选择无代理

It helped me.

它帮助了我。

回答by lalo

I had the same problem but none of the answers above worked. The solution for me was to restore the Manager web applicationthat is bundled with Tomcat.

我遇到了同样的问题,但上面的答案都没有奏效。我的解决方案是恢复与 Tomcat 捆绑的Manager Web 应用程序

回答by Devology Ltd

None of the answers here solved my issue (as at February 2020), so I raised an issue at https://issues.apache.org/jira/browse/NETBEANS-3903and Netbeans fixed the issue!

这里的答案都没有解决我的问题(截至 2020 年 2 月),所以我在https://issues.apache.org/jira/browse/NETBEANS-3903提出了一个问题,Netbeans 解决了这个问题!

They're working on a pull request so the fix will be in a future .dmg installer soon, but in the meantime you can copy a file referenced in the bug and replace one in your netbeans modules folder.

他们正在处理拉取请求,因此修复程序很快就会在未来的 .dmg 安装程序中出现,但与此同时,您可以复制错误中引用的文件并替换您的 netbeans 模块文件夹中的文件。

Tip - if you right click on Applications > Netbeans and choose Show Package Contents Show Package Contentsthen you can find and replace the file org-netbeans-modules-tomcat5.jarthat they refer to in your Netbeans folder, e.g. within /Applications/NetBeans/Apache NetBeans 11.2.app/Contents/Resources/NetBeans/netbeans/enterprise/modules

提示 - 如果您右键单击 Applications > Netbeans 并选择 Show Package Contents,显示包裹内容那么您可以找到并替换它们在您的 Netbeans 文件夹中引用的文件org-netbeans-modules-tomcat5.jar,例如在 /Applications/NetBeans/Apache NetBeans 中11.2.app/Contents/Resources/NetBeans/netbeans/enterprise/modules