Hello
What’s the correct procedure for using external java libraries or projects in CUBA?
I’m gonna need to use OptaPlanner http://www.optaplanner.org/ in my first CUBA Project.
Thanks,
Pedro
Hello
What’s the correct procedure for using external java libraries or projects in CUBA?
I’m gonna need to use OptaPlanner http://www.optaplanner.org/ in my first CUBA Project.
Thanks,
Pedro
Hi,
you can just add additional dependencies in your gradle build (build.gradle). It depends a little bit on which modules of the application you want to add the dependency. In case of Optaplanner, i would think that it is probably something that will be executed in the core module. So then, just add the following to your build.gradle:
configure(coreModule) {
//...
dependencies {
//...
compile 'org.optaplanner:optaplanner:6.4.0.Final'
}
}
Bye,
Mario
Thanks for the reply Mario.
Sorry, quite new to java, don’t really understand.
Another example, Google maps service in GitHub - googlemaps/google-maps-services-java: Java client library for Google Maps API Web Services, I also need to do geocoding.
I downloaded “google-maps-services-java-master” from that project site. Where do I put these binaries in my CUBA project.
I believe what you say is acomplished in CUBA Studio in project properties/advanced/dependencies.
But what do I import then and how to use it in my screen controlers?
I find absolutly no information in CUBA docs about this and don’t know how to proceed.
Thanks
I’m afraid there is no generic way to explain how to use Java libraries in a CUBA application. You can easily add dependencies on libraries using project properties/advanced/dependencies in Studio or directly in build.gradle as suggested by Mario. But first you need to understand on what tier you will use the library (client or middleware) - it affects in what module you should add the dependency.
And of course you will not find information in CUBA docs on how to use a particular library - there are thousands of them. However, if you explain what concrete library you need and what you want to achieve, we’ll try to help you.
As for Google Maps, there is ready-made integration in the Charts and Maps add-on, see the documentation here.
Thanks Konstantin,
It’s just as you and Mario say. I’ve got it working now. I added the dependency to the web module and now I can geocode adresses. This now runs in the screen controller:
GeocodingResult[] results = GeocodingApi.geocode(context,
event.getItem().getMorada() + ", " + event.getItem().getCodPostal() + ", PORTUGAL").await();
event.getItem().setLatitude(String.valueOf(results[0].geometry.location.lat));
event.getItem().setLongitude(String.valueOf(results[0].geometry.location.lng));
I need Geocoding and Directions, don’t think that’s covered in the ready-made integration, maybe I’m wrong?
Thank you very much
Good to hear it works. You are right, geocoding is not covered by the integration, only displaying maps.
Dear Mario David, after include
configure(coreModule) {
//...
dependencies {
//...
compile 'org.optaplanner:optaplanner:6.4.0.Final'
}
}
How I do to recognize under other class the compile recently added, in my case I use
dependencies {
compile(globalModule)
provided(servletApi)
jdbc(postgres)
testRuntime(postgres)
compile 'org.fusesource.mqtt-client:mqtt-client:1.12'
}
But when I try to use my code where use this mqtt library try to find on the web but I do not how recognize the library _
I need recompile and use Create and Update the Gradle Wrapper ?
How works the Cuba Studio ?
Please help me,
Kind regards
Dear Mario, apologyze I found the Gradle under Studio, regards
Dear Mario apologze i getting other kind of error, I use the Gradle option in studio but when Create/Update under studio, show me a lot of errors , by example
mqtt/mqttClient.java:3: error: package org.fusesource.mqtt.client does not exist
import org.fusesource.mqtt.client.BlockingConnection;
^
/media/juan/ExtraDrive1/development/2017/pnc/ezinfo/modules/web/src/net/ezmovil/ezinfo/web/cui/mqtt/mqttClient.java:4: error: package org.fusesource.mqtt.client does not exist
import org.fusesource.mqtt.client.Future;
etc…
Do you know what i need to do
I have under dependencies
configure(coreModule) {
configurations {
jdbc
dbscripts
}
dependencies {
compile(globalModule)
provided(servletApi)
jdbc(postgres)
testRuntime(postgres)
compile 'org.fusesource.mqtt-client:mqtt-client:1.12'
}
.....
Dear Mario I found the solution, was writing the dependencies under differente Configure(core) not Configue(web), where I need test.
Now I take the rigth solution, regards