B4J Question SLC throwing error

elitevenkat

Active Member
Licensed User
Longtime User
I created a maven project using the below dependencies in pom.xml. When I try to compile this project into a B4J library using SLC, I get an error saying the simple-json package does not exists.


pom.xml
--------------------------------------------------
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.3.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-path</artifactId>
<version>4.3.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>


FAL.java
------------------------------------------------------
package com.elite;

import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.simple.JSONArray; // throwing error in this line while compiling using SLC
import org.json.simple.JSONObject;

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.http.Cookies;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;

public class FAL {


Error in SLC
--------------------------------------------------------
Starting step: Compiling Java code.
javac 1.8.0_281
D:\proj\FrLib\src\main\java\com\elite\FAL.java:9: error: package org.json.simple does not exist
import org.json.simple.JSONArray;
^
1 error

Project Structure:
fs.png

Error.
 

agraham

Expert
Licensed User
Longtime User
Upvote 0

elitevenkat

Active Member
Licensed User
Longtime User
If org.json.simple is not part of the Java installation then SLC needs a 'libs' folder with that jar in it in order to reference it. This may be the problem.
See How to use here
[Tool] Simple Library Compiler - Build libraries without Eclipse | B4X Programming Forum
As pointed by you, i had reconstructed the dir structure.
That error is gone.
I am able create the lib successfully in SLC.
B4X:
java code 
    public boolean login(String clientID, String key) {
        requestPaths();
        setClientID(clientID);
        setKey(key);

/*

Response response = RestAssured.given()
                .headers(buildHeaders())
                .body(loginRequestBuilder(getClientID(), getKey()))
            .when()
                .post(data.get(0).toString())
            .then()
                .statusCode(200)
                .contentType(ContentType.JSON)
                .extract()
                .response();
        JsonPath jsonPathEvaluator = response.jsonPath();
        setCookies(response.getDetailedCookies());
        System.out.println(response.asPrettyString());
        setResId(jsonPathEvaluator.get("user_id"));
        
        return (jsonPathEvaluator.get("statusMessage").toString().toLowerCase()=="login successful");

    */

    return true;
    }
if  i remove the comment, error is thrown
if i retain the comment ,   xui.MsgboxAsync("Hello World!", ok)    ' the result is true in the title.
folder structure all the required external libs are in libs folder.

 Volume in drive D is New Volume
 Volume Serial Number is 9240-55AA

 Directory of D:\FALib\libs

15/03/2021  13:12    <DIR>          .
15/03/2021  13:12    <DIR>          ..
21/01/2014  14:25           263,965 commons-codec-1.9.jar
06/11/2020  15:28           577,742 commons-lang3-3.11.jar
10/06/2015  19:25            61,829 commons-logging-1.2.jar
11/12/2020  09:03         7,949,743 groovy-3.0.7.jar
11/12/2020  09:03           133,034 groovy-json-3.0.7.jar
11/12/2020  09:03           292,540 groovy-xml-3.0.7.jar
15/03/2019  14:33           123,103 hamcrest-2.1.jar
18/04/2017  14:05           747,794 httpclient-4.5.3.jar
30/01/2017  14:41           323,824 httpcore-4.4.6.jar
18/04/2017  14:05            41,029 httpmime-4.5.3.jar
10/03/2020  11:08            46,613 jakarta.activation-api-1.2.2.jar
07/04/2020  08:22           115,638 jakarta.xml.bind-api-2.3.3.jar
03/07/2020  08:36         1,133,924 jaxb-impl-2.3.3.jar
11/12/2020  09:57           105,164 json-path-4.3.3.jar
15/03/2021  00:23            23,737 json-simple-1.1.1.jar
11/12/2020  09:57           865,467 rest-assured-4.3.3.jar
22/07/2012  09:23            90,722 tagsoup-1.2.1.jar
              18 File(s)     12,895,868 bytes
               2 Dir(s)  447,011,999,744 bytes free


b4j code

B4X:
#Region Project Attributes 
    #MainFormWidth: 600
    #MainFormHeight: 600 
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI 
    Private Button1 As B4XView
    Private f1 As FAL
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    MainForm.Show
End Sub

Sub Button1_Click
    Dim ok As Boolean=    f1.login("xxxx","xxx")
     xui.MsgboxAsync("Hello World!", ok)    ' the result is true in the title.
End Sub
 
Upvote 0

elitevenkat

Active Member
Licensed User
Longtime User
Sorry i have not posted the error when method from rest-assured-4.3.3.jar is called.

the error is

main._button1_click (java line: 64)
java.lang.NoClassDefFoundError: io/restassured/RestAssured
at com.elite.FAL.login(FAL.java:37)
at b4j.example.main._button1_click(main.java:64)
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 anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
at anywheresoftware.b4a.BA$1.run(BA.java:216)
at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:185)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassNotFoundException: io.restassured.RestAssured
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)
... 15 more
 
Upvote 0

elitevenkat

Active Member
Licensed User
Longtime User
Libraries shouldn't make http requests or deal with json. These are trivial features to implement in B4X.

Yes. The process we are trying with the lib is to access Restapi from a 3rd party site. I pass user credentials (login id and pw).
In the response i get the cookies from the response header. This cookie value is passed in the subsequent post request.
To achieve this the lib was planed.
I don't know to do it b4j itself.
 
Upvote 0
Top