Android Tutorial Custom class templates

Erel

B4X founder
Staff member
Licensed User
Longtime User
Starting from B4A v8.0 it is possible to include custom class templates inside your libraries. Note that it will also be added to B4J and B4i.

You can include multiple templates.

There are two steps:
1. Add the template files to the project. File extension must be .b4x_excluded.
For example B4J jServer library now includes the three server handlers:

SS-2018-03-12_16.07.14.png


2. Declare them with the new @CustomClasses annotation:
B4X:
@CustomClasses(values = {
       @CustomClass(name = "Server Handler", fileNameWithoutExtension = "server_handler"),
       @CustomClass(name = "Server Filter", fileNameWithoutExtension = "server_filter"),
       @CustomClass(name = "Server WebSocket", fileNameWithoutExtension = "server_websocket")
})
@Version(2.90f)
@ShortName("Server")
@DependsOn(values={"jetty_b4j", "c3p0-0.9.5.2", "c3p0-oracle-thin-extras-0.9.5.2"
       ,"mchange-commons-java-0.2.11", "json"})
public class ServerWrapper {

If you are using SLC to build the library then you should put the files in the 'additional' folder.

The jar structure should be:

SS-2018-03-12_16.10.22.png


Make sure to use BADoclet v1.07+. The updated doclet is available inside SLC.

The generated XML should end with:
B4X:
    <customClass>name:Server Handler, filenamewithoutextension:server_handler</customClass>
    <customClass>name:Server Filter, filenamewithoutextension:server_filter</customClass>
    <customClass>name:Server WebSocket, filenamewithoutextension:server_websocket</customClass>
</root>

See this link if you want to create a custom class template without building a library: https://www.b4x.com/android/forum/threads/custom-class-templates-in-b4a.90552/#post-572445
 
Last edited:

Star-Dust

Expert
Licensed User
Longtime User
So it is possible to create it only in Java. It is not possible with the B4A libraries
 
Top