Java Question Referncing wrapped libs

HotShoe

Well-Known Member
Licensed User
Longtime User
I have written a version of the jcifs lib because I needed more functionality than the current one. It works fine, except I have to load Erels SMB lib or it reports "jcifs.jar doesn't exist". So the question is, how do I get my version of the lib to work stand alone like Erels does? How do I pack jcifs into the lib since it isn't on most android devices by default?

I have tried importing it into the bin dir of the lib project, but that did no good. it is already in the Referenced libs section of the eclipse project, and of course, it is imported into the project.

Thanks,

--- Jem
 

warwound

Expert
Licensed User
Longtime User
Try this.

Right-click the project in Eclipse.
Select Build Path > Configure Build Path.

On the window that appears click the Order and Export tab.
Check the checkbox for jcifs.jar and try re-compiling your project.

Martin.
 

HotShoe

Well-Known Member
Licensed User
Longtime User
Thanks for the reply. I tried the above, but still get the:

src\org\mlsoft\adt\main.java:4675: error: package jcifs.smb does not exist

message during compile.

--- Jem
 

warwound

Expert
Licensed User
Longtime User
You could try manually opening your library .jar file with a program such as WinRAR and doing the same with the jcifs.jar file.

Drag the contents of jcifs.jar to your library .jar and close it.

Some forum members have reported success doing that.

But watch that you have permission to distribute jcifs.jar with your library...

Martin.
 

HotShoe

Well-Known Member
Licensed User
Longtime User
No I didn't. Does that pack the external lib into my current one? I have searched. but can't find any documentation on what @dependson actually does. It would be great if someone or a group would do a reference guide on how to do libraries for b4a. I mean a nice reference that describes the thongs that b4a needs that are not needed for pure java projects.

Warwound: Thanks, copying to my jar file works. I no longer have to check the SMB lib in a project to use mine.

--- Jem
 

HotShoe

Well-Known Member
Licensed User
Longtime User
libs

Sorry Erel, my last reply sounded a bit snotty. I would like to see more docs concerning things specific to b4a libraries. I have a bad habit of needing to know how things work, but more importantly, why things work.

I would be more than happy to write docs, I have a long background in writing docs and a few years of teaching. First, I have to learn how things work myself though... :) BTW, I did add the @DependsOn tag, but it didn't seem to change the availability of the jcifs lib.

--- Jem
 

warwound

Expert
Licensed User
Longtime User
If you use the DependsOn attribute in your library like this:

B4X:
@DependsOn(values = { "jcifs" })

(Assuming the library file you want to include is named jcifs.jar - notice you don't include the file extension in the DependsOn attribute).

Then jcifs.jar must be included in your B4A additional libraries folder - along with your library .jar and .xml files.

As you've found it doesn't instruct Eclipse to package the jcifs.jar file with your library .jar file.

Manually adding jcifs.jar to your library .jar file using WinRAR works as you have found BUT if the jcifs.jar file gets updated at any point in the future then your library will contain an old version of jcifs.jar, a minor disadvantage of that solution.

If you have the source code for a library that you want compiled into your B4A library then that is possible.

You create a new project in Eclipse and import the source code for the library you want to add to your B4A library.

Then in your B4A library build path, change the reference to the other library from the .jar file to the new project you just created.
(Reference the source NOT the .jar file).

Click the Order and Export tab in build path and check the checkbox for the source code library project.
(As i suggested you try in my earlier post).

You should now find that your compiled B4A library is compiled with the other library included.
No need for DependsOn or WinRAR.

Martin.
 

HotShoe

Well-Known Member
Licensed User
Longtime User
Thanks Martin, that seems to work fine! That's a much better solution than copying files to the .jar. I knew there had to be a way it's just holding your mouth right.. Thanks again to both you and Erel.

--- Jem
 

HotShoe

Well-Known Member
Licensed User
Longtime User
Another question

This may or may not be related, but I switched modes to release after getting the smb routines working in my file manager and now I get an "Unable to connect to network" error.

If I switch back to debug, recompile and run, it works just fine again. What's release mode doing different than debug mode in program execution?

Here's the stack trace from 4.0.3 but it does the same on 2.3.5

jcifs.smb.SmbException: Failed to connect to server
java.net.UnknownHostException: ..__MSBROWSE__.<01>
at jcifs.netbios.NbtAddress.doNameQuery(NbtAddress.java:317)
at jcifs.netbios.NbtAddress.getByName(NbtAddress.java:422)
at jcifs.netbios.NbtAddress.getByName(NbtAddress.java:403)
at jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:850)
at jcifs.smb.SmbFile.connect(SmbFile.java:951)
at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
at jcifs.smb.SmbFile.doNetServerEnum(SmbFile.java:1914)
at jcifs.smb.SmbFile.doEnum(SmbFile.java:1734)
at jcifs.smb.SmbFile.listFiles(SmbFile.java:1715)
at jcifs.smb.SmbFile.listFiles(SmbFile.java:1648)
at Fileslib.MLsmb.SmbList(MLsmb.java:238)
at org.mlsoft.adt.main._smblist(main.java:3211)
at org.mlsoft.adt.main._lanbtn_click(main.java:2364)
at org.mlsoft.adt.main._menubtn_click(main.java:2535)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:124)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:120)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:49)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14109)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
at jcifs.smb.SmbFile.connect0(SmbFile.java:882)
at jcifs.smb.SmbFile.doNetServerEnum(SmbFile.java:1914)
at jcifs.smb.SmbFile.doEnum(SmbFile.java:1734)
at jcifs.smb.SmbFile.listFiles(SmbFile.java:1715)
at jcifs.smb.SmbFile.listFiles(SmbFile.java:1648)
at Fileslib.MLsmb.SmbList(MLsmb.java:238)
at org.mlsoft.adt.main._smblist(main.java:3211)
at org.mlsoft.adt.main._lanbtn_click(main.java:2364)
at org.mlsoft.adt.main._menubtn_click(main.java:2535)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:136)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:124)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:120)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:49)
at android.view.View.performClick(View.java:3511)
at android.view.View$PerformClick.run(View.java:14109)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
 

warwound

Expert
Licensed User
Longtime User
When debug mode is used you'll find that android.permission.INTERNET is automatically added to your manifest file as the debugger requires that permission.

In release mode that permission is now missing.

Use the manifest editor to add it to your application:

B4X:
'End of default text.
AddPermission(android.permission.INTERNET)

Martin.
 
Last edited:

HotShoe

Well-Known Member
Licensed User
Longtime User
Wow, now I know I'm over thinking this stuff. I can't believe I missed that. I added the permission to the library, and now all is right with the world again. Thanks Martin.

--- Jem
 

corwin42

Expert
Licensed User
Longtime User
If your library always needs this permission you should add it to your library.

B4X:
@Permissions(values={"android.permission.INTERNET"})

Edit: Oh sorry, I just see in your comment that you did that exactly
 

HotShoe

Well-Known Member
Licensed User
Longtime User
I'm re-asking this by Erel's request. I thought this was sorted, but I had the jcifs.jar in my additional libraries location so it has been compiling fine. I still need to know how to make the lib work without requiring the jcifs library on the library users machine like Erel's smb library does.

I have the @DependsOn in the lib, I have added it to the export options in eclipse. I have tried adding a new project using the jcifs source and adding it to my project, but it is either not an eclipse project or I am missing something.

The library has no problems being created, but unless I have the jcifs.jar in a b4a library directory, the b4a app won't compile. I get a missing jcifs error.

There has to be an answer...

Thanks,

--- Jem
 

warwound

Expert
Licensed User
Longtime User
If you want your library to be self-contained and have no dependancies on other external libraries you must have the source of the other library or libraries available within Eclipse when you compile your library.

The source code for jcifs does not look like it is a standard Eclipse project but you should still be able to import it into Eclipse.

https://www.google.co.uk/search?q=eclipse+import+non+eclipse+source&ie=UTF-8&oe=UTF-8

There's various ways to do that as you can see if you look at that link.

Maybe you could find a way to simply get Eclipse to compile your library with the external jar automatically included:

https://www.google.co.uk/search?q=eclipse+include+external+jar+in+export&ie=UTF-8&oe=UTF-8

This link looks like a simple solution but i have no idea if actually works:

Linux & Java tips: include external jar into your own exported jar

But assuming you cannot get Eclipse to compile your library with the external jar included and also assuming that you have the source code for the external library available as a project in Eclipse you need to modify your library project's build path as explained in post 9 of this thread.

The best option if you can get it to work is to get Eclipse to compile your library with the external jar included.
That way if the external jar is updated you can simple change the jar and re-compile your library - no need to delete old source and import the new source for the external library.

Martin.
 

warwound

Expert
Licensed User
Longtime User
That looks interesting, i see the page you linked to says:

A simple version of Fat-Jar is integrated into Eclipse 3.4 as "Runnable Jar File" Export Wizard

I use Eclipse 3.6.2 and never even noticed that export option before.

I'll try to remember to give it a try next time i compile a library.

Martin.
 

HotShoe

Well-Known Member
Licensed User
Longtime User
Martin,

I tried this solution but had no joy. It seems there needs to be some mechanism to allow the included jar to be seen that b4a does not do. For now I am just including the download link to the required lib.

--- Jem
 

warwound

Expert
Licensed User
Longtime User
Did you try each of the three options?

I have Eclipse 3.6.2 and the Export > Runnable JAR file has three options, see attached screenshot.

I'm not sure what the Launch configuration option is, there's a help page here which suggests 'Java application' but nothing appears in the drop down list for me.

Martin.
 

Attachments

  • eclipse_export_jar.png
    eclipse_export_jar.png
    43 KB · Views: 307
Top