I have a little problem. I´ve been trying to use different libraries to produce a json token and now I'm using JJWT from Stormpath. They have tutorials well explained. But my problem is, when I try to run the String method in a "public static void main" method, I get a runtime or class error. In their official website says there is a requeriment that the jackson library must being newer than Version 2.8. So I downloaded such library.
Here my source code:
package org.comunidadIT.proyecto.accesoDatos;
import java.security.Key;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.impl.crypto.MacProvider;
public class ValidarToken {
public String token(){
// We need a signing key, so we'll create one just for this example. Usually
// the key would be read from your application configuration instead.
Key key = MacProvider.generateKey();
String compactJws = Jwts.builder()
.setSubject("Joe")
.signWith(SignatureAlgorithm.HS512, key)
.compact();
return compactJws;
}
public static void main(String args[]){
ValidarToken t= new ValidarToken();
System.out.println(t.token());
}
}
The console show following error message:
Exception in thread "main" java.lang.NoSuchFieldError: USE_DEFAULTS
at com.fasterxml.jackson.annotation.JsonInclude$Value.<clinit>(JsonInclude.java:204)
at com.fasterxml.jackson.databind.cfg.MapperConfig.<clinit>(MapperConfig.java:44)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:549)
at com.fasterxml.jackson.databind.ObjectMapper.<init>(ObjectMapper.java:465)
at io.jsonwebtoken.impl.DefaultJwtBuilder.<clinit>(DefaultJwtBuilder.java:42)
at io.jsonwebtoken.Jwts.builder(Jwts.java:116)
at org.comunidadIT.proyecto.accesoDatos.ValidarToken.token(ValidarToken.java:16)
at org.comunidadIT.proyecto.accesoDatos.ValidarToken.main(ValidarToken.java:27)
Image from maven dependencies where appears to be fine with jackson
Image from the console with erros
As you can see the jackson dependencies appears to be fine.
Also I aatached more libreries to the build-path on reference libraries, but they are outside from the pom.xml.
What do I do wrong?
Thank you
I answer myself so perhaps someone could have the same problem.
I've been with this problem about a month, until I got balls to delete some old libraries located in my project.
The problem appeared to be that I declared a Maven dependecy with jackson 2.8.2 or later and in the 'reference libraries' I had libraries lowers than 1.9, when I removed from my Build-Path the problem was gone. And now I can see the String Token.
This is the picture with the problem solved.
Thank you.
Related
I'm having an issue importing the libraries for the Google Cloud API, I opened a default maven file and included all the appropriate dependencies in my pom.xml file (provided in the CloudCode extension on VSCode) however I keep getting the same error:
The import com.google cannot be resolved
All I'm using is the sample code provided, I'm unsure what the problem is, and I can't seem to find any resources apart from Eclipse.
package com.ootd;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.BucketInfo;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
public class App {
public static void createBucket(String projectId, String bucketName) {
// The ID of your GCP project
// String projectId = "your-project-id";
// The ID to give your GCS bucket
// String bucketName = "your-unique-bucket-name";
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
Bucket bucket = storage.create(BucketInfo.newBuilder(bucketName).build());
System.out.println("Created bucket " + bucket.getName());
}
}
I'm not well versed in Maven, but I've set it up correctly, following step-by-step instructions. I can't see what the issue is.
How can I fix that?
I'm using algorithmia, a repository of trained ML functions on the Internet. Few weeks ago, an issue showed up, and since then, haven't been able to figure out what's going on. I'm executing this code, which can be found on their official site.
import com.algorithmia.Algorithmia;
import com.algorithmia.AlgorithmiaClient;
import com.algorithmia.algo.AlgoResponse;
import com.algorithmia.algo.Algorithm;
public class Main {
public static void main(String[] args) throws Exception {
String input = "A purely peer-to-peer...";
AlgorithmiaClient client = Algorithmia.client("api_key");
Algorithm algo = client.algo("nlp/Summarizer/0.1.8");
algo.setTimeout(300L, java.util.concurrent.TimeUnit.SECONDS); //optional
AlgoResponse result = algo.pipe(input);
System.out.println(result.asJsonString());
}
}
But this code raises the following exception:
Exception in thread "main" com.algorithmia.APIException: 308 unexpected API response:
at com.algorithmia.algo.Algorithm.pipeRequest(Algorithm.java:145)
at com.algorithmia.algo.Algorithm.pipe(Algorithm.java:96)
at Main.main(Main.java:13)
I want to help out
Create a maven project
Add this maven dependency
<dependency>
<groupId>com.algorithmia</groupId>
<artifactId>algorithmia-client</artifactId>
<version>[,1.1.0)</version>
</dependency>
Paste the code showed above
Further observations and guessings
Issuing a cURL request everything works as expected
Using Python works fine
It may have something to do with HttpClient
The Java code will work with a proxy like Charles
Refer to the opened issue on GitHub
Given the current date, 2nd July 2019, they published version 1.0.16 that fix such error.
So I am trying to get an OCR working for a bigger project that reads characters from an image and I am following this you tube video: https://www.youtube.com/watch?v=aEMSxiXctPk
I did everything in the video and still cannot get it to work. I looked on this forum about the error I am getting, but it looks like their projects are different so I think they need different jars than I would. I have all of the jars from the video or at least I think I do. Any ways, the issue in java delivered this message.
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The type org.slf4j.Logger cannot be resolved. It is indirectly referenced from required .class files
org.slf4j.Logger cannot be resolved to a type
LoggerFactory cannot be resolved
The method setDatapath(String) of type Tesseract must override a superclass method
This is my code:
package Tess4j;
import java.io.*;
import net.sourceforge.tess4j.*;
import org.slf4j.*;
public class test {
public static void main(String[] args) throws IOException{
File imageFile = new File("C:\\Users\\Sean\\workspace\\Bigno Tracker\\Images\\eurotext.png");
ITesseract instance=new Tesseract();
instance.setDatapath("C:\\Users\\Sean\\workspace\\Bigno Tracker\\tessdata");
try {
String result=instance.doOCR(imageFile);
System.out.println(result);
}catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
}
This is an image of my screen that shows the jars I have.
So what am I missing?
Thanks in advance.
Edit:
I don’t really understand your question but, I’ve done some work with OCR Engines in the past.. ABBYY hass a good one that’s really easy to integrate!
P.S Did a little research, check to see if you have all the appropriate dependencies for your OCR engine version
Cheers
I've created an EventHub to receive some random messages.
I was just trying to see if i can send messages from a java application.
Below is the code
package com.hasher.connectedcars.sender;
import java.io.IOException;
import java.nio.charset.*;
import java.util.*;
import java.util.concurrent.ExecutionException;
import com.microsoft.azure.eventhubs.*;
import com.microsoft.azure.servicebus.*;
public class Sender {
public static void main(String[] args) throws ServiceBusException,
ExecutionException, InterruptedException, IOException {
try {
final String namespaceName = "******************";
final String eventHubName = "**************************";
final String sasKeyName = "*******************";
final String sasKey = "*******************";
ConnectionStringBuilder connStr = new ConnectionStringBuilder(
namespaceName, eventHubName, sasKeyName, sasKey);
byte[] payloadBytes = "TEST MESSAGES"
.getBytes("UTF-8");
EventData sendEvent = new EventData(payloadBytes);
EventHubClient ehClient = EventHubClient.createFromConnectionStringSync(connStr.toString());
ehClient.sendSync(sendEvent);
} catch (Exception e) {
e.printStackTrace();
}
}
I get the below compilation error from eclipse at
EventData sendEvent = new EventData(payloadBytes);
The type org.apache.qpid.proton.message.Message cannot be resolved. It
is indirectly referenced from required .class files
========================================================================= Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/qpid/proton/engine/Extendable
Can someone point if I am missing some imports.
Thanks,
SriHarsha
According to your code, it seems to be from the offical tutorial https://azure.microsoft.com/en-us/documentation/articles/event-hubs-java-ephjava-getstarted/#send-messages-to-event-hubs.
I tried to reproduce your issue in my maven project, but failed. I added the maven dependency of Azure EventHub SDK for Java in the pom.xml file, then it works fine without NoClassDefFoundError exception. So I guess you might not use maven to build your project, then you need to manually add the dependency libraries into the classpath of your eclipse project.
Please try to use maven to build your project in Eclipse, or add these dependencies (proton-j & bcpkix-jdk15on) into project classpath.
Any concern, please feel free to let me know.
What is interesting is that you get this error with the latest version of the SDK (0.9.0) even when using Maven. Going back to version 0.8.2 seems to be a workaround or, you can simply add the following to the pom.xml:
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>proton-j</artifactId>
<version>0.16.0</version>
</dependency>
I am struggling with a very strange issue (eclipse mars.1)
I have a jar which I am using its methods.
I have added a new method to the class I use, created a new jar, refreshed the client project, I CAN SEE the new methods in the client project explorer, but I cannot use them in the client code!!! I can use only the old methods! It is making me crazy!!
Please see image:
In case image was not uploaded, the error message I get is: "The method initLog(String) is undefined for the type Log4jWrapper"
public void init(String a_strPropertiesPath){
Log4jWrapper.initLog("aaa"); //doesn't recognize initLog
}
public void log(LogLevelEnum a_level, String a_sMethodName, String a_sMessage){
Log4jWrapper.writeLog(a_level, a_sMessage); //recognizes writeLog
}
Thank you all!
You have multiple imports of the same jar in your classpath :-)