onsdag 5. juli 2017

Android note to self #1: Google Maven repository

From support library version 25.4.0 and newer you need to add 'google' as a repository.
Application build.gradle:


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.4.0'
    compile 'com.android.support:cardview-v7:25.4.0'
    compile 'com.android.support:design:25.4.0'
    compile 'com.android.support:recyclerview-v7:25.4.0'
}
repositories {
    mavenCentral()
    google()
}

søndag 4. juni 2017

Vert.x static content

Serving static content from Vert.x can be accomplished adding the following to your router:

router.route("/static/*").handler(StaticHandler.create())


This line of code will route all requests containing the word 'static' to the webroot folder.

More info about how Vert.x serves static content:

http://vertx.io/docs/vertx-web/kotlin/#_serving_static_resources

The default folder for static content is 'webroot', but trying to find out where to place this folder got me really confused...

From this question on Stack Overflow

https://stackoverflow.com/questions/31778971/vertx-web-where-do-i-place-webroot-folder
I can tell I'm not the first person wondering (lot's of suggestions with no approved answer)...


What I've found during testing is the following:


  • Static content outside the jar
    Is being served relative to the working directory, or the directory you're in when starting the app from the command line.
    If you have a folder called 'webroot' in this directory it's content will be available through the StaticHandler object.
  • Static content inside the jar
    If you wish to serve static content directly from your jar file you need to add 'webroot' as a resource in the jar and place all the content of interest there. In the picture below I have my resources folder at the same level as the source code. Note that the folder is marked in Intellij as a resource folder.



    The index.html will be served directly when calling http://<server>/static.