我编写了这个简单的测试业务对象API程序。
import com.crystaldecisions.sdk.framework.*;
import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
import com.crystaldecisions.sdk.occa.infostore.IInfoObject;
import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;
import com.crystaldecisions.sdk.framework.IEnterpriseSession;
import com.crystaldecisions.sdk.framework.CrystalEnterprise;
import java.util.*;
import java.net.URLEncoder;
import java.io.UnsupportedEncodingException;
class LogonToken {
public static void main(String[] args) {
final Map<String, List<String>> params = new HashMap<>();
List<String> options = null;
for (int i = 0; i < args.length; i++) {
final String a = args[i];
if (a.charAt(0) == '-') {
if (a.length() < 2) {
System.err.println("Error at argument " + a);
return;
}
options = new ArrayList<>();
params.put(a.substring(1), options);
}
else if (options != null) {
options.add(a);
}
else {
System.err.println("Illegal parameter usage");
return;
}
}
if (
args.length == 0 ||
params.get("-username") == null ||
params.get("-username").size() == 0 ||
params.get("-password") == null ||
params.get("-password").size() == 0 ||
params.get("-output-type") == null ||
params.get("-output-type").size() == 0 ||
params.get("-doc-id") == null ||
params.get("-doc-id").size() == 0 ||
params.get("-s-id-type") == null ||
params.get("-s-id-type").size() == 0 ||
params.get("-cms-auth-type") == null ||
params.get("-cms-auth-type").size() == 0 ||
params.get("-cms-name") == null ||
params.get("-cms-name").size() == 0
) {
printArgumentsError("");
return;
}
String username = params.get("-username").get(0);
String password = params.get("-password").get(0);
String output_type = params.get("-output-type").get(0);
String doc_id = params.get("-doc-id").get(0);
String s_id_type = params.get("-s-id-type").get(0);
String cms_name = params.get("-cms-name").get(0);
String cms_auth_type = params.get("-cms-auth-type").get(0);
if (output_type.equals("url")) {
System.out.println("URL: " + getUrl(username, password, doc_id, s_id_type, cms_name, cms_auth_type));
} else {
if (output_type.equals("token")) {
System.out.println("TOKEN: " + getToken(username, password, doc_id, s_id_type, cms_name, cms_auth_type));
} else {
printArgumentsError("Output type must be either url or token. You provided: *" + params.get("-output-type").get(0) + "*");
}
}
}
public static String getToken(String username, String password, String doc_id, String s_id_type, String cms_name, String cms_auth_type) {
try {
return openDocumentToken(username, password, cms_name, cms_auth_type);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
return "ERROR: " + e.getMessage();
} catch (SDKException e) {
return "ERROR: " + e.getMessage();
}
}
public static String getUrl(String username, String password, String doc_id, String s_id_type, String cms_name, String cms_auth_type) {
try {
return ( "http://<server>:<port>/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=" + doc_id + "&sIDType=" + s_id_type + "&token=" + openDocumentToken(username, password, cms_name, cms_auth_type));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
return "ERROR: " + e.getMessage();
} catch (SDKException e) {
return "ERROR: " + e.getMessage();
}
}
public static String openDocumentToken(String username, String password, String cms_name, String cms_auth_type) throws UnsupportedEncodingException, SDKException
{
IEnterpriseSession sess = CrystalEnterprise.getSessionMgr().logon(username, password, cms_name, cms_auth_type);
String token = sess.getLogonTokenMgr().createLogonToken("", 600, 600);
String tokenEncode = URLEncoder.encode( token, "UTF-8");
// String tokenEncode = URLEncoder.encode("Test", "UTF-8");
return tokenEncode;
}
public static void printArgumentsError(String error) {
System.out.println("");
System.out.println("======================================");
System.out.println(error);
System.out.println("Please provide all required arguments:");
System.out.println("--username username");
System.out.println("--password password");
System.out.println("--output-type output_type (url or token)");
System.out.println("--doc-id iDocID");
System.out.println("--s-id-type sIDType (ex. CUID)");
System.out.println("--cms-name cms_type (ex. \"<cms>:<port>\", double quotes are required in such case)");
System.out.println("--cms-auth-type auth_type (ex. secEnterprise)");
System.out.println("");
System.out.println("Example invokation:");
System.out.println("java LogonToken --username tmiskiew --password AwesomePass --output-type token --doc-id 12345 --s-id-type CUID --cms-name \"<cms>:<port>\" --cms-auth-type secEnterprise");
System.out.println("");
System.out.println("======================================");
System.out.println("");
}}
我将我的LogonToken.java与C:\ Cache \ libz一起放在所需的罐子里。
编译工作正常。
然而,当我尝试运行它时
C:\Cache\libz>"C:\Program Files\Java\jdk1.7.0_45\bin\java" -cp . LogonToken --username myUser --password mySecret --output-type url --doc-id ATKhgk7J3CtHizezzIfibUAE --s-id-type CUID --cms-name myHost
我明白了:
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: com/rsa/cryptoj/f/tK (wrong name: com/rsa/cryptoj/f/tk)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at com.businessobjects.bcm.internal.BcmRsaLib.initialize(BcmRsaLib.java:214)
at com.businessobjects.bcm.internal.BcmRsaLib.<clinit>(BcmRsaLib.java:289)
at com.businessobjects.bcm.BCM.<clinit>(BCM.java:1144)
at com.crystaldecisions.enterprise.ocaframework.BCMInitializer.run(BCMInitializer.java:29)
at java.lang.Thread.run(Thread.java:744)
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class com.businessobjects.bcm.BCM
at com.crystaldecisions.sdk.occa.security.internal.ConfidentialChannelService.establishConfidentialChannel(ConfidentialChannelService.java:175)
at com.crystaldecisions.sdk.occa.security.internal.ConfidentialChannelService.createConfidentialChannel(ConfidentialChannelService.java:145)
at com.crystaldecisions.sdk.occa.security.internal.CCMap.locateCCItem(CCMap.java:63)
at com.crystaldecisions.sdk.occa.security.internal.LogonService.doUserLogon(LogonService.java:845)
at com.crystaldecisions.sdk.occa.security.internal.LogonService.doUserLogon(LogonService.java:805)
at com.crystaldecisions.sdk.occa.security.internal.LogonService.userLogon(LogonService.java:210)
at com.crystaldecisions.sdk.occa.security.internal.SecurityMgr.userLogon(SecurityMgr.java:166)
at com.crystaldecisions.sdk.framework.internal.SessionMgr.logon_aroundBody0(SessionMgr.java:454)
at com.crystaldecisions.sdk.framework.internal.SessionMgr.logon_aroundBody1$advice(SessionMgr.java:512)
at com.crystaldecisions.sdk.framework.internal.SessionMgr.logon(SessionMgr.java:1)
at LogonToken.openDocumentToken(LogonToken.java:105)
at LogonToken.getUrl(LogonToken.java:94)
at LogonToken.main(LogonToken.java:69)
知道那个“错误名称”类型的错误试图告诉我什么?编译器在编译期间知道类,为什么它在运行时抱怨。这对我来说是一个令人困惑的偶然java程序员。
答案 0 :(得分:2)
在我看来与此类似:NoClassDefFoundError: wrong name。那么你的包裹名称是什么,你试过调用"C:\Program Files\Java\jdk1.7.0_45\bin\java" -cp . my.package.namespace.LogonToken
吗?