B4J Question SOLVED??? jar in a jar?

JackKirk

Well-Known Member
Licensed User
Longtime User
I have been searching the forums, without luck, for a way to embed a referenced jar inside a jar created by the simple library compiler - can anyone point me to a relevant post - thanks in advance.
 

DonManfred

Expert
Licensed User
Longtime User
A referenced jar is what it is. A referenced jar.
You need to add a refernce to the jar in your java project which you use to compile with SLC.

The jar will be NOT INCLUDED in the jar SLC creates.
Even after compiling with SLC you need to reference it.
with
B4X:
@DependsOn(values={"referencedjar"})
in your javaproject
or with
B4X:
#additionaljar: referencedjar
in your B4X project.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
By default, AdditionalJar is compiled into your result.jar in release mode when #MergeLibraries: True is set.
You can use B4J to compile. You don't need SLC.

1777107154914.png
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
I may not have been clear - I am using B4J SLC to compile a bit of Java that wraps a jar and creates a B4J library - I'm interested in any post that discusses how to embed the wrapped jar inside the B4J SLC jar so as to avoid having to use #Additionaljar: in every project that uses the library.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I'm interested in any post that discusses how to embed the wrapped jar inside the B4J SLC jar
There is no such post

You can use the wrapped jars sourcecode inside your SLC-Project.
This way SLC can generate one jar containing your wrappercode and the source of the wrapped jar.
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
You can use the wrapped jars sourcecode inside your SLC-Project.
If I don't have the wrapped jars source? - sorry for being perdantic but I am leading to something here.
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User
If I don't have the wrapped jars source? - sorry for being perdantic but I am leading to something here.
How many classes in the Jar? You can copy them out and add the classes to your b4j wrapper. Painful but can be done - have done it before with a simple jar. Just make sure you get java project set up correctly to have the correct package names/paths/folders in your java project.

That is what I have here

 
Upvote 0

tchart

Well-Known Member
Licensed User
Longtime User
Actually, its pretty straight forward. Jar in a Jar isnt a thing but combining jars is. Jars are just zip files so you can unzip and rezip to create an Uber (or Fat) Jar.

Example below of a JDBC jar I created that combines all the dependencies. You'd need to do this after you ran SLC.

Been a while but from memory I did run into issues with B4J and the things in the root of the Jar (eg LICENSE, NOTICE etc) this is why they get deleted.

Also, I did try some 3rd party tools (google jar combiner) to do this but found they didn't tidy up these things which caused downstream issues - there's likely a post on the forum somewhere.

B4X:
@echo off

cd /d %0\..

SET Lib_Name=iotdb-jdbc-0.12.2-all-deps.jar

rmdir /S /Q all
del /Q %Lib_Name%

mkdir all

for %%f in (.\libs\*.jar) do (
    echo %%f
    C:\Apps\7-zip\7z.exe x %%f -oall -r -aoa -y
)

del /Q .\all\*.class
del /Q .\all\*.html
del /Q .\all\LICENSE
del /Q .\all\NOTICE

rmdir /S /Q .\all\META-INF

C:\Apps\7-Zip\7z a %Lib_Name% .\all\*

copy %Lib_Name% C:\Apps\B4J\AdditionalLibraries\%Lib_Name%

pause
 
Upvote 0

JackKirk

Well-Known Member
Licensed User
Longtime User
Thank you everyone, I think you collectively have confirmed there is no common, simple solution in the forums so I can post a solution I have found here with some hope it is a positive contribution.
 
Upvote 0
Top