代码如下,我直接用TAMCAT配置server.xml,是可以成功的。用代码就不行了,求达人解决。谢谢。
public void startTomcat() throws Exception {
Engine engine = null;
// Set the home directory
System.setProperty("catalina.home", getPath()); // Create an embedded server
embedded = new Embedded();
// print all log statements to standard error
// embedded.setDebug(0); // Create an engine
engine = embedded.createEngine();
engine.setDefaultHost("localhost"); // 创建虚拟主机
host = embedded.createHost("localhost", path);
engine.addChild(host); // 创建根应
Context rootContext = embedded.createContext("", path + dirchar + Constants.WEB_ROOT);
host.addChild(rootContext); // Install the assembled container hierarchy
embedded.addEngine(engine); // Assemble and install a default HTTP connector
Connector connector = null;
InetAddress address = null;
try {

connector = new Connector();
String ipaddress = "" + SystemEnv.getLocalHostAddress();
if(Config.getBoolean("usehttps")){
IntrospectionUtils.setProperty(connector, "scheme","https");
IntrospectionUtils.setProperty(connector, "secure","true");
IntrospectionUtils.setProperty(connector, "maxThreads","150");
IntrospectionUtils.setProperty(connector, "protocol","HTTP/1.1");
IntrospectionUtils.setProperty(connector, "clientAuth","false");
IntrospectionUtils.setProperty(connector, "SSLEnabled","true");
IntrospectionUtils.setProperty(connector, "sslProtocol","TLS");
IntrospectionUtils.setProperty(connector, "keystoreFile","c:\\server.jks");
IntrospectionUtils.setProperty(connector, "keystorePass","password");
}else{
connector.setSecure(false);
connector.setEnableLookups(false);
}
address = InetAddress.getLocalHost();
if (address != null) {
IntrospectionUtils.setProperty(connector, "address", ipaddress);
}
IntrospectionUtils.setProperty(connector, "port", "" + Constants.SERVER_PORT); } catch (Exception ex) {
ex.printStackTrace();
} embedded.addConnector(connector);
// Start the embedded server
embedded.start();
}

解决方案 »

  1.   

    附错误提示:2010-5-27 9:37:16 org.apache.coyote.http11.Http11AprProtocol init
    严重: Error initializing endpoint
    java.lang.Exception: Invalid Server SSL Protocol
    at org.apache.tomcat.jni.SSLContext.make(Native Method)
    at org.apache.tomcat.util.net.AprEndpoint.init(AprEndpoint.java:680)
    at org.apache.coyote.http11.Http11AprProtocol.init(Http11AprProtocol.java:121)
    at org.apache.catalina.connector.Connector.initialize(Connector.java:1059)
    at org.apache.catalina.startup.Embedded.start(Embedded.java:830)
    at cn.com.voltronicpower.main.EmbeddedTomcat.startTomcat(EmbeddedTomcat.java:154)
    at cn.com.voltronicpower.main.TomcatWrapper.runService(TomcatWrapper.java:112)
    at cn.com.voltronicpower.main.TomcatWrapper.main(TomcatWrapper.java:64)
      

  2.   

    加上: connector.setProtocol( "SSL");if(Config.getBoolean("usehttps")){
                    IntrospectionUtils.setProperty(connector, "scheme","https");
                    IntrospectionUtils.setProperty(connector, "secure","true");
                    IntrospectionUtils.setProperty(connector, "maxThreads","150");
                    IntrospectionUtils.setProperty(connector, "protocol","HTTP/1.1");
                    IntrospectionUtils.setProperty(connector, "clientAuth","false");
                    IntrospectionUtils.setProperty(connector, "SSLEnabled","true");
                    IntrospectionUtils.setProperty(connector, "sslProtocol","TLS");
                    IntrospectionUtils.setProperty(connector, "keystoreFile","c:\\server.jks");
                    IntrospectionUtils.setProperty(connector, "keystorePass","password");
           
                    connector.setProtocol( "SSL");
                }