{"id":28465488,"url":"https://github.com/javalin/javalin-mithril","last_synced_at":"2026-04-26T08:39:10.116Z","repository":{"id":51267435,"uuid":"367740805","full_name":"javalin/javalin-mithril","owner":"javalin","description":":rocket: Mithril.js plugin for Javalin :rocket:","archived":false,"fork":false,"pushed_at":"2021-09-14T19:00:16.000Z","size":51,"stargazers_count":4,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-06-30T20:44:22.033Z","etag":null,"topics":["java","javalin","javascript","mithril","mithriljs","ssr","web"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/javalin.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-15T22:26:04.000Z","updated_at":"2024-05-25T19:56:57.000Z","dependencies_parsed_at":"2022-08-24T07:20:31.112Z","dependency_job_id":null,"html_url":"https://github.com/javalin/javalin-mithril","commit_stats":null,"previous_names":["javalin/javalinmithril"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/javalin/javalin-mithril","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javalin%2Fjavalin-mithril","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javalin%2Fjavalin-mithril/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javalin%2Fjavalin-mithril/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javalin%2Fjavalin-mithril/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/javalin","download_url":"https://codeload.github.com/javalin/javalin-mithril/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/javalin%2Fjavalin-mithril/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32291336,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T08:29:33.829Z","status":"ssl_error","status_checked_at":"2026-04-26T08:29:18.366Z","response_time":129,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","javalin","javascript","mithril","mithriljs","ssr","web"],"created_at":"2025-06-07T05:39:28.160Z","updated_at":"2026-04-26T08:39:10.099Z","avatar_url":"https://github.com/javalin.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.javalin/javalinmithril/badge.png)\n# JavalinMithril\n## Introduction\nThis is the [Mithril.js](https://mithril.js.org/) plugin for [Javalin](https://javalin.io). It allows\nyou to use Mithril.js and Server Side Routing and State Injection to create multi-page applications\nwith javalin. It is heavily inspired by the JavalinVue plugin.\n## Usage\n### Including in your project\nAdd the following to your ```pom.xml```\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.javalin\u003c/groupId\u003e\n    \u003cartifactId\u003ejavalinmithril\u003c/artifactId\u003e\n    \u003cversion\u003e${LATEST_VERSION}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nYou will also need the webjar for Mithril.js\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.webjars.npm\u003c/groupId\u003e\n    \u003cartifactId\u003emithril\u003c/artifactId\u003e\n    \u003cversion\u003e2.0.4\u003c/version\u003e\n\u003c/dependency\u003e\n```\n### Folder Structure\nThe plugin looks for mithril JavaScript class files in ```/src/main/resources/mithril``` by default.\nThe layout of the page is in ```layout.html```, and the components are in any ```*.js``` files in the directory\nor its children.\n```\nroot\n   |_src\n     |_main\n        |_resources\n        |_mithril\n          |_layout.html\n          |_component1.js\n          |_component2.js\n          |_comonent100.js  \n```\n### Configuration\nYou need to start by enabling webjars. this is done using ```app.config.enableWebjars();```.\n Afterwards, Configuration is done using a function that consumes the configuration object. You can \nset the path to the mithril root directory, the state function which will be injected to \nevery request, the running mode(dev or not), and the Cache Header Values.\n```java\napp.config.enableWebjars();\nJavalinMithril.configure(config -\u003e {\n    config.isDev(true)\n        .stateFunction(ctx -\u003e singletonMap(\"test\", \"var\"))\n        .filePath(\"src/test/resources/mithril\");\n});\n\n```\n\nAdditionally, you will need a ```layout.html``` file which looks something like this\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n    \u003chead\u003e\n        \u003cmeta charset=\"utf8\"/\u003e\n        \u003clink rel=\"stylesheet\" href=\"/webjars/font-awesome/5.14.0/css/all.min.css\"\u003e\u003c/link\u003e\n        \u003cscript src=\"/webjars/mithril/2.0.4/mithril.min.js\"\u003e\u003c/script\u003e\n        @componentRegistration\n    \u003cbody\u003e\n        \u003cmain id=\"main-view\" class=\"app\"\u003e\n        \u003c/main\u003e\n        \u003cscript\u003e\n           m.render(document.getElementById(\"main-view\"), @routeComponent)\n        \u003c/script\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n\n```\n\nThe key is in the ```@componentRegistration``` and ```@routeComponent``` directives. Addionally,\nthere is an ```@cdnwebjar``` directive which you can use instead of just ```/webjars``` to use a \nCDN when in non-dev mode. In the case above, this would look like this :\n\n```html\n\u003clink rel=\"stylesheet\" href=\"@cdnwebjar/font-awesome/5.14.0/css/all.min.css\"\u003e\u003c/link\u003e\n\u003cscript src=\"@cdnwebjar/mithril/2.0.4/mithril.min.js\"\u003e\u003c/script\u003e\n\n```\n### Structure of JS Files\nEach js file must contain an  ```@package my.package.name;``` in the top of the file\nfollowed optionally with a set of ```@import my.package.name.MyDependencyClass;``` directives.\nThese are used by JavalinMithril to resolve dependencies between mithril files in the project\nto reduce the size of delivered File. The JS File would then look like this\n\n```js\n@package io.javalin.test;\n@import io.javalin.test.SingleComponent;\n\n\nclass ImportComponent2{\n    constructor(){\n        this.singleComponent = new SingleComponent();\n    }\n\n    view(){\n        return m(\"div\",\"Hello World\")\n    }\n}\n\n\n```\n\nThis is not a tutorial on how to use mithril.js, so you will have to see how \nclass-based components work there.\n\n### Calling a Component\nTo call a component in your javalin app, you need its Fully Qualified Class Name. \n\n```java\n\napp.get(\"/my-page\",new MithrilComponent(\"io.javalin.test.ImportComponent2\"));\n\n```\n\nYou can use roles like any other endpoint, and before/after filters apply as well.\nAdditionally, you can have a per-component state function, which overrides the values\nin the global state function if they have the same keys\n\n```java\n\napp.get(\"/my-page\",new MithrilComponent(\"io.javalin.test.ImportComponent2\",ctx-\u003e{/*Function that returns map*/}));\n\n```\n\nYou can look in the ```src/test``` directory on more config examples and usages.\n\n## Contributing \u0026 Developing\nThe project is a simple maven project. All you need is any IDE capable of working with ```pom.xml``` files\nand you are good to go. Pull Requests and Feature Requests are more than welcome - there are no specific \nformats or processes in place.\n\n## Special Notes\nThanks to [David Aase](https://github.com/tipsy/), for creating Javalin, and being open to new ideas \nand directions in the framework.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavalin%2Fjavalin-mithril","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjavalin%2Fjavalin-mithril","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjavalin%2Fjavalin-mithril/lists"}