【问题标题】:Why won't eclipse app instance run in https为什么 Eclipse 应用程序实例不能在 https 中运行
【发布时间】:2026-01-21 16:05:01
【问题描述】:

我正在维护一个之前在 Eclipse Helios 中开发的 servlet 应用程序。我有 servlet 实例 war 文件,它在 Windows 上的 Tomcat 7.0 中运行良好,我在 SoapUI 中收到了正确的 Web 响应。它使用 SSL 加密和 SoapUI 状态下的 url 运行;

https://localhost:8443/ProjectName/etc/etc

但是在将原始代码从 SVN 检索到 Eclipse Helios 后,我可以通过导入的 Tomcat 开始正常运行,但它似乎没有开始在 Eclipse Helios 中使用 SSL 并且 Eclipse 选项卡中的 URL 状态;

http://localhost:8000/ProjectName/etc/etc

因此,当我尝试在 SoapUI 中运行 Web 请求时,它的反应就像 servlet 实例没有运行一样。我做错了什么?

【问题讨论】:

    标签: eclipse tomcat servlets ssl


    【解决方案1】:
        This solution is supplied for MAC, can follow the same strategy for windows as well.
    
        Step 1) Generate the certificate with java keytool utility by navigating to bin folder of java installation directory
    
        LM-MAA-22004958:etc rkala$ cd /Applications/corona-java-1.1.0/jdk-7u45-macosx-x64/Contents/Home/bin 
        LM-MAA-22004958:bin rkala$ keytool -genkey -alias myappcert -keyalg RSA -keystore myapp.keystore
        Enter keystore password:  
        Re-enter new password: 
        What is your first and last name?
          [Unknown]:  localhost.xyz.com
        What is the name of your organizational unit?
          [Unknown]:  my
        What is the name of your organization?
          [Unknown]:  my
        What is the name of your City or Locality?
          [Unknown]:  my
        What is the name of your State or Province?
          [Unknown]:  my
        What is the two-letter country code for this unit?
          [Unknown]:  my
        Is CN=localhost.xyz.com, OU=my, O=my, L=my, ST=my, C=my correct?
          [no]:  yes
    
        Enter key password for <myappcert>
            (RETURN if same as keystore password):  
    
        Step 2): Copy the generated myapp.keystore file to tomcat /conf directory
    
        LM-MAA-22004958:bin rkala$ mv myapp.keystore /Users/rkala/Downloads/apache-tomcat-7.0.93/conf 
        LM-MAA-22004958:bin rkala$ cd /Users/rkala/Downloads/apache-tomcat-7.0.93/bin
        LM-MAA-22004958:bin rkala$ ./startup.sh 
        Using CATALINA_BASE:   /Users/rkala/Downloads/apache-tomcat-7.0.93
        Using CATALINA_HOME:   /Users/rkala/Downloads/apache-tomcat-7.0.93
        Using CATALINA_TMPDIR: /Users/rkala/Downloads/apache-tomcat-7.0.93/temp
        Using JRE_HOME:        /Applications/corona-java-1.1.0/jdk-7u45-macosx-x64/Contents/Home
        Using CLASSPATH:       /Users/rkala/Downloads/apache-tomcat-7.0.93/bin/bootstrap.jar:/Users/rkala/Downloads/apache-tomcat-7.0.93/bin/tomcat-juli.jar
    
        Hit the browser with url https://localhost:8443 and you are good to go
    
        Step 3) Modify both server.xml with the same config provided below
    
        1.Tomcat server.xml -> Path: /Users/rkala/Downloads/apache-tomcat-7.0.93/conf/server.xml
        2.Under eclipse workspace server folder,modify the server.xml here as well
    
        Add the tls config below this section of commented code. I used port 8443 for https
    
         <!-- A "Connector" represents an endpoint by which requests are received
                 and responses are returned. Documentation at :
                 Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
                 Java AJP  Connector: /docs/config/ajp.html
                 APR (HTTP/AJP) Connector: /docs/apr.html
                 Define a non-SSL HTTP/1.1 Connector on port 8080
            -->
           <Connector
                SSLEnabled="true"
                clientAuth="false"
                keyAlias="myappcert"
                keystoreFile="/Users/rkala/Downloads/apache-tomcat-7.0.93/conf/myapp.keystore"
                keystorePass="password which you supplied while generating the certificate using keytool"
                maxThreads="200"
                port="8443"
                scheme="https"
                secure="true"
                sslProtocol="TLS"
         /> 
    
    
        Step 4) Catalina policy permission:
    
        Modify the catalina.policy file located in /conf folder of tomcat installation directory
    
        Search for below keyword(grant codeBase "file:${catalina.home}/bin/tomcat-juli.jar) and replace all the code with single line as mentioned below
    
        grant codeBase "file:${catalina.home}/bin/tomcat-juli.jar" {
              permission java.security.AllPermission;
        };
    
    Step 5) Modify the eclipse.ini file and add the below entries and then restart the eclipse.
    
    -vmargs
    -Djavax.net.ssl.trustStore=/Users/rkala/Downloads/apache-tomcat-7.0.93/conf/myapp.keystore
    -Djavax.net.ssl.trustStorePassword=password which you supplied at step 1
    
        Now you should be able to launch the application and will be able to access it via https
    

    【讨论】:

      【解决方案2】:

      我假设您指的是从 Eclipse 中运行 tomcat。默认情况下,由 Eclipse 管理的服务器实例(它们自己的项目)根据选择的本地安装的运行时版本,每个都有自己单独的 tomcat 配置文件(server.xml、context.xml、tomcat-users.xml 等)副本在创作时。因此,如果在该配置中未启用 SSL 连接器,则它不会启动。这允许您同时运行多个 tomcat 实例,每个实例都有不同的配置。

      要编辑 Eclipse 托管 tomcat 实例的配置,请在项目资源管理器中查找 Servers,打开您的实例并编辑 server.xml 以取消注释 SSL 连接器标签看起来像:

      <Connector SSLEnabled="true" clientAuth="false" maxThreads="150" port="8443" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLS"/>
      

      如果您还没有为 tomcat 创建密钥库,您可能还需要 - 请参阅文档了解更多信息:http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html

      从 Eclipse 中重新启动 tomcat 并尝试安全地址。希望对您有所帮助。

      【讨论】:

      • 感谢您的回复 Tombola82。是的,从 Eclipse 中运行 Tomcat。另外,是的,这就是我如此困惑的原因。您会看到我实际上是从 PC 转移到笔记本电脑,并且在 PC 上一切正常。我已经在 Tomcat\conf 和 Eclipse 中生成的 server.xml 文件中的 server.xml 文件中设置了“连接器”标签。我还有一个密钥库设置和导入的 SSL 证书。该实例在 Eclipse 中似乎可以正常启动,但 SoapUI 的反应就像它没有运行一样。
      • 您能否浏览到在 SoapUI 之外的安全地址上运行在 eclipse-tomcat 实例上的它,或者这也会失败?
      • 当我在 eclipse-tomcat 中启动实例并尝试转到 IE 中的 URL 时,我最初被警告证书错误并接受风险,但之后在 soapUI 中仍然给出相同的输出
      • 听起来像是 SoapUI SSL 信任问题 - 您可以在我认为的设置和首选项中配置密钥库/信任库等;也许先查看 SoapUI 响应日志以确认发生了什么。
      • 我已经解决了这个问题。感谢您的输入。我在 Eclipse 中删除了服务器并再次添加它,一切似乎都很好。
      【解决方案3】:

      我在 Eclipse 中删除了服务器并再次添加它,现在一切似乎都在工作。感谢所有查看和输入的人。

      【讨论】: