JavaWeb java.lang.NoClassDefFoundError: sun/security/ssl/HelloExtension

huangapple go评论100阅读模式
英文:

JavaWeb java.lang.NoClassDefFoundError: sun/security/ssl/HelloExtension

问题

我在尝试使用Glassfish 5.0运行JavaWeb项目时遇到了错误。每次它试图从我的SQL数据库中获取数据时,都会出现以下错误。 <br>
StandardWrapperValve[ListadoPersonas]: Servlet.service() for servlet ListadoPersonas threw exception
java.lang.NoClassDefFoundError: sun/security/ssl/HelloExtension

以下是调用从数据库获取数据的函数的servlet ListadoEstadosCiviles

GestorPersonas g = new GestorPersonas();
ArrayList&lt;EstadoCivil&gt; lista = g.obtenerEstadosCiviles();
for (EstadoCivil estadoCivil : lista) {
    out.println("&lt;tr&gt;&lt;td&gt;" + estadoCivil.getId() + "&lt;/td&gt;&lt;td&gt;" + estadoCivil.getNombre() + "&lt;/td&gt;&lt;/tr&gt;");
}

以下是GestorPersonas() 构造函数:

public GestorPersonas() {
    try {
        Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(GestorPersonas.class.getName()).log(Level.SEVERE, null, ex);
    }
}

以下是obtenerEstadosCiviles() 方法:

public ArrayList&lt;EstadoCivil&gt; obtenerEstadosCiviles() {
    ArrayList&lt;EstadoCivil&gt; lista = new ArrayList&lt;&gt;();
    
    try {
        Connection conn = DriverManager.getConnection(CONN,USER,PASS);
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery("select * from EstadosCiviles");
        // 如果select语句只返回一行记录,使用if而不是while
        while (rs.next()) {
            int id = rs.getInt("id");
            String nombre = rs.getString("nombre");
            EstadoCivil ec = new EstadoCivil(id, nombre);
            lista.add(ec);
        }
        
        rs.close();
        st.close();
        conn.close();
    } catch (SQLException ex) {
        Logger.getLogger(GestorPersonas.class.getName()).log(Level.SEVERE, null, ex);
    }
    
    return lista;
}

我没有问题将我的Java应用程序连接到SQL,我认为问题出在Glassfish上,但我无法弄清楚为什么它不起作用。

这是调用obtenerEstadosCiviles()函数的servlet,我期望表中充满数据。

期望效果:
JavaWeb java.lang.NoClassDefFoundError: sun/security/ssl/HelloExtension

更新

我刚刚检查了我的插件,发现Java Web和EE已经激活,但"Active"标志似乎没有激活。这可能是问题的一部分吗?
JavaWeb java.lang.NoClassDefFoundError: sun/security/ssl/HelloExtension

英文:

I'm getting an error when trying to use a JavaWeb project using Glassfish 5.0. Everytime it tries to bring data from my SQL Database it gives me this error. <br>
StandardWrapperValve[ListadoPersonas]: Servlet.service() for servlet ListadoPersonas threw exception
java.lang.NoClassDefFoundError: sun/security/ssl/HelloExtension

Here is the servlet ListadoEstadosCiviles where I call the function which brings the data back from my database

GestorPersonas g = new GestorPersonas();
ArrayList&lt;EstadoCivil&gt; lista = g.obtenerEstadosCiviles();
for (EstadoCivil estadoCivil : lista) {
    out.println(&quot;&lt;tr&gt;&lt;td&gt;&quot; + estadoCivil.getId() + &quot;&lt;/td&gt;&lt;td&gt;&quot; + estadoCivil.getNombre() + &quot;&lt;/td&gt;&lt;/tr&gt;&quot;);
}

Here is GestorPersonas() constructor:

 public GestorPersonas() {
        try {
            Class.forName(&quot;com.microsoft.sqlserver.jdbc.SQLServerDriver&quot;);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(GestorPersonas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

Here is obtenerEstadosCiviles() method

public ArrayList&lt;EstadoCivil&gt; obtenerEstadosCiviles() {
    ArrayList&lt;EstadoCivil&gt; lista = new ArrayList&lt;&gt;();
    
    try {
        Connection conn = DriverManager.getConnection(CONN,USER,PASS);
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(&quot;select * from EstadosCiviles&quot;);
        // Si el select devuelve una &#250;nica fila, en lugar de while, se usa un if
        while (rs.next()) {
            int id = rs.getInt(&quot;id&quot;);
            String nombre = rs.getString(&quot;nombre&quot;);
            EstadoCivil ec = new EstadoCivil(id, nombre);
            lista.add(ec);
        }
        
        rs.close();
        st.close();
        conn.close();
    } catch (SQLException ex) {
        Logger.getLogger(GestorPersonas.class.getName()).log(Level.SEVERE, null, ex);
    }
    
    return lista;
}

I have no problem connecting my java application to sql, I think the problem is with glassfish but i cant figure out why it is not working

This is the servlet that is calling obtenerEstadosCiviles() function, I expect that table full with data

What I expect:
JavaWeb java.lang.NoClassDefFoundError: sun/security/ssl/HelloExtension

UPDATE

I've just checked my plugins and it appears that Java Web and EE it´s activated but the "Active" symbol doesnt appears active. Could this be part of the problem?
JavaWeb java.lang.NoClassDefFoundError: sun/security/ssl/HelloExtension

答案1

得分: 6

基本上是相同的问题,最终通过这个解决方案解决了。

在你的glassfish文件夹中,进入glassfish5/glassfish/modules/endorsed/目录,用WinRAR或你偏好的解压工具打开grizzly-npn-bootstrap.jar文件。

删除sun文件夹,然后尝试重新运行你的程序。

英文:

Had basically the same problem, eventually solved it with this solution here.

In your glassfish folder go to glassfish5/glassfish/modules/endorsed/ and open the grizzly-npn-bootstrap.jar file with winrar or your preferred unzipper.

Delete the sun folder and try running your program again.

huangapple
  • 本文由 发表于 2020年9月30日 23:13:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/64140616.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定