File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes cannot find javax/crypto/spec/SecretKeySpec class inTomcat 6 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "cannot find javax/crypto/spec/SecretKeySpec class inTomcat 6" Watch "cannot find javax/crypto/spec/SecretKeySpec class inTomcat 6" New topic
Author

cannot find javax/crypto/spec/SecretKeySpec class inTomcat 6

Chuck Dial
Greenhorn

Joined: Nov 06, 2008
Posts: 10
Hello,

I have a simple module to log into MS SQL. It works when I run it as a standalone program. When I add it to Tomcat 6 as servlet code I get:

java.lang.NoClassDefFoundError: javax/crypto/spec/SecretKeySpec

This class is in the jce.jar. I'm not sure what I'm doing wrong. The code is included.

Thanks,

Chuck

package com.example.web;


import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.*;
import java.*;
import java.sql.*;
import javax.crypto.spec.SecretKeySpec;

public class SoitLogon extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException{

response.setContentType("text/html");
PrintWriter out = response.getWriter();




DB db = new DB();
String ret = db.dbConnect(
"jdbc:sqlserver://localhost:1433","sa","931900");

out.println("return value = " + ret);

}

class DB
{
public DB() {}

public String dbConnect(String db_connect_string,
String db_userid, String db_password)
{
try
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection conn = DriverManager.getConnection(
db_connect_string, db_userid, db_password);
return "connected";

}
catch (Exception e)
{
e.printStackTrace();
return e.getMessage();

}
}
}
}



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Where did you put jce,jar?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Chuck Dial
Greenhorn

Joined: Nov 06, 2008
Posts: 10
It is under Tomcat6.0/lib.

I also extracted the jce.jar file. It is under Tomcat6.0/lib/javax/crypto/spec/SecretKeySpec.class.

I also put the class under the classes directory of the servlet where my code class resides.

I thought putting it under the Tomcat6.0/lib directory would have worked.

Chuck
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Chuck Dial wrote:It is under Tomcat6.0/lib

That will do it.

All the other stuff you did will not work. Undo it.

Are you sure that the class file is in the jar file?
Chuck Dial
Greenhorn

Joined: Nov 06, 2008
Posts: 10
Bear,

I didn't say thanks before, so thanks for helping. I did a jar -tf jce.jar and the class showed up in the list as javax/crypto/spec/SecretKeySpec.class.

I also did the extraction earlier to verify the class was there.

I'm at a loss on what to do next. I've been spinning my wheels for 2 days.

Thanks,

Chuck
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

I've never heard of Tomcat not finding a class in a properly deployed jar.

Move the jar to your app's WEB-INF/lib, just as a test.

Also, post the entire stack trace. Use code tags to preserve formatting.
Chuck Dial
Greenhorn

Joined: Nov 06, 2008
Posts: 10
With code tag. Never used them before.

New, shorter, code. Still get same SecretKeySpec error. Not sure why I get this error. I included the code and the trace that appeared on the IE screen.



Trace:

javax.servlet.ServletException: Servlet execution threw an exception


root cause

java.lang.NoClassDefFoundError: javax/crypto/spec/SecretKeySpec
com.sun.net.ssl.internal.ssl.CipherSuite$BulkCipher.isAvailable(CipherSuite.java:384)
com.sun.net.ssl.internal.ssl.CipherSuite$BulkCipher.isAvailable(CipherSuite.java:367)
com.sun.net.ssl.internal.ssl.CipherSuite.isAvailable(CipherSuite.java:143)
com.sun.net.ssl.internal.ssl.CipherSuiteList.buildAvailableCache(CipherSuiteList.java:210)
com.sun.net.ssl.internal.ssl.CipherSuiteList.getDefault(CipherSuiteList.java:233)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.init(SSLSocketImpl.java:508)
com.sun.net.ssl.internal.ssl.SSLSocketImpl.<init>(SSLSocketImpl.java:479)
com.sun.net.ssl.internal.ssl.SSLSocketFactoryImpl.createSocket(SSLSocketFactoryImpl.java:92)
com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1368)
com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1058)
com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:833)
com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:716)
com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:841)
java.sql.DriverManager.getConnection(DriverManager.java:582)
java.sql.DriverManager.getConnection(DriverManager.java:207)
com.example.web.SoitLogon.doPost(SoitLogon.java:21)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Chuck
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.
Chuck Dial
Greenhorn

Joined: Nov 06, 2008
Posts: 10
Bear,

I added code tags to my prior post.

Chuck
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

Did you try moving it to WEB-INF/lib to see what happens?
Chuck Dial
Greenhorn

Joined: Nov 06, 2008
Posts: 10
Yes,

C:Apache Software Foundation/Tomcat6.0/webapps/SoitProcess/WEB-INF/lib/jce.jar

I had to create the lib directory. I didn't mention it but I'm running under Vista if that makes a difference.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

It shouldn't make a difference. And at this point, I've got nothing. I've never heard of Tomcat not finding a valid class in a jar placed in one of the proper locations.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
Try removing the file jce.jar from Tomcat altogether. Starting with Java 5, JCE is part of the core JRE, and does not need to be added separately.


Ping & DNS - updated with new look and Ping home screen widget
Chuck Dial
Greenhorn

Joined: Nov 06, 2008
Posts: 10
I removed Tomcat 6 and loaded Tomcat 5.5.28. I can now access the database with the same code. I think there is either an issue with the way I loaded Tomcat 6 or there may be a bug in Tomcat 6. Either way, I can move forward. Thanks for your help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot find javax/crypto/spec/SecretKeySpec class inTomcat 6
 
Similar Threads
Mysql JDBC Cant load.....
Trying to grab the last record.
Viewing data from database into an xls format not working
Problems regarding MS JDBC Driver and JTDS-JDBC Connectivity for MS SQL Server 2000
SQL Server 2000 Database Connection using JDBC