Course on the MotiveWave's Java language

xerol

Active member
Joined
Apr 6, 2022
Posts
28
Likes
7
Thanks for your input... I couldn't make it work. I will try to place the jar files in the MW install folders that contain jar files. Maybe this will work? I'm, looking forward to your gradle hacks 🙏
 

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
106
Likes
46
So, I confirmed my previous post is correct--just add the .jar files for the libraries you need to 'MotiveWave Extensions/dev'. 'MotiveWave Extensions/ext'.

Here's a quick example of the manual way to do it.

Add apache commons lang to build.gradle dependencies

dependencies { ... implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0' }

Then reload gradle changes (click elephant). It will dl lib and place in 'External Libraries'

Now, add this method to one of your studies

public void printFraction() { System.out.println("Printing fraction " + Fraction.getFraction(5, 6)); }

Idea will recognize you haven't done the import. Hover your mouse over the red text and select 'Import class', then select appropriate class.

Then add a call to this method somewhere in your code

printFraction()

Now, if you compile and install this in 'dev' and try to run it, you'll get the java.lang.NoClassDefFoundError.

To fix, 1st be sure you have an 'ext' dir inside 'MotiveWave Extensions' dir. (Of course, this is the LIVE dir that MotiveWave reads your studies/libs from).

In the proj structure on left side in idea find and expand the 'External Libraries' dir.
Find and expand the Gradle: org.apache.commons:commons-lang' dir.
Right click the .jar file and choose 'Open In->Finder' for Mac (or the equivalent for Windows).

Then just copy the .jar file into the 'ext' dir.

Restart MW, and you should be good.
 
Last edited:

xerol

Active member
Joined
Apr 6, 2022
Posts
28
Likes
7
I tried it step-by-step with your instructions and it worked after a little bit of tweaking! I should mention that I'm using Ubuntu 22.04 Linux as my distro and I had to add one step:

- In order to be able to compile/deploy my study I had to additionally copy the commons-lang3*.jar to the lib folder of my project (where also the mwave_sdk.jar resides)
- I also had to create the 'ext' directory inside 'MotiveWave Extensions' dir since there was only a 'dev' directory... not sure why :unsure:

After that I was able to deploy and print the fraction.

Great work Shtick Hustler... you cracked the code 🥳 I will also try it with the nats libs... Thank you for your help 🙏
 

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
106
Likes
46
I tried it step-by-step with your instructions and it worked after a little bit of tweaking! I should mention that I'm using Ubuntu 22.04 Linux as my distro and I had to add one step:

- In order to be able to compile/deploy my study I had to additionally copy the commons-lang3*.jar to the lib folder of my project (where also the mwave_sdk.jar resides)
- I also had to create the 'ext' directory inside 'MotiveWave Extensions' dir since there was only a 'dev' directory... not sure why :unsure:

After that I was able to deploy and print the fraction.

Great work Shtick Hustler... you cracked the code 🥳 I will also try it with the nats libs... Thank you for your help 🙏

Good to hear.

Config codeblocks development 😠

😁
 

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
106
Likes
46
Here's one way to sync dependent libs to a folder with a gradle task.

I've excluded the mw jar as it's iincluded in the MW app.

This will test the task by putting the libs into a 'libs' dir in your home folder.
Delete the test 'into' line and comment out next line to put it in MW 'ext'.

configurations { externalLib.extendsFrom(implementation) } tasks.register('syncLibs', Sync) { from configurations.externalLib { into '~/libs' // into '~/MotiveWave Extensions/ext' exclude('mwave_sdk.jar') } }
 

Johnedoe

Well-known member
Joined
Feb 29, 2020
Posts
82
Likes
10
Why not just use an AI?
AI is going to kill the coder market since all you have to do is explain what you want and let the AI do the coding.
You might have to refine your explanation a time or two but hell ... Who needs to actually learn to code anymore?
 

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
106
Likes
46
Why not just use an AI?
AI is going to kill the coder market since all you have to do is explain what you want and let the AI do the coding.
You might have to refine your explanation a time or two but hell ... Who needs to actually learn to code anymore?
Is that you...Chat GPT...? :unsure:


1687111589612.jpeg
 
Last edited:

scruffyak

New member
Joined
May 29, 2023
Posts
2
Likes
0
Here's a quick tutorial.

It uses your Ant targets as-is. I may post an update to write native gradle code to do the same tasks.
May also add section to enable Kotlin code (which is trivially simple).

Let me know how it works :unsure:
thanks, this is really helpful!
 

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
106
Likes
46
I may post an update to write native gradle code to do the same tasks.

Here is some native gradle code to replace the ant task for 'deploy as jar'.

Java:
def srcDirName = "src/main/java/study_examples"
def destDir = "~/MotiveWave Extensions/dev"
def updateFiloToTouch = "${destDir}/.last_updated"

def propDir = "src/main/java/study_examples/nls"
def propDirName = "nls"

tasks.register('touchUpdateFile') {
    delete updateFiloToTouch
    outputs.files(updateFiloToTouch)
}

tasks.register('deployAsJar', Jar) {
    dependsOn(build)
    from(javaBuildDir) {
        include "**/*" into srcDirName
    }
    from(propDir) {
        include "**/*" into "${srcDirName}/${propDirName}"
    }

    archiveFileName = "examples.jar"
    destinationDirectory = file(destDir)
}

// means 'deployAsJar' task calls 'touchUpdateFile' task as soon as it finishes building & deploying .jar file
deployAsJar.finalizedBy(touchUpdateFile)

Once you paste it into your build.gradle file, and 'Update Gradle Changes', it should show up in your Idea gradle tab in 'other' section.
The path strings were written for a Mac, but may work fine on PC. If not, enter PC-appropriate strings.
 

HalTrader

Active member
Joined
May 26, 2022
Posts
34
Likes
11
Hello @Shtick Hustler ,

Thank you for your contribution. Do you have it for Maven as well?

I have a third-party library that receives external data and compiled using Maven. However it was not possible to combine it together with the MotiveWave library that runs using Ant. If you have a similar replacement for Maven for the MotiveWave library, that would be great.

I also spent some time to find how to automatically convert Maven projects to Ant, but couldn't figure it out.
 

q0paz

Active member
Joined
Aug 19, 2020
Posts
27
Likes
7
Here's a quick tutorial.

It uses your Ant targets as-is. I may post an update to write native gradle code to do the same tasks.
May also add section to enable Kotlin code (which is trivially simple).

Let me know how it works :unsure:
for anyone following up here, Shtick Hustler's samples here use Groovy as the build language.. I am feeling my way forward here, but since I decided to ditch java for kotlin, I thought I would use kotlin as the DSL too.
Here is a screenshot of my set up. I haven't added the post build stuff to my gradle, but setting up a basic kotlin project and including mwave_sdk.jar, this is how you do it (or rather what I have done so far).
I am on linux mint. The gradle in the mint repo is 4 something, so I installed the package 'sdkman' as per the documentation in the gradle.org site (https://docs.gradle.org/8.7/userguide/installation.html), and was able to install gradle very easily, which at time of this post just upgraded to 8.7
In my experience, kotlin native libraries are all better than the java versions, e.g. klogging, kotlinx-serialization-json, kotlinx-datetime and kotlin-reflect. In general, the language is far more expressive; the ability to use functional programming, coming from C# with all its great stuff like LINQ and other functional constructs, produces code which is much more easy on the eye, but especially in critical programming like trading, being able to pass as many values within your code as deterministic mathematical expressions is a huge plus. imho.
 

Attachments

  • Mwave_Gradle.png
    Mwave_Gradle.png
    152.5 KB · Views: 8
Last edited:

Shtick Hustler

Well-known member
Joined
Oct 15, 2020
Posts
106
Likes
46
I am feeling my way forward here, but since I decided to ditch java for kotlin, I thought I would use kotlin as the DSL too.

I had issues translating my groovy gradle build file to Kotlin DSL, so put it on the back burner.

I am 100% Kotlin at this point, and not looking back 🏃‍♂️ .

Glad to see there's another Kotlin coder here 👍 (if anyone else is, please let us know).
 
Top