Java Question Problem making a library from lots of separate .java files

aedwall

Active Member
Licensed User
Longtime User
I have a lot of .java files, most which contain a public class. I want to make a library called SWE_Lib which will contain all the routines in all these separate .java files. I get the feeling that I have to modify these .java files and add:

import anywheresoftware.b4a.BA.ShortName;
@ShortName("TransitCalculator")

after the package name, which is "package v176".

1) Where does the "anywheresoftware.b4a." in #1 above come from? Is this import statement needed? In my setup wouldn't I just use "import BA.ShortName;"? But when I do any of this in my TransitCalculator.java script, for instance, then Eclipse gives me an error and will not run javadoc.

I want to name my library "SWE_Lib", but the code below does not run - it can't find "SWE_Lib".

'Activity module
Sub Process_Globals
Dim fl As FirstLib 'this works fine
Dim swe As SWE_Lib 'compiling does not recognize the library
End Sub

Sub Activity_Create(FirstTime As Boolean)
Log(fl.multiply(27)) 'this works fine
' Log(swe.swedate(22.09.1949))
End Sub


I attach my Eclipse Workspace in case anyone wants to have a go with the files I am working with. Well, I can't attach the whole thing because the forum has a file size limit.

.java files in - C:\Program Files\eclipse\Workspace\SwissEphLib\src\v176
Basic4android is installed in - C:\Program Files\Basic4android
Eclipse is installed in - C:\Program Files\eclipse
Eclipse workspace installed in - C:\Program Files\eclipse\Workspace
Java jdk installed in - C:\Program Files\Java\jdk1.6.0_26
Java itself installed in - C:\Program Files\Java\jre6
Running XP SP3.

Thank you.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I recommend you to see the video tutorial: Video tutorial - Creating a simple library

You should reference BAShared.jar.

As of Basic4android v1.8 you can use the DependsOn annotation and reference other jar files. This allows you to make a jar file with all your existing java files and then use it from your library.
You will need to copy both jar files to the libraries folder.
 

aedwall

Active Member
Licensed User
Longtime User
I have watched the tutorial many times. But it is only a simple tutorial that does not cover specifics like you just mentioned. I did reference "BAShared.jar" because it said to, but there was nothing mentioned of what you could do with it. I will have to look up "DependsOn annotation" and see if I can make sense out of it. I hear what you are saying by "This allows you to make a jar file with all your existing java files and then use it from your library.", but I do not understand how to do it or what to do with it. Another specific example would be helpful. Okay, back to the classroom. Thank you.

I see it says "NEW - @DependsOn - An array of strings with additional jar files that will be referenced when this library is referenced. Removes the need to "dummy" xml files." Not sure what "dummy xml files" means" from a practical standpoint. I looked through all the source code I have and nowhere is there a reference to "@DependsOn" that I can learn from.
 
Last edited:

aedwall

Active Member
Licensed User
Longtime User
I put the following in my FirstLib example library (FirstLib.java):

import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.BA.DependsOn;

@Version(1.0f)
@ShortName("FirstLib")
@DependsOn("swissephSWI-1.76.00-03.jar")

and Eclispse gives me an error (red 'x'). The error reads:

Multiple markers at this line
- The attribute value is undefined for the annotation type
BA.DependsOn
- The annotation @BA.DependsOn must define the attribute values

I don't know what this means or how to correct it. Can anyone help?

Perhaps I fixed it with this:

@DependsOn(values = { "swissephSWI-1.76.00-03.jar" })

The error message in Eclipse goes away. So I make my .jar file and my .xml file for FirstLib.
But perhaps FirstLib.jar has to include all the contents of swissephSWI-1.76.00-03.jar?
I don't know.
 

Attachments

  • ScreenShot_01-27-12 01.jpg
    ScreenShot_01-27-12 01.jpg
    27.7 KB · Views: 243
Last edited:

aedwall

Active Member
Licensed User
Longtime User
I make my library, refresh it, and try to compile. I get an error saying a referenced library is missing: swissephswi-1.76.00-03.jar

Sub Process_Globals
Dim fl As FirstLib
End Sub

Sub Activity_Create(FirstTime As Boolean)
Log(fl.multiply_by_2(27))
End Sub

Boy, there's got to be a simpler way.

So I create a "swissephSWI-1.76.00-03.xml" file with this contents:

<?xml version="1.0" encoding="UTF-8"?>
<root>
<doclet-version-NOT-library-version>1.00</doclet-version-NOT-library-version>
<version>1.0</version>
</root>

The swissephSWI-1.76.00-03 library displays in my list of libraries, but it still won't compile.

The fix is to replace:

@DependsOn(values = { "swissephSWI-1.76.00-03.jar" })

with

@DependsOn(values = { "swissephSWI-1.76.00-03" })
 

Attachments

  • ScreenShot_01-27-12 01.jpg
    ScreenShot_01-27-12 01.jpg
    23.4 KB · Views: 269
Last edited:
Top