I'm trying to read data from ePassporta using jmrtd and scuba.
But it doesn’t work. In Android, almost the same code works.
And when reading from a smart card it doesn’t work.
My method for reading:
public static void reader() throws Exception {
try {
CardTerminal terminal =TerminalFactory.getDefault().terminals().list().get(0);
CardService cs = CardService.getInstance(terminal);
PassportService service = new PassportService(cs);
service.open();
BACKeySpec bacKey = new BACKey("12312312312312", "31121990", "311230");
boolean paceSucceeded = false;
try {
CardAccessFile cardAccessFile = new CardAccessFile(service.getInputStream(PassportService.EF_CARD_ACCESS));
Collection<PACEInfo> paceInfos = cardAccessFile.getPACEInfos();
if (paceInfos != null && paceInfos.size() > 0) {
PACEInfo paceInfo = paceInfos.iterator().next();
service.doPACE(bacKey, paceInfo.getObjectIdentifier(), PACEInfo.toParameterSpec(paceInfo.getParameterId()));
paceSucceeded = true;
} else {
paceSucceeded = true;
}
} catch (Exception e) {
e.printStackTrace();
}
service.sendSelectApplet(paceSucceeded);
if (!paceSucceeded) {
try {
service.getInputStream(PassportService.EF_COM).read();
} catch (Exception e) {
service.doBAC(bacKey);
}
}
LDS lds = new LDS();
CardFileInputStream dg1In = service.getInputStream(PassportService.EF_DG1);
lds.add(PassportService.EF_DG1, dg1In, dg1In.getLength());
DG1File dg1File = lds.getDG1File();
System.out.println(dg1File.getMRZInfo().toString());
} catch (CardServiceException e) {
e.printStackTrace();
}
}
pom.xml
<dependency>
<groupId>org.jmrtd</groupId>
<artifactId>jmrtd</artifactId>
<version>0.5.2</version>
</dependency>
<dependency>
<groupId>net.sf.scuba</groupId>
<artifactId>scuba-sc-j2se</artifactId>
<version>0.0.13</version>
</dependency>
<dependency>
<groupId>net.sf.scuba</groupId>
<artifactId>scuba-smartcards</artifactId>
<version>0.0.13</version>
</dependency>
Stacktrace :
add more text just for stack overflow to accept the question.
added full stacktrace content.
added full stacktrace content.
added full stacktrace content.
added full stacktrace content.
D:\Java\jdk\bin\java -Didea.launcher.port=7539 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.0\bin" -Dfile.encoding=UTF-8 -classpath "D:\Java\jdk\jre\lib\charsets.jar;D:\Java\jdk\jre\lib\deploy.jar;D:\Java\jdk\jre\lib\javaws.jar;D:\Java\jdk\jre\lib\jce.jar;D:\Java\jdk\jre\lib\jfr.jar;D:\Java\jdk\jre\lib\jfxswt.jar;D:\Java\jdk\jre\lib\jsse.jar;D:\Java\jdk\jre\lib\management-agent.jar;D:\Java\jdk\jre\lib\plugin.jar;D:\Java\jdk\jre\lib\resources.jar;D:\Java\jdk\jre\lib\rt.jar;D:\Java\jdk\jre\lib\ext\access-bridge-32.jar;D:\Java\jdk\jre\lib\ext\cldrdata.jar;D:\Java\jdk\jre\lib\ext\dnsns.jar;D:\Java\jdk\jre\lib\ext\jaccess.jar;D:\Java\jdk\jre\lib\ext\jfxrt.jar;D:\Java\jdk\jre\lib\ext\localedata.jar;D:\Java\jdk\jre\lib\ext\nashorn.jar;D:\Java\jdk\jre\lib\ext\sunec.jar;D:\Java\jdk\jre\lib\ext\sunjce_provider.jar;D:\Java\jdk\jre\lib\ext\sunmscapi.jar;D:\Java\jdk\jre\lib\ext\sunpkcs11.jar;D:\Java\jdk\jre\lib\ext\zipfs.jar;C:\Users\maksat\IdeaProjects\smart_card\target\classes;C:\Users\maksat\.m2\repository\org\jmrtd\jmrtd\0.5.2\jmrtd-0.5.2.jar;C:\Users\maksat\.m2\repository\org\bouncycastle\bcprov-jdk15on\1.52\bcprov-jdk15on-1.52.jar;C:\Users\maksat\.m2\repository\net\sf\scuba\scuba-sc-j2se\0.0.11\scuba-sc-j2se-0.0.11.jar;C:\Users\maksat\.m2\repository\net\sf\scuba\scuba-smartcards\0.0.9\scuba-smartcards-0.0.9.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 14.0\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain paket.ReadFromSmartCard
net.sf.scuba.smartcards.CardServiceException: File not found, CAPDU = 00A4020C02011C, RAPDU = 6A82 (SW = 0x6A82: FILE NOT FOUND)
at org.jmrtd.PassportApduService.checkStatusWordAfterFileOperation(Unknown Source)
at org.jmrtd.PassportApduService.sendSelectFile(Unknown Source)
at org.jmrtd.PassportService.sendSelectFile(Unknown Source)
at org.jmrtd.MRTDFileSystem.getFileInfo(Unknown Source)
at org.jmrtd.MRTDFileSystem.getSelectedPath(Unknown Source)
at net.sf.scuba.smartcards.CardFileInputStream.<init>(CardFileInputStream.java:56)
at org.jmrtd.PassportService.getInputStream(Unknown Source)
at paket.ReadFromSmartCard.sdvsdv(ReadFromSmartCard.java:121)
at paket.ReadFromSmartCard.readData(ReadFromSmartCard.java:89)
at paket.ReadFromSmartCard.main(ReadFromSmartCard.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
ноя 19, 2019 10:45:51 AM org.jmrtd.PassportService doBAC
WARNING: BAC failed for BAC key "21009199301195, 100993, 120229"
net.sf.scuba.smartcards.CardServiceException: Mutual authentication failed: expected length: 40 + 2, actual length: 2 (SW = 0x6985: CONDITIONS NOT SATISFIED)
at org.jmrtd.PassportApduService.sendMutualAuth(Unknown Source)
at org.jmrtd.PassportService.doBAC(Unknown Source)
at org.jmrtd.PassportService.doBAC(Unknown Source)
at paket.ReadFromSmartCard.sdvsdv(ReadFromSmartCard.java:140)
at paket.ReadFromSmartCard.readData(ReadFromSmartCard.java:89)
at paket.ReadFromSmartCard.main(ReadFromSmartCard.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Process finished with exit code 0
Related
public static void main(String[] args) {
try {
PdfViewerStarter jt = new PdfViewerStarter();
jt.doConversion("http://pd4ml.com/sample.htm", "D:/pd4ml.pdf");
} catch (Exception e) {
e.printStackTrace();
}
}
public void doConversion(String url, String outputPath)
throws InvalidParameterException, MalformedURLException, IOException {
File output = new File(outputPath);
java.io.FileOutputStream fos = new java.io.FileOutputStream(output);
PD4ML pd4ml = new PD4ML();
pd4ml.setHtmlWidth(userSpaceWidth);
pd4ml.setPageSize(pd4ml.changePageOrientation(PD4Constants.A4));
pd4ml.setPageInsetsMM(new Insets(topValue, leftValue, bottomValue, rightValue));
pd4ml.useTTF("c:/windows/fonts", true);
pd4ml.render(new URL(url), fos);
fos.close();
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(output);
} else {
System.out.println("Awt Desktop is not supported!");
}
System.out.println(outputPath + "\ndone.");
}
Error:
Error. ss_css2.jar is not in the classpath. See README.txt
Exception in thread "main" java.lang.NoClassDefFoundError: org/w3c/css/sac/CSSException
at org.zefer.html.doc.PD4MLHtmlParser.o00000(Unknown Source)
at org.zefer.html.doc.PD4MLHtmlParser.<init>(Unknown Source)
at org.zefer.pd4ml.PD4ML.super(Unknown Source)
at org.zefer.pd4ml.PD4ML.render(Unknown Source)
at TestForPdfPD4ML.doConversion(TestForPdfPD4ML.java:42)
at TestForPdfPD4ML.main(TestForPdfPD4ML.java:24)
Caused by: java.lang.ClassNotFoundException: org.w3c.css.sac.CSSException
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 6 more
It may be asking for the ClassPath of the Jar File where the needed (imported) libraries are contained. If you are running from Command Line try something like this:
java -cp .;"The full path where the Jar File is\jarfile.jar" YourRunningClassFile
I have this method(simplified) for detecting faces(count) on images(URLs):
private int processImage(String urlString) {
InputStream is = null;
URLConnection resource;
int facesCount = 0;
try {
resource = new URL(urlString).openConnection();
resource.setConnectTimeout(200);
resource.setReadTimeout(1000);
resource.setRequestProperty("User-Agent", "Mozilla/5.0");
String type = resource.getHeaderField("Content-Type");
if (!type.startsWith("image/")) {
throw new IOException("Not an image (Content-Type:" + type + ")");
}
is = resource.getInputStream();
MBFImage mbfimage = ImageUtilities.readMBF(is);
facesCount = faceDetector.detectFaces(Transforms.calculateIntensity(mbfimage)).size();
is.close();
} catch (IOException e) {
System.out.println("oops");
}
return facesCount;
}
It works well, but if the image is somewhat corrupted (for example this test image), i get this error:
Error: Cannot decode the image for the type : Occurs in:
com.sun.media.jai.opimage.CodecRIFUtil java.io.IOException: Source
stream does not support seeking backwards. at
com.sun.media.jai.codecimpl.CodecUtils.toIOException(CodecUtils.java:76)
at
com.sun.media.jai.codecimpl.FPXImageDecoder.decodeAsRenderedImage(FPXImageDecoder.java:40)
at
com.sun.media.jai.opimage.CodecRIFUtil.create(CodecRIFUtil.java:88)
at com.sun.media.jai.opimage.FPXRIF.create(FPXRIF.java:46) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
javax.media.jai.FactoryCache.invoke(FactoryCache.java:122) at
javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at
javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at com.sun.media.jai.opimage.StreamRIF.create(StreamRIF.java:102) at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606) at
javax.media.jai.FactoryCache.invoke(FactoryCache.java:122) at
javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1674)
at
javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:473)
at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:332)
at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:819) at
javax.media.jai.RenderedOp.createRendering(RenderedOp.java:867) at
javax.media.jai.RenderedOp.getColorModel(RenderedOp.java:2242) at
javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2498)
at
javax.media.jai.PlanarImage.getAsBufferedImage(PlanarImage.java:2546)
at org.openimaj.image.ExtendedImageIO.read(ExtendedImageIO.java:162)
at org.openimaj.image.ImageUtilities.readMBF(ImageUtilities.java:273)
at image.ImageThread.processImage(ImageThread.java:233) at
image.ImageThread.main(ImageThread.java:255) Caused by:
java.lang.IllegalArgumentException: Source stream does not support
seeking backwards. at
com.sun.media.jai.codec.SegmentedSeekableStream.(SegmentedSeekableStream.java:200)
at
com.sun.media.jai.codec.SegmentedSeekableStream.(SegmentedSeekableStream.java:262)
at
com.sun.media.jai.codecimpl.fpx.StructuredStorage.getFat(StructuredStorage.java:238)
at
com.sun.media.jai.codecimpl.fpx.StructuredStorage.(StructuredStorage.java:131)
at com.sun.media.jai.codecimpl.fpx.FPXImage.(FPXImage.java:110)
at
com.sun.media.jai.codecimpl.FPXImageDecoder.decodeAsRenderedImage(FPXImageDecoder.java:38)
... 28 more
and the program hangs. I want to catch that exception, log it and go on.
Could you please help me?
Ok, I found the solution. I was using old version of openIMAJ (1.1.3). The latest version is 1.3.1 which works well. I didn't notice, because I overlooked the version numbers.
I have below code of main class that i am trying to run with gradle . i have attached the sample main class of java and gradle script below.
public class Hello {
public static void main(String[] args) throws IOException {
System.out.println("This is file system watch service");
Path dir = Paths.get("c:\\sid\\");
WatchService service = FileSystems.getDefault().newWatchService();
WatchKey key = dir.register(service, ENTRY_CREATE);
System.out.println("Watching directory: "+dir.toString());
//file creation logic
while(true) {
for (WatchEvent<?> event: key.pollEvents()) {
WatchEvent.Kind<?> kind = event.kind();
if (kind == OVERFLOW) {
continue;
}
WatchEvent<Path> ev = (WatchEvent<Path>)event;
Path filename = ev.context();
}
}
}
}
Also my gradle script is as below
apply plugin: 'java'
task hello1 << {
def process = ['java', '-cp', 'sourceSets.main.runtimeClasspath', 'com.test.gradle.Hello'].execute()
process.in.close()
process.out.close()
process.err.close()
}
task hello << {
ant.java(classpath:'sourceSets.main.runtimeClasspath', classname:'com.test.gradle.Hello', fork:'true')
ant.echo('Done')
}
When I call gradle hello1 from command prompt it says build successful however it seems my main program never gets executed. To see the execution of main program I have added sample sysout and file creation logic with PrintWriter.
I have also tried with ant with gradle hello this is also not working.
Now when i use the gradle task as below removed fork true from previous
task hello << {
ant.java(classpath:'sourceSets.main.runtimeClasspath.asPath', classname:'com.test.gradle.Hello.class')
ant.echo('Done')
}
it is generating below exception
[ant:java] Could not find com.test.gradle.Hello.class. Make sure you have it in
your classpath
at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:13
8)
at org.apache.tools.ant.taskdefs.Java.run(Java.java:771)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:221)
at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135)
at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
at groovy.util.AntBuilder.performTask(AntBuilder.java:319)
at groovy.util.AntBuilder.nodeCompleted(AntBuilder.java:264)
at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(Bas
icAntBuilder.java:72)
at groovy.util.BuilderSupport.doInvokeMethod(BuilderSupport.java:147)
at groovy.util.AntBuilder.doInvokeMethod(AntBuilder.java:203)
at org.gradle.api.internal.project.ant.BasicAntBuilder.doInvokeMethod(Ba
sicAntBuilder.java:87)
at groovy.util.BuilderSupport.invokeMethod(BuilderSupport.java:64)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaC
lassSite.java:45)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSi
teArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCa
llSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCa
llSite.java:116)
at build_1dcr9mg141bsc4tjjgplovccq0$_run_closure2.doCall(C:\Users\sumit\
workspace1\gradleTest\build.gradle:13)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:
90)
Try this
javaexec {
main = 'com.pack.YourClass'
classpath(sourceSets.src.output.classesDir, sourceSets.src.compileClasspath)
args(arg1, arg2)
}
In an android app, having:
public class Pars extends Activity{
public Document docout(){
InputStream is = getResources().openRawResource(R.raw.talechap01);
Document docout = null;
DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = domFactory.newDocumentBuilder();
docout = builder.parse(is);
} catch (ParserConfigurationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return docout;
}
and
public class Manager {
public static String getStory(String spage, Document docs) {
XPathExpression expr;
XPath xpath = XPathFactory.newInstance().newXPath();
Object result = null;
String num = spage;
String par = null;
try {
expr = xpath.compile("//decision"+num+"/p//text()");
result = expr.evaluate(docs, XPathConstants.NODESET);
}
catch (XPathExpressionException e) {
e.printStackTrace();
}
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
par = nodes.item(i).getNodeValue();
System.out.println(par);
}
return par;
}
}
Now I want to test the code.
public class Test {
public static void main(String[] args) {
try {Pars p = new Pars();
Document doc = p.docout();
System.out.println(Manager.getStory("000", doc));
}catch (Exception e){
e.printStackTrace();
}
}
}
I run "Test" as a java application and I get:
Exception in thread "main" java.lang.NoClassDefFoundError:
android/app/Activity at java.lang.ClassLoader.defineClass1(Native
Method) at java.lang.ClassLoader.defineClass(Unknown Source) at
java.security.SecureClassLoader.defineClass(Unknown Source) at
java.net.URLClassLoader.defineClass(Unknown Source) at
java.net.URLClassLoader.access$100(Unknown Source) at
java.net.URLClassLoader$1.run(Unknown Source) at
java.net.URLClassLoader$1.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
com.stack.over.Test.main(Test.java:11) Caused by:
java.lang.ClassNotFoundException: android.app.Activity at
java.net.URLClassLoader$1.run(Unknown Source) at
java.net.URLClassLoader$1.run(Unknown Source) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) at
sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at
java.lang.ClassLoader.loadClass(Unknown Source) ... 13 more
I tried to find how to fix it but cannot achieve it.
I have this answer from another question but I'm kind of noob yet and can't figure it out how to fix it.
You have defined your Pars class as extending the class Activity. The
error you are seeing is telling you that the class
android.app.Activity is not available on the classpath. Maybe you need
to check which libraries you import. – adamretter Mar 5 at 10:01
Thanks all.
The error is that you're trying to run a program that references Android classes (android.app.Activity) as a regular Java program that doesn't have Android runtime libraries in its classpath.
You should run Android apps as Android apps (on an emulator or a device) and regular Java programs as regular Java programs and not mix the two. Activity is Android; main() method is regular Java.
To learn Android app development, you can start with the developer.android.com getting started documentation.
The error message says it all. You are writing Android now. Trying to write a main method doesn't make any more sense in Android than it would if you were writing a webapp that runs in Tomcat. You are going to need to step back and read up on how Android works.
I have seen many errors with Twitter4j with Android, but I am not using it for Android. I am using it for Bukkit (Minecraft Plugin). For some reason, when I add twitter4j-core-3.0.3.jar to my project, I get a error when loading in the server console:
[SEVERE] Could not load 'plugins\Test.jar' in folder 'plugins'
org.bukkit.plugin.InvalidPluginException: java.lang.NoClassDefFoundError: twitter4j/TwitterException
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:184)
at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
at org.bukkit.craftbukkit.v1_6_R2.CraftServer.loadPlugins(CraftServer.java:239)
at org.bukkit.craftbukkit.v1_6_R2.CraftServer.<init>(CraftServer.java:217)
at net.minecraft.server.v1_6_R2.PlayerList.<init>(PlayerList.java:56)
at net.minecraft.server.v1_6_R2.DedicatedPlayerList.<init>(SourceFile:11)
at net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.java:106)
at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:391)
at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
Caused by: java.lang.NoClassDefFoundError: twitter4j/TwitterException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:173)
... 9 more
Caused by: java.lang.ClassNotFoundException: twitter4j.TwitterException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 12 more`
Since I am new to Java, I am really not getting what I am doing wrong here. This is my code (I do not think this is the issue, since the plugin fails to load ... :
String TWITTER_CONSUMER_KEY = "XXXXXXXX";
String TWITTER_SECRET_KEY = "XXXXXX";
String TWITTER_ACCESS_TOKEN = "XXXXXXXXXX";
String TWITTER_ACCESS_TOKEN_SECRET = "XXXXXX";
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true).setOAuthConsumerKey(TWITTER_CONSUMER_KEY).setOAuthConsumerSecret(TWITTER_SECRET_KEY).setOAuthAccessToken(TWITTER_ACCESS_TOKEN).setOAuthAccessTokenSecret(TWITTER_ACCESS_TOKEN_SECRET);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
try {
Query query = new Query(Username);
QueryResult result;
do {
result = twitter.search(query);
List<Status> tweets = result.getTweets();
for (Status tweet : tweets)
{
String rawJSON = DataObjectFactory.getRawJSON(tweet);
try
{
BufferedWriter out = new BufferedWriter(new FileWriter((getDataFolder() + File.separator + "TwitterData.txt")));
out.write(rawJSON);
out.close();
}
catch (IOException ioe)
{
ioe.printStackTrace();
System.out.println("Failed to store tweets: " + ioe.getMessage());
}
}
}
while ((query = result.nextQuery()) != null);
System.exit(0);
}
catch (TwitterException te)
{
te.printStackTrace();
System.out.println("Failed to search tweets: " + te.getMessage());
System.exit(-1);
}
Why is Twitter4j not loading properly? Thanks!
EDIT: Also, the twitter4j-core-3.03.jar is in another directory on my computer. Is that a issue?
All jars needed by your Java program need to be on the classpath on the server. This includes Twitter4J in your case.