B4J Question B4J user external library (Jar)

Discussion in 'B4J Questions' started by Roberto P., Jul 16, 2015.

  1. Roberto P.

    Roberto P. Well-Known Member Licensed User

    where can I find an example or tuturial for B4J that uses a library Jar outside?
    thanks
     
  2. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi Roberto,

    external libraries can be included by using the #AdditionalJar Parameter in the Project Attribute section.
    You can start with the B4J jSQL Library Tutorial here or have a look at my B4J HOWTOs > Inline Java > select the HOWTO Ext Library JSch or JSoup.
    Important is that you copy the external library (jar file) you want to use to the B4J external library folder.
     
  3. Roberto P.

    Roberto P. Well-Known Member Licensed User

    thanks Rob
     
  4. Roberto P.

    Roberto P. Well-Known Member Licensed User

    I can import every single class? or, I can transform a class in a jar?
    I do not know these features of Java!
    thanks
     
  5. rwblinn

    rwblinn Well-Known Member Licensed User

    Yes you can - have made a simple example showing how to do:
    See attached Java Project (Package > Class > 2 methods and the jar file) and the B4J Project using this external library.
    Please read the b4j project file for further information.
     

    Attached Files:

  6. Roberto P.

    Roberto P. Well-Known Member Licensed User

    thank you. I see, though, you need to have to compile the Jar.
    thanks again

    p.s.
    just for info, your example by mistake.


    Program started.
    ExtLibEx
    Hello World
    main._appstart (java line: 57)
    java.lang.UnsupportedClassVersionError: rwblinn/extlibex/ExtLibExClass : Unsupported major.minor version 52.0
    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 java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(JavaObject.java:272)
    at anywheresoftware.b4j.object.JavaObject.InitializeStatic(JavaObject.java:73)
    at b4j.example.main._appstart(main.java:57)
    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 anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:84)
    at b4j.example.main.start(main.java:36)
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:216)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179)
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:176)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:176)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17)
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67)
    at java.lang.Thread.run(Thread.java:744)
     
  7. rwblinn

    rwblinn Well-Known Member Licensed User

    Hi,

    this message occurs because of a higher JDK during compile time (I used JDK 1.8.0_45) and lower JDK during runtime. Which means you probably have a lower Java version.
    To Fix: Upgrade your Java runtime or recompile the class using your local Java compiler.
     
  8. Roberto P.

    Roberto P. Well-Known Member Licensed User

    ok, thanks you
     
Loading...