You are not logged in.

Dear visitor, welcome to Jabaco - Community. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

1

Monday, March 31st 2014, 9:28pm

How to write a Jabaco app, where the routines are callable from elsewhere.

Hi,

How should a Jabaco app be written, such that it's procedures are callable from Java or Groovy or Jabaco or any jvm-based application?

In other words, I want to create a number of subroutines, in a Jabaco app - STATIC routines which don't require object instantiation - generate the jar, and then use those subroutines from Java.


How does such a callable Jabaco app get written, so that its subroutines are visible elsewhere? The parent Java/Groovy/Clojure/Jabaco part I understand; but am not clear about the format of the code in the callable Jabaco project.

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

2

Tuesday, April 1st 2014, 12:48am

How should a Jabaco app be written, such that it's procedures are callable from Java or Groovy or Jabaco or any jvm-based application?
??? If you set your SUBs and FUNCTIONs to PUBLIC and not to PRIVATE, they are automatically accessable from every JVM-language.

Quoted

In other words, I want to create a number of subroutines, in a Jabaco app - STATIC routines which don't require object instantiation - generate the jar, and then use those subroutines from Java.
That is possible. Where is the problem, to do so?

Quoted

How does such a callable Jabaco app get written, so that its subroutines are visible elsewhere?
As I have said, you have set them to PUBLIC.

Quoted

The parent Java/Groovy/Clojure/Jabaco part I understand; but am not clear about the format of the code in the callable Jabaco project.


I really don't see the problem, to do so.

For example:

Create a "new Project" and select "Class Library" as new project type.

As default, there is now the only class Class1.

Remove this text:

Jabaco Source

1
2
3
4
Private Sub Class_Initialize()
   ' [Your Source] ...

End Sub
and write instead:

Jabaco Source

1
2
3
Public Static Sub SayHello()
  MsgBox "Hello Jabaco-folks!"
End Sub


In the properties set as Namespace for example "myNameSpace".
So that the folloing properties exists:

Source code

1
2
3
4
5
(Access): Public
(Name): Class1
(NameSpace): myNameSpace
(SuperClass): java/lang/Object
(Type): Class


Thats it. Now compile it:
Click in the menu "File" -> "Make Project..."
Select as Filetype "Jar-File". And use as FileName for example "MyClass.jar". Save that file on any location you want.

Now access it from Java.
Go in that directory, in which you have saved MyClass.jar and create (for example with notepad.exe) there the file "JavaTest.java", which have the following code:

Source code

1
2
3
4
5
6
7
import myNameSpace.*;

public class JavaTest {
  public static void main(String[] args) {
    Class1.SayHello();
  }
}


I assume, that you have installed the JDK on your computer.

So, then write in the commandline

Source code

1
javac.exe -cp MyClass.jar;. JavaTest.java

Now you can start it with

Source code

1
java.exe -cp MyClass.jar;. JavaTest


Then there opend a dialog-window,m in which stands "Hello Jabaco-folks". Thats the thing, you have written in Jabaco.

Greatings
theuserbl

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

3

Tuesday, April 1st 2014, 2:59am

.."Create a "new Project" and select "Class Library" as new project type..


This is the reason I was asking, theuserbl. I had tried creating an ordinary console project, making the routines public as you are saying.

I assumed that Jabaco generated a type of class, from this project, from which you could call a subroutine like you would call a static method. But when these subroutines calls were coded, it wouldn't compile.


So you actually need to create a class library? Ok, will do that, thanks theuserbl.

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

4

Tuesday, April 1st 2014, 10:56am

This is the reason I was asking, theuserbl. I had tried creating an ordinary console project, making the routines public as you are saying.
It is possible with all other projects, too. But if you choose "Console Application", you already have a running program. So, you have more in it, then you needed.

Quoted

I assumed that Jabaco generated a type of class, from this project, from which you could call a subroutine like you would call a static method. But when these subroutines calls were coded, it wouldn't compile.
Don't know, what you mean.

Quoted

So you actually need to create a class library?
No. With the other types, it is possible, too.
For example, as you says with a "Console Application".

Then the only existing class is called Module1.

Jabaco set everything in a Jabaco-Module to static. So you don't need to write it there.
Then you can write this one in Mosule1:

Jabaco Source

1
2
3
4
5
6
7
Public Sub main(ByJava args() As String)
   SayHello()
End Sub

Public Sub SayHello()
  MsgBox "Hello Jabaco-folks!"
End Sub

It is now already a working Jabaco-Application.
Compile it, for example to "JabCon.jar".

Again create a file called "JavaTest.java":

Source code

1
2
3
4
5
public class JavaTest {
  public static void main(String[] args) {
    Module1.SayHello();
  }
}


Compile the program

Source code

1
javac.exe -cp JabCon.jar;. JavaTest.java
and running it:

Source code

1
java.exe -cp JabCon.jar;. JavaTest


If you want, you can do the same with "SDI Application", "MDI Application" or "Web Applet".

Greatings
theuserbl

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

5

Tuesday, April 1st 2014, 11:44am

Ok, then I must have done something wrong. Your examples are equivalent to what I tried.

Yes, I understand about the console project being overkill, because it includes the kitchen sink. The class library does make more sense.

Easiest way through this, is to just use your examples as a template, and start from there.

Thanks for the assist, theuserbl.

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

6

Tuesday, August 26th 2014, 3:24pm

Source code

1
2
3
Public Static Sub SayHello()
  MsgBox "Hello Jabaco-folks!"
End Sub



Although this works as a sub, what if you want to write a function, to be callable from another app?

For example, in the same application where your SayHello example works ( Test.SayHello() works fine, thanks ), I tried

Source code

1
2
3
4
5
Public Static Function GetTestString() As String
Dim sTestString As String
sTestString = "What the...?"
GetTestString = sTestString
End Function


But, when it's called,


Source code

1
2
Dim sTestString As String
sTestString = Test.GetTestString()


, Jabaco complains that the GetTestString function is not defined.

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

7

Tuesday, August 26th 2014, 4:03pm

Don't know, what you have a problem with that.

Have added a Function-Test project, which shows, that everything works fine.
theuserbl has attached the following file:
  • FuctionTest.zip (2.95 kB - 369 times downloaded - latest: Mar 9th 2024, 4:04pm)

jbExplorer

Trainee

  • "jbExplorer" started this thread

Posts: 111

Date of registration: Mar 18th 2013

  • Send private message

8

Tuesday, August 26th 2014, 4:33pm

Don't know, what you have a problem with that.

Have added a Function-Test project, which shows, that everything works fine.

Don't know, what you have a problem with that.

Have added a Function-Test project, which shows, that everything works fine.

theuserbl,

Never mind. I exited from the calling app, went back in, and everything fine, thanks.

Rate this thread
WoltLab Burning Board