2012-05-13 93 views
0

我遇到了項目部署的問題。這裏的錯誤我得到:Java - Jboss部署錯誤

01:08:26,780 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/domain-as]] (MSC service thread 1-7) Exception sending context initialized event to listener instance of class pt.ist.anacom.applicationserver.ApplicationServerInitListener: java.lang.NoClassDefFoundError: sun/security/x509/X509CertImpl 
at pt.ist.anacom.applicationserver.ApplicationServerInitListener.generateCert(ApplicationServerInitListener.java:86) [classes:] 
at pt.ist.anacom.applicationserver.ApplicationServerInitListener.contextInitialized(ApplicationServerInitListener.java:51) [classes:] 
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3368) [jbossweb-7.0.1.Final.jar:7.0.2.Final] 
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3821) [jbossweb-7.0.1.Final.jar:7.0.2.Final] 
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:70) [jboss-as-web-7.0.2.Final.jar:7.0.2.Final] 
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1824) 
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1759) 
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [:1.6.0_30] 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [:1.6.0_30] 
at java.lang.Thread.run(Unknown Source) [:1.6.0_30] 
Caused by: java.lang.ClassNotFoundException: sun.security.x509.X509CertImpl from [Module "deployment.domain-as.war:main" from Service Module Loader] 
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:191) 
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:361) 
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:333) 
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:310) 
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:103) 
... 10 more 

這發生了,當我添加了一個新功能,我的代碼在我稱之爲另一個類的函數生成的安全證書。這是撥打電話的功能的代碼:

public static void generateCert(String name, KeyPair key, int days, String algorithm) throws GeneralSecurityException, IOException{ 

    System.out.println("Starting to generate certificate"); 
    X509Certificate cert = CertificationAuthority.generateCertificate(name, key, days, algorithm); 
    //return cert; 
} 

它會打印,但會發生錯誤。生成認證是在另一個類(CertificationAuthority類),並具有下面的代碼:

public static X509Certificate generateCertificate(String dn, KeyPair pair, int days, String algorithm) 
     throws GeneralSecurityException, IOException 
     { 

    PrivateKey privkey = pair.getPrivate(); 
    X509CertInfo info = new X509CertInfo(); 

    //caso haja tempo, tratar isto com long + long 
    Date from = new Date(); 
    Date to = new Date(from.getTime() + days * 864000001); 
    CertificateValidity interval = new CertificateValidity(from, to); 
    BigInteger sn = new BigInteger(64, new SecureRandom()); 
    X500Name owner = new X500Name(dn); 

    info.set(X509CertInfo.VALIDITY, interval); 
    info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(sn)); 
    info.set(X509CertInfo.SUBJECT, new CertificateSubjectName(owner)); 
    info.set(X509CertInfo.ISSUER, new CertificateIssuerName(owner)); 
    info.set(X509CertInfo.KEY, new CertificateX509Key(pair.getPublic())); 
    info.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3)); 
    AlgorithmId algo = new AlgorithmId(AlgorithmId.md5WithRSAEncryption_oid); 
    info.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algo)); 

    // Sign the cert to identify the algorithm that's used. 
    X509CertImpl cert = new X509CertImpl(info); 
    cert.sign(privkey, algorithm); 

    // Update the algorithm, and resign. 
    algo = (AlgorithmId)cert.get(X509CertImpl.SIG_ALG); 
    info.set(CertificateAlgorithmId.NAME + "." + CertificateAlgorithmId.ALGORITHM, algo); 
    cert = new X509CertImpl(info); 
    cert.sign(privkey, algorithm); 

    certificates.add(cert); 

    return cert; 
     } 

我不明白爲什麼我收到錯誤。我試圖測試generateCertificate方法的功能,但我無法做到這一點,因爲這個錯誤。

任何人都知道發生了什麼?

+0

你錯過了一個類,看到這個錯誤'sun/security/x509/X509CertImpl' – ant

+0

我使用eclipse和jboss插件來開發和部署。 –

+0

'sun/security/x509/X509CertImpl'應該在rt.jar中。您是使用Sun JVM還是其他一些實現?如果它不是Sun的JVM,那麼Sun安全配置可能會泄漏到非Sun環境中。 –

回答

2

JBoss隔離Sun類。看看sun.jdk模塊,您需要添加sun/security/x509作爲導出,或創建您自己的模塊。

+1

我必須將添加到jboss目錄中/ modules/sun/jdk/main中的module.xml文件中。 –