Java Question How to add .jar file to library

potduang

Member
Licensed User
Longtime User
I'm a newbie one on b4a. I've an android tablet with bult-in barcode scanner (real barcode scanner, not a camera) with a SDK library file in .jar (platform_extension.jar) . I've created a .xml file for that SDK and in Libs can call function like my .xml file declared. The problem is that when I compile the program it return error

Compiling code. 0.10
Compiling layouts code. 0.04
Generating R file. 0.00
Compiling generated Java code. Error
javac 1.7.0_07
src\test9300\b4a\main.java:210: error: package platform_extension does not exist
platform_extension.scanManager _scanner = null;
^
1 error

Am I missing or done anything wrong?
 

barx

Well-Known Member
Licensed User
Longtime User
If you are creating a library that exposes a 3rd party java lib to basic 4 android then it is classed as a 'wrapper', because it wraps the underlying 3rd party lib.

To let Basic 4 Android know that your library requires another file to be present you add the @DependsOn annotation. and example being:

B4X:
@DependsOn(values = {"android-support-v4"})

'android-support-v4' being the file name (without the extension).

you place this code at in the same place as you add @author, @Version, etc.

Hope this helps
 

potduang

Member
Licensed User
Longtime User
Thank you barx. I will try as your advice.

Further more questions,please.

Am I correct that this must be add to java source code?
If I don't have the java code, I've to ask my vendor to do this for me. Am I right?

Thank you in advance!
 

barx

Well-Known Member
Licensed User
Longtime User
I have just read your first post again and I think you are misunderstanding what you require to do. This is how things normally work with libraries. The platform_extension.jar stays as it is. You create a new library for Basic4Android. In the new library you create methods for the calls that are required. These calls then call the methods of platform-extension.jar. When you add the additional libraries in eclipse (BAShared, Core and Android) you should also add reference to platform_extension.jar. and also include an import within the class.

I'm not exactly an expert on libs so I hope I have explained that in a manner that is understandable.
 

potduang

Member
Licensed User
Longtime User
I have just read your first post again and I think you are misunderstanding what you require to do. This is how things normally work with libraries. The platform_extension.jar stays as it is. You create a new library for Basic4Android. In the new library you create methods for the calls that are required. These calls then call the methods of platform-extension.jar. When you add the additional libraries in eclipse (BAShared, Core and Android) you should also add reference to platform_extension.jar. and also include an import within the class.

I'm not exactly an expert on libs so I hope I have explained that in a manner that is understandable.

Thanks barx!!! You've enlighted me. I will try follow your suggestion. I will post my result later.
 

potduang

Member
Licensed User
Longtime User
After trying for awhile, I've create my testing as

upload_2014-1-4_22-39-41.png


when I generate JavaDoc, console display as below

upload_2014-1-4_22-40-27.png


and when I checked at output folder, there was only "myLib.xml"! Where can I find "myLib.jar"?

Any suggestion? Please help!
 

agraham

Expert
Licensed User
Longtime User
Select your "src" folder in Package Explorer, right click -> Export Java -> Jar file; select destination and name then press Finish.

Or better, set up SLC, http://www.b4x.com/android/forum/th...mpiler-build-libraries-without-eclipse.29918/, as an external tool with arguments ${project_name} c:\Java\workspace\${project_path}, Run -> External Tools -> External Tools Configuration and it will compile the jar and xml in one go if you select your project in Package Explorer and do Run -> External Tools -> SLC.

As your library depends on another jar you will need to make a "Libs" folder in your project and copy that jar there so SLC can find it.
 

potduang

Member
Licensed User
Longtime User
Select your "src" folder in Package Explorer, right click -> Export Java -> Jar file; select destination and name then press Finish.

Or better, set up SLC, http://www.b4x.com/android/forum/th...mpiler-build-libraries-without-eclipse.29918/, as an external tool with arguments ${project_name} c:\Java\workspace\${project_path}, Run -> External Tools -> External Tools Configuration and it will compile the jar and xml in one go if you select your project in Package Explorer and do Run -> External Tools -> SLC.

As your library depends on another jar you will need to make a "Libs" folder in your project and copy that jar there so SLC can find it.

Thank you agraham. I've just tried myLib in B4A and now there no error during compile time.
Next I will try using SLC as your instructions.
 

Firpas

Active Member
Licensed User
Longtime User
Hello,
I have the same problem, but my library includes a third jar file ("PDFjet.jar").

This is a trial version downloaded from the official website (http://pdfjet.com/java/download.html).

I copied this jar in a "lib" folder within the project and I added reference in "Buid Path" just like the B4A libraries ("B4AShared.jar" and "core.jar")
and of course "android. jar ".

The "Project - Generate javadoc ..." option generates the xml file only, and Eclipse console displays:

Loading source files for package com.ags.agspdf...
Constructing Javadoc information...
[-doclet, BADoclet]
[-docletpath, D:\EclipseWorkspace\qpdf\BADoclet]
[-sourcepath, D:\EclipseWorkspace\AGSPdfJet\src]
[-classpath, C:\Program Files\Anywhere Software\Basic4android\Libraries\B4AShared.jar;D:\EclipseWorkspace\AGSPdfJet\lib\PDFjet.jar;D:\Android\adt-bundle-windows-x86-20140702\sdk\platforms\android-14\android.jar;C:\Program Files\Anywhere Software\Basic4android\Libraries\Core.jar]
[-public]
[-b4atarget, C:\Program Files\Anywhere Software\Basic4android\Libraries\AGSpdf.xml]
starting....
Working with class: com.ags.agspdf.AGSpdf
finish: C:\Program Files\Anywhere Software\Basic4android\Libraries\AGSpdf.xml


I tried with SLC and I have the same result.

Starting step: Compiling Java code.
javac 1.8.0_11
D:\EclipseWorkspace\AGSPdfJet\src\com\ags\agspdf\AGSpdf.java:5: error: package com.pdfjet does not exist
import com.pdfjet.*;
^
1 error

Error.

See attached images

Can anybody help me?

Thanks for your cooperation.
 

Attachments

  • Screen1.png
    89.7 KB · Views: 294
  • Screen2.png
    45.2 KB · Views: 394

Firpas

Active Member
Licensed User
Longtime User
Hi Erel,
I`ve add a "@DependsOn" annotation ....

B4X:
import java.io.*;

import com.pdfjet.*;

import android.util.Log;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@DependsOn(values=("com.pdfjet"))
@ShortName("AGSpdf")
@Version(1)
@Author("Firpas")

... but with the same result ...

Starting step: Compiling Java code.
javac 1.8.0_11
D:\EclipseWorkspace\AGSPdfJet\src\com\ags\agspdf\AGSpdf.java:5: error: package com.pdfjet does not exist
import com.pdfjet.*;
^
1 error

Error.

What am I doing wrong?

Thanks in advance
 

Firpas

Active Member
Licensed User
Longtime User
Hi DonManfred

Thanks for your replay.

I´ve changed @DependsOn(values=("com.pdfjet")) by @DependsOn(values=("PDFjet")) but ...
the error persists.
 

Firpas

Active Member
Licensed User
Longtime User
If i compile with SLC i recive nothing.

Starting step: Compiling Java code.
javac 1.8.0_11
D:\EclipseWorkspace\AGSPdfJet\src\com\ags\agspdf\AGSpdf.java:7: error: package com.pdfjet does not exist
import com.pdfjet.*;
^
1 error

Error.

With Eclipse "Generate javadoc" i recive the XML file only.

Loading source files for package com.ags.agspdf...
Constructing Javadoc information...
[-doclet, BADoclet]
[-docletpath, D:\EclipseWorkspace\qpdf\BADoclet]
[-sourcepath, D:\EclipseWorkspace\AGSPdfJet\src]
[-classpath, C:\Program Files\Anywhere Software\Basic4android\Libraries\B4AShared.jar;D:\EclipseWorkspace\AGSPdfJet\lib\PDFjet.jar;D:\Android\adt-bundle-windows-x86-20140702\sdk\platforms\android-14\android.jar;C:\Program Files\Anywhere Software\Basic4android\Libraries\Core.jar]
[-public]
[-b4atarget, C:\Program Files\Anywhere Software\Basic4android\Libraries\AGSpdf.xml]
starting....
Working with class: com.ags.agspdf.AGSpdf
finish: C:\Program Files\Anywhere Software\Basic4android\Libraries\AGSpdf.xml

i've attached XML file
 

Attachments

  • AGSpdf.zip
    679 bytes · Views: 234
Last edited:
Top