Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I have a strange issue that may be related to how I am importing an external library. I went to the Modules tab and clicked on the "import External Jars" icon, and selected my jar. In this case oauth2-platform-api-6.2.4.jar.
I created a tjava component with the following code:
//Prepare the config
OAuth2Config oauth2Config = new OAuth2Config.OAuth2ConfigBuilder(
context.clientId,
context.clientSecret
) // set client id and secret
.callDiscoveryAPI(Environment.SANDBOX) // call discovery API to populate urls
.buildConfig();
//Generate the CSRF token
String csrf = oauth2Config.generateCSRFToken();
//Prepare scopes
List<Scope> scopes = new ArrayList<Scope>();
//scopes.add(Scope.OpenIdAll);
scopes.add(Scope.Accounting); // add as needed
//Get the authorization URL
String url = oauth2Config.prepareUrl(scopes, context.callbackUrl, csrf); //redirectUri - pass the callback url
System.out.println(url);
and in the includes I have:
import java.util.ArrayList;
import java.util.List;
import com.intuit.oauth2.config.Environment;
import com.intuit.oauth2.config.OAuth2Config;
import com.intuit.oauth2.config.Scope;
If I run it normally I get a runtime error:
Starting job Authorization at 17:25 13/10/2023.
[statistics] connecting to socket on port 3868
[statistics] connected
Exception in thread "main" java.lang.NoClassDefFoundError: com/intuit/oauth2/config/OAuth2Config$OAuth2ConfigBuilder
at quickbooks_api_base.authorization_0_1.Authorization.tJava_2Process(Authorization.java:1404)
at quickbooks_api_base.authorization_0_1.Authorization.tFileInputDelimited_1Process(Authorization.java:1321)
at quickbooks_api_base.authorization_0_1.Authorization.runJobInTOS(Authorization.java:2202)
at quickbooks_api_base.authorization_0_1.Authorization.main(Authorization.java:1800)
[statistics] disconnected
[statistics] disconnected
Caused by: java.lang.ClassNotFoundException: com.intuit.oauth2.config.OAuth2Config$OAuth2ConfigBuilder
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 4 more
Job Authorization ended at 17:25 13/10/2023. [Exit code = 1]
The context variables clientId, clientSecret, and callbackUrl contain oauth2 client_id, client_secret, and callback_url. This is for quickbooks, and the library came from intuit.
The class that cannot be found is in the jar, I looked.
It is only at runtime that it can't be found. The compiler finds it just fine as no compile errors appear, and even stranger, if I run it in Java Debug, the code runs through normally (Traces Debug fails the same way that the normal run fails).
It seems that I am missing a configuration or something somewhere.
One thing that is strange, I had to add a Maven config to Project Settings : Build->Maven->Default->Project all the way at the bottom of the pom, immediately before </project>.
<dependencies>
<!-- https://mvnrepository.com/artifact/com.intuit.quickbooks-online/oauth2-platform-api -->
<dependency>
<groupId>com.intuit.quickbooks-online</groupId>
<artifactId>oauth2-platform-api</artifactId>
<version>6.2.4</version>
</dependency>
</dependencies>
Without this, the code wouldn't even compile.
Is there any setting that I might be missing? or did I import the jar improperly?
Hi
Using a tLibraryLoad component to load external jar in the beginning of job or create a user routine to implement your code, import external jar to your user routine.
Regards
Shong
This worked, but I had to put in eleven tLibraryLoad components because it doesn't check dependencies. Is there a way to get Maven to load a library and it's dependencies?