Ho installato un certificato autofirmato per testare una connessione js ssl - tuttavia, si rifiuta di localizzare il java trustStore. Ne ho salvate copie in/Java/jre6/lib/security oltre alla cartella in cui sono compilate le classi (im usando netbeans) e anche a/java/jre6/bin nessuna di queste sembra funzionare, perché quando eseguo il seguente - trustStore = null.java - path to trustStore - set property non funziona?
public class ShowTrustStore {
public static void main(String[] args) {
System.setProperty("javax.net.ssl.keyStore", "keystore.jks");
System.setProperty("javax.net.ssl.trustStrore", "cacerts.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
String trustStore = System.getProperty("javax.net.ssl.trustStore");
if (trustStore == null) {
System.out.println("javax.net.ssl.trustStore is not defined");
} else {
System.out.println("javax.net.ssl.trustStore = " + trustStore);
}
}
}
come impostare il percorso correttamente?
********** UPDATE ************ Utilizzando il metodo getFile() e ancora un po 'di dati di debug:
package ssltest;
public class Main {
public static void main(String[] args) {
// System.setProperty("javax.net.ssl.keyStore", "/keystore.jks");
// System.setProperty("javax.net.ssl.trustStrore", "/java.home/cacerts.jks");
// System.setProperty("javax.net.ssl.keyStorePassword", "changeit");
// System.setProperty("javax.net.ssl.trustStorePassword", "changeit");
try {
Main.class.getResource("trustStore.jks").getFile();
} catch (Exception e) {
e.printStackTrace();
}
String trustStore = System.getProperty("javax.net.ssl.trustStore");
if (trustStore == null) {
String storeLoc;
storeLoc = System.getProperty("java.class.path");
System.out.println("classpath: " + storeLoc);
}
trustStore = System.getProperty("javax.net.ssl.trustStore");
if (trustStore == null) {
System.out.println("javax.net.ssl.trustStore is not defined");
} else {
System.out.println("javax.net.ssl.trustStore = " + trustStore);
}
}
}
run: java.lang.NullPointerException classpath: C: \ Users \ Main \ Documents \ NetBeansProjects \ sslTest \ build \ classes; C: \ Users \ Main \ Documents \ NetBeansProjects \ sslTest \ src su ssltest.Main.main (Main.java : 15) javax.net.ssl.trustStore non è definito BUILD SUCCESSFUL (tempo totale: 0 secondi)
vedi la mia risposta aggiornata – Bozho
funziona! grazie molto! – oneAday
Buono a sapersi che non sono l'unico a cercare un'ora di errore per ora ... a causa di un errore di battitura ... ;-) – Steffen