<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tadayoshi Sato on Medium]]></title>
        <description><![CDATA[Stories by Tadayoshi Sato on Medium]]></description>
        <link>https://medium.com/@tadayoshi-sato?source=rss-b42746ddc587------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*IWvpf-Iebbb9avsMe3t6zQ.jpeg</url>
            <title>Stories by Tadayoshi Sato on Medium</title>
            <link>https://medium.com/@tadayoshi-sato?source=rss-b42746ddc587------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 17:38:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tadayoshi-sato/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[JBang: Scripting Java for a New Era of Development]]></title>
            <link>https://tadayoshi-sato.medium.com/jbang-scripting-java-for-a-new-era-of-development-1636a1913ea8?source=rss-b42746ddc587------2</link>
            <guid isPermaLink="false">https://medium.com/p/1636a1913ea8</guid>
            <category><![CDATA[script]]></category>
            <category><![CDATA[scripting]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[jbang]]></category>
            <dc:creator><![CDATA[Tadayoshi Sato]]></dc:creator>
            <pubDate>Wed, 18 Jun 2025 17:10:13 GMT</pubDate>
            <atom:updated>2025-06-19T06:09:54.483Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-Sjdzz40LCUzNIQ4" /><figcaption>Photo by <a href="https://unsplash.com/@nolanissac?utm_source=medium&amp;utm_medium=referral">Nolan Issac</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>JBang is a powerful tool that enables Java code to be executed directly as scripts.</p><p><a href="https://www.jbang.dev/">JBang</a></p><p>Having used JBang for over four years, I’ve come to realise that it’s far more than just another utility for running compiled languages like scripts. It represents a new development environment with the potential to fundamentally transform Java development.</p><p>This article will explore JBang’s capabilities and how it’s fostering a new ecosystem as an innovative Java development and distribution platform.</p><h3>Why JBang?</h3><p>When developing in Java, there are often situations where you need to quickly test the behaviour of a library or API.</p><p>You wouldn’t want to integrate such test code directly into your main project. Typically, this involves creating a new, separate project solely for testing. This process usually entails setting up a Java project from an IDE or command line, then modifying pom.xml or build.gradle to add the necessary project configurations and dependencies, before you can even begin writing your test code.</p><p>While Java’s build and execution are remarkably fast and efficient, the initial project setup can be somewhat cumbersome. JBang, however, streamlines this by allowing you to generate a single script from the command line, enabling you to immediately start coding in your preferred editor, such as Vim or Emacs.</p><p>As you become more proficient with JBang, you’ll discover that you can condense an entire project’s worth of information into a single script. Essentially, JBang allows you to write Java code with the paradigm of “one script equals one project.”</p><p>Equally important is that while JBang offers the convenience of scripting, its execution runtime remains the same JVM used in a production environment. This means you can begin development and testing with ease, and the executable code produced retains the same speed and robustness as in a production setting.</p><p>Furthermore, JBang is well-equipped with robust IDE integration and efficient script distribution methods, providing a clear path to evolve from quickly written scripts to full-fledged applications. This also makes it highly suitable for microservices development.</p><p>Thus, continued use of JBang reveals it to be more than just a convenient tool; it emerges as a next-generation Java development environment. It’s an innovative platform that enables starting small and seamlessly evolving into full-scale development, or effectively building a knowledge base for sharing sample and test code within a team.</p><h3>Installation</h3><p>JBang offers various installation methods, all detailed on its download page:</p><p><a href="https://www.jbang.dev/download/">Download</a></p><p><strong>NOTE:</strong> The recommended method is <a href="https://sdkman.io/">sdkman</a>. sdkman is a package manager specifically designed for Java, enabling you to install and manage not only JBang but also various JDK distributions from different vendors, as well as other Java-based command-line tools like Maven, Gradle, Spring Boot and Quarkus CLI.</p><p><strong>curl</strong></p><pre>curl -Ls https://sh.jbang.dev | bash -s - app setup</pre><p><strong>sdkman</strong></p><pre>sdk install jbang</pre><p><strong>homebrew</strong></p><pre>brew install jbangdev/tap/jbang</pre><h3>Getting Started</h3><p><strong>Init</strong></p><p>Use the init command to create a new script file.</p><pre>jbang init hello.java</pre><pre>///usr/bin/env jbang &quot;$0&quot; &quot;$@&quot; ; exit $?<br><br><br>import static java.lang.System.*;<br><br>public class hello {<br><br>    public static void main(String... args) {<br>        out.println(&quot;Hello World&quot;);<br>    }<br>}</pre><p>While you can certainly start writing code from scratch, init generates a script pre-embedded with the necessary conventions to execute it directly like a shell script.</p><p><strong>Run</strong></p><p>The script generated by init can be executed directly, just like a standard shell script.</p><pre>./hello.java</pre><p>Alternatively, you can run it using the jbang command:</p><pre>jbang hello.java</pre><p>JBang also supports <a href="https://www.jbang.dev/documentation/guide/latest/usage.html">many other interesting ways to run scripts</a>. For instance, you can upload a script to Gist and execute it directly from its URL:</p><pre>jbang https://gist.github.com/tadayosi/43dc74403c7acce5384c23129fbeb918</pre><p><strong>Build</strong></p><p>You can also compile your JBang script into a JAR file. Once built, this JAR can be executed in environments where JBang is not installed.</p><pre>jbang build --build-dir &lt;path&gt; hello.java</pre><p><strong>Native build</strong></p><p>If GraalVM is installed, native compilation is also an option. This is particularly effective for use cases where execution speed or a minimal footprint are critical, such as in embedded environments.</p><pre>jbang build --build-dir &lt;path&gt; --native hello.java</pre><h3>The Secret Behind the File Header</h3><p>Examining the script generated by init, you&#39;ll notice the following file header:</p><pre>///usr/bin/env jbang &quot;$0&quot; &quot;$@&quot; ; exit $?</pre><p>This technique mimics the shell script’s shebang #!, as explained in the Go Cookbook.</p><p><a href="https://golangcookbook.com/chapters/running/shebang/">Running a file via a shebang line</a></p><p>In essence, when the file is executed as a script from the shell, the first line is read, and the triple slashes (///) are interpreted as a single path separator. This results in env being called with an absolute path, equivalent to:</p><pre>/usr/bin/env jbang &quot;hello.java&quot; &quot;&quot;; exit $?</pre><p>Subsequently, when the jbang command is recursively invoked, the leading double slashes (//) are treated as a Java comment and ignored, allowing the remainder of the file to be executed as valid Java source code.</p><p>This is the ingenious mechanism behind the JBang script file header.</p><h3>Importing Dependencies</h3><p>One of Java’s greatest strengths is its rich ecosystem of libraries. JBang, naturally, allows you to fully leverage this advantage.</p><p>By utilising the DEPS comment tag within the file header, you can effortlessly import dependent libraries.</p><pre>//DEPS org.slf4j:slf4j-api:2.0.17<br>//DEPS org.slf4j:slf4j-simple:2.0.17</pre><p>Dependencies are specified using the familiar Maven GAV (Group ID, Artifact ID, Version) format, which will be well-known to those accustomed to Gradle.</p><h3>Leveraging BOMs</h3><p>JBang also supports loading a BOM (Bill of Materials) by appending @pom after the version of a dependent library.</p><pre>//DEPS org.slf4j:slf4j-bom:2.0.17@pom<br>//DEPS org.slf4j:slf4j-api<br>//DEPS org.slf4j:slf4j-simple</pre><p>In this example, the SLF4J BOM is loaded. Consequently, sub-components like slf4j-api and slf4j-simple can be imported without explicitly specifying their versions.</p><h3>Maven Central Search (mcs)</h3><p>While not directly part of JBang, this tool is invaluable for looking up dependent libraries when working with JBang.</p><p><a href="https://github.com/mthmulders/mcs">GitHub - mthmulders/mcs: Search the Maven Central Repository from your command line!</a></p><p>The Maven Central Search (mcs) command enables you to search for a portion of a Maven coordinate and retrieve the latest version list directly from the Maven Central repository.</p><pre>$ mcs org.slf4j:slf4j-api<br>...<br><br>  Coordinates                        Last updated<br>  ===========                        ============<br>  org.slf4j:slf4j-api:2.0.17         26 Feb 2025 at 01:43 (JST)<br>  org.slf4j:slf4j-api:2.0.16         10 Aug 2024 at 18:15 (JST)<br>  org.slf4j:slf4j-api:2.0.15         08 Aug 2024 at 21:59 (JST)<br>  ...</pre><h3>Repositories</h3><p>By default, JBang resolves Maven dependencies from Maven Central. However, if you need to reference internal repositories in an offline corporate environment, or use a specific repository from a product vendor, you can specify it using the REPOS comment tag.</p><pre>//REPOS central,jitpack,myrepo=https://myrepo.local/maven</pre><p>In addition to the default central, google, and jitpack, you can define your own repositories as myrepo=https://myrepo.local/maven using a repository ID and URL pair.</p><ul><li>central — <a href="https://repo1.maven.org/maven2/">https://repo1.maven.org/maven2/</a></li><li>google — <a href="https://maven.google.com/">https://maven.google.com/</a></li><li>jitpack — <a href="https://jitpack.io/">https://jitpack.io/</a></li></ul><h3>Other Tags</h3><p>JBang supports numerous other tags, but here are some of the most significant ones, in my opinion:</p><pre>//JAVA 21+<br><br>//COMPILE_OPTIONS --enable-preview --verbose<br><br>//RUNTIME_OPTIONS --add-opens java.base/java.net=ALL-UNNAMED<br><br>//NATIVE_OPTIONS -O1 -g<br><br>//PREVIEW<br><br>//MODULE &lt;module-name&gt;<br><br>//MAIN &lt;main-class-name&gt;<br><br>//MANIFEST Built-By=JBang<br><br>...</pre><p>The JAVA tag, in particular, allows you to explicitly specify the Java version to be used. Optionally, appending + indicates the minimum required Java version. This is particularly useful when you want to experiment with the latest Java syntax in your scripts.</p><h3>Multiple Files</h3><p>Beyond importing dependent libraries, the ability to load other source files from a script is crucial. Certain frameworks, such as logging, Spring Boot, or Quarkus, often require specific resource files to be loaded as configuration.</p><p>To load files, use the SOURCES comment tag for Java source files and the FILES comment tag for resource files.</p><pre>//SOURCES GreetingService.java<br>//SOURCES model/Person.java</pre><pre>//FILES application.properties<br>//FILES META-INF/resources/index.html=index.html</pre><p>For resource files, you can also use the = syntax, as in META-INF/resources/index.html=index.html, to load the local file on the right (index.html) to the specified path on the left (META-INF/resources/index.html). This is particularly useful when resource files need to be placed under META-INF, as is often the case with Jakarta EE.</p><h3>IDE Integration</h3><p>When working with JBang scripts that utilise dependent libraries and multiple files, robust IDE support, such as code completion, becomes essential. The jbang edit command facilitates this by allowing you to launch a specified IDE directly from JBang.</p><pre>jbang edit greet.java</pre><p>Using the --sandbox option creates a temporary project directory and opens the IDE within it. The script, along with any referenced Java source and resource files, are symlinked into this sandbox project. This ensures that any modifications made in the IDE are directly reflected in your original source files.</p><pre>jbang edit --sandbox greet.java</pre><p>For more advanced workflows, the --no-open option prevents the IDE from launching automatically, providing only the path to the sandbox project. You can then pass this path to your preferred IDE&#39;s command-line interface to open and edit the project.</p><pre>$ jbang edit --sandbox --no-open greet.java<br>[jbang] Creating sandbox for script editing greet.java<br>/Users/tasato/.jbang/cache/projects/greet.java_jbang_6df7e8896068e72b39f45fca68fbb4c219e412c50af646bdfbfaa1472c26e429/greet<br><br>$ idea `jbang edit --sandbox --no-open greet.java`</pre><h3>IDE Plugins</h3><p>Beyond the inherent Java support in IDEs, installing JBang extensions or plugins further enhances the development experience. These plugins enable seamless integration, allowing you to:</p><ul><li>Set up dependent libraries from DEPS (via Synchronize JBang).</li><li>Directly run JBang scripts (via Run JBang).</li><li>Debug JBang scripts (via Debug JBang).</li></ul><p>Here are the official extensions/plugins for VS Code and IntelliJ:</p><ul><li><a href="https://marketplace.visualstudio.com/items?itemName=jbangdev.jbang-vscode">VS Code</a></li><li><a href="https://plugins.jetbrains.com/plugin/18257-jbang">IntelliJ</a></li></ul><h3>Exporting Projects</h3><p>Should you decide to transition from a JBang script to a conventional Java project, JBang provides export functionality to convert your script into a Maven or Gradle project.</p><pre>jbang export maven app.java<br>jbang export gradle app.java</pre><p>This export process includes the specified script, any referenced Java source and resource files as project source code, and automatically adds all dependent libraries defined in the script to your pom.xml or build.gradle file.</p><h3>Practical Applications</h3><p>Having covered the fundamental usage of JBang, let’s now explore its practical applications based on my real-world experience.</p><ol><li>REST</li><li>gRPC</li><li>AI/LLM</li></ol><h3>REST</h3><p>JBang simplifies the implementation of REST services, making it ideal for quick tests or creating mock REST services for system integration testing.</p><p><strong>Quarkus</strong></p><p>Here’s a REST service script built with Quarkus. Thanks to Quarkus support, you can launch a REST service directly from JBang with this minimal script, even without a main method.</p><pre>///usr/bin/env jbang &quot;$0&quot; &quot;$@&quot; ; exit $?<br><br>//DEPS io.quarkus.platform:quarkus-bom:3.22.3@pom<br>//DEPS io.quarkus:quarkus-rest<br><br>import static java.lang.System.out;<br><br>import jakarta.enterprise.context.ApplicationScoped;<br>import jakarta.ws.rs.GET;<br>import jakarta.ws.rs.Path;<br><br>@Path(&quot;/&quot;)<br>@ApplicationScoped<br>public class quarkus_rest {<br>    @GET<br>    public String hello() {<br>        out.println(&quot;Received: /&quot;);<br>        return &quot;Hello JJUG!&quot;;<br>    }<br><br>    @Path(&quot;{name}&quot;)<br>    @GET<br>    public String hello(String name) {<br>        out.println(&quot;Received: &quot; + name);<br>        return &quot;Hello &quot; + name + &quot;!&quot;;<br>    }<br>}</pre><p><strong>Spring Boot</strong></p><p>REST services can also be implemented using Spring Boot. Note that Spring Boot requires a main method, and due to its component scanning specifications, you must use a package name other than the default package.</p><pre>///usr/bin/env jbang &quot;$0&quot; &quot;$@&quot; ; exit $?<br><br>//DEPS org.springframework.boot:spring-boot-dependencies:3.4.6@pom<br>//DEPS org.springframework.boot:spring-boot-starter-web<br><br>package rest;<br><br>import static java.lang.System.out;<br><br>import org.springframework.boot.SpringApplication;<br>import org.springframework.boot.autoconfigure.SpringBootApplication;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.PathVariable;<br>import org.springframework.web.bind.annotation.RestController;<br><br>@SpringBootApplication<br>@RestController<br>public class sb_rest {<br>    public static void main(String... args) {<br>        SpringApplication.run(sb_rest.class, args);<br>    }<br><br>    @GetMapping(&quot;/&quot;)<br>    public String hello() {<br>        out.println(&quot;Received: /&quot;);<br>        return &quot;Hello JJUG!&quot;;<br>    }<br><br>    @GetMapping(&quot;/{name}&quot;)<br>    public String hello(@PathVariable(&quot;name&quot;) String name) {<br>        out.println(&quot;Received: &quot; + name);<br>        return &quot;Hello &quot; + name + &quot;!&quot;;<br>    }<br>}</pre><h3>gRPC</h3><p>JBang is also well-suited for testing gRPC communication. Let’s demonstrate by implementing a gRPC client and server that interact using the following .proto file:</p><pre>syntax = &quot;proto3&quot;;<br><br>package hello;<br><br>service HelloService {<br>  rpc Hello (HelloRequest) returns (HelloResponse) {}<br>}<br><br>message HelloRequest {<br>  string name = 1;<br>}<br><br>message HelloResponse {<br>  string message = 1;<br>}</pre><p>First, you’ll need to generate Protocol Buffers model classes and gRPC stubs from the .proto file using the protoc command.</p><pre># Generate model classes<br>protoc --java_out=. ./hello.proto<br><br># Generate gRPC Java stubs<br>protoc \<br>  --plugin=protoc-gen-grpc-java=./protoc-gen-grpc-java-${GRPC_VERSION}-${OS}-${ARCH}.exe \<br>  --grpc-java_out=. \<br>  ./hello.proto</pre><p><strong>gRPC Server</strong></p><p>This example shows a gRPC server implementing HelloService, which loads the following generated Java source files:</p><ul><li>hello/Hello.java</li><li>hello/HelloServiceGrpc.java</li></ul><pre>///usr/bin/env jbang &quot;$0&quot; &quot;$@&quot; ; exit $?<br><br>//DEPS com.google.protobuf:protobuf-java:4.31.1<br>//DEPS com.google.protobuf:protobuf-java-util:4.31.1<br>//DEPS io.grpc:grpc-bom:1.73.0@pom<br>//DEPS io.grpc:grpc-netty-shaded<br>//DEPS io.grpc:grpc-protobuf<br>//DEPS io.grpc:grpc-stub<br>//DEPS org.apache.tomcat:annotations-api:6.0.53<br><br>//SOURCES hello/Hello.java<br>//SOURCES hello/HelloServiceGrpc.java<br><br>import static java.lang.System.out;<br><br>import hello.Hello.HelloRequest;<br>import hello.Hello.HelloResponse;<br>import hello.HelloServiceGrpc.HelloServiceImplBase;<br>import io.grpc.Grpc;<br>import io.grpc.InsecureServerCredentials;<br>import io.grpc.stub.StreamObserver;<br><br>public class server {<br>    static int port = 50051;<br><br>    public static void main(String... args) throws Exception {<br>        var server = Grpc.newServerBuilderForPort(port, InsecureServerCredentials.create())<br>                .addService(new HelloServiceImpl())<br>                .build();<br>        server.start();<br>        out.println(&quot;Server started, listening on port &quot; + port);<br>        Runtime.getRuntime().addShutdownHook(new Thread(() -&gt; {<br>            out.println(&quot;Shutting down server&quot;);<br>            server.shutdown();<br>            out.println(&quot;Server shut down&quot;);<br>        }));<br>        server.awaitTermination();<br>    }<br><br>    static class HelloServiceImpl extends HelloServiceImplBase {<br>        @Override<br>        public void hello(HelloRequest request, StreamObserver&lt;HelloResponse&gt; responseObserver) {<br>            out.println(&quot;Received: &quot; + request.getName());<br>            var response = HelloResponse.newBuilder()<br>                    .setMessage(&quot;Hello &quot; + request.getName())<br>                    .build();<br>            responseObserver.onNext(response);<br>            responseObserver.onCompleted();<br>        }<br>    }<br>}</pre><p><strong>gRPC Client</strong></p><p>Similarly, this implements a gRPC client, loading the same generated Java source files.</p><pre>///usr/bin/env jbang &quot;$0&quot; &quot;$@&quot; ; exit $?<br><br>//DEPS com.google.protobuf:protobuf-java:4.31.1<br>//DEPS com.google.protobuf:protobuf-java-util:4.31.1<br>//DEPS io.grpc:grpc-bom:1.73.0@pom<br>//DEPS io.grpc:grpc-protobuf<br>//DEPS io.grpc:grpc-stub<br>//DEPS io.grpc:grpc-netty-shaded<br>//DEPS org.apache.tomcat:annotations-api:6.0.53<br><br>//SOURCES hello/Hello.java<br>//SOURCES hello/HelloServiceGrpc.java<br><br>import static java.lang.System.out;<br><br>import hello.Hello.HelloRequest;<br>import hello.HelloServiceGrpc;<br>import io.grpc.Grpc;<br>import io.grpc.InsecureChannelCredentials;<br><br>public class client {<br>    static String target = &quot;localhost:50051&quot;;<br><br>    public static void main(String... args) {<br>        var name = args.length &gt; 0 ? args[0] : &quot;JJUG&quot;;<br><br>        var channel = Grpc.newChannelBuilder(target, InsecureChannelCredentials.create())<br>                .build();<br>        var stub = HelloServiceGrpc.newBlockingStub(channel);<br>        var request = HelloRequest.newBuilder()<br>                .setName(name)<br>                .build();<br>        var response = stub.hello(request);<br>        out.println(&quot;Response: &quot; + response.getMessage());<br>    }<br>}</pre><h3>AI/LLM</h3><p>JBang can also be effectively used for testing and training AI and LLM models.</p><p><strong>DJL</strong></p><p>This is a sample script demonstrating <a href="https://djl.ai/">DJL</a>, a deep learning framework for Java. It performs handwritten digit image recognition using an MLP AI model.</p><pre>///usr/bin/env jbang &quot;$0&quot; &quot;$@&quot; ; exit $?<br><br>//JAVA 17+<br>//DEPS ai.djl:bom:0.33.0@pom<br>//DEPS ai.djl:api<br>//DEPS ai.djl:model-zoo<br>//DEPS ai.djl.pytorch:pytorch-engine<br>//DEPS org.slf4j:slf4j-simple:2.0.17<br><br>import static java.lang.System.out;<br><br>import java.nio.file.Path;<br><br>import ai.djl.Application;<br>import ai.djl.modality.Classifications;<br>import ai.djl.modality.cv.Image;<br>import ai.djl.modality.cv.ImageFactory;<br>import ai.djl.repository.zoo.Criteria;<br>import ai.djl.training.util.ProgressBar;<br><br>public class djl {<br>    static Path input = Path.of(&quot;3.png&quot;);<br><br>    public static void main(String... args) throws Exception {<br>        var criteria = Criteria.builder()<br>                .optApplication(Application.CV.IMAGE_CLASSIFICATION)<br>                .setTypes(Image.class, Classifications.class)<br>                .optArtifactId(&quot;mlp&quot;)<br>                .optProgress(new ProgressBar())<br>                .build();<br>        var model = criteria.loadModel();<br>        var img = ImageFactory.getInstance().fromFile(input);<br>        try (var predictor = model.newPredictor()) {<br>            var classifications = predictor.predict(img);<br>            out.println(classifications);<br>            out.println(&quot;Answer = %s&quot;.formatted(classifications.best().getClassName()));<br>        }<br>    }<br>}</pre><p><strong>LangChain4j</strong></p><p>Finally, this sample script showcases running a small LLM locally using <a href="https://docs.langchain4j.dev/">LangChain4j</a> and <a href="https://ollama.com/">Ollama</a>. It leverages Llama 3.2 and LangChain4j’s AI service features to query the LLM on how to prepare coffee.</p><pre>///usr/bin/env jbang &quot;$0&quot; &quot;$@&quot; ; exit $?<br><br>//DEPS dev.langchain4j:langchain4j-bom:1.0.0@pom<br>//DEPS dev.langchain4j:langchain4j<br>//DEPS dev.langchain4j:langchain4j-ollama<br>//DEPS org.slf4j:slf4j-simple:2.0.17<br><br>import static java.lang.System.out;<br>import static java.time.Duration.ofSeconds;<br><br>import dev.langchain4j.model.ollama.OllamaChatModel;<br>import dev.langchain4j.service.AiServices;<br>import dev.langchain4j.service.SystemMessage;<br><br>public class llm {<br>    static final String OLLAMA_URL = &quot;http://localhost:11434&quot;;<br>    static final String MODEL = &quot;llama3.2&quot;;<br><br>    public static void main(String... args) {<br>        var model = OllamaChatModel.builder()<br>                .baseUrl(OLLAMA_URL)<br>                .modelName(MODEL)<br>                .timeout(ofSeconds(60 * 3))<br>                .build();<br>        var assistant = AiServices.builder(Assistant.class)<br>                .chatModel(model)<br>                .build();<br>        var drink = args.length &gt; 0 ? args[0] : &quot;coffee&quot;;<br>        out.println(assistant.recipe(drink));<br>    }<br><br>    interface Assistant {<br>        @SystemMessage(&quot;&quot;&quot;<br>                Tell me how to make a drink.<br>                &quot;&quot;&quot;)<br>        String recipe(String query);<br>    }<br>}</pre><h3>CLI Development</h3><p>Next, I’ll introduce JBang’s ecosystem and its features, starting with CLI development.</p><p>While shell scripts are commonly used for creating small command-line interface (CLI) tools, JBang offers a robust alternative for developing CLIs in Java.</p><pre>jbang init --template=cli cli.java</pre><p>This command generates a script template like the one below:</p><pre>///usr/bin/env jbang &quot;$0&quot; &quot;$@&quot; ; exit $?<br>//DEPS info.picocli:picocli:4.6.3<br><br>import picocli.CommandLine;<br>import picocli.CommandLine.Command;<br>import picocli.CommandLine.Parameters;<br><br>import java.util.concurrent.Callable;<br><br>@Command(name = &quot;cli&quot;, mixinStandardHelpOptions = true, version = &quot;cli 0.1&quot;, description = &quot;cli made with jbang&quot;)<br>class cli implements Callable&lt;Integer&gt; {<br><br>    @Parameters(index = &quot;0&quot;, description = &quot;The greeting to print&quot;, defaultValue = &quot;World!&quot;)<br>    private String greeting;<br><br>    public static void main(String... args) {<br>        int exitCode = new CommandLine(new cli()).execute(args);<br>        System.exit(exitCode);<br>    }<br><br>    @Override<br>    public Integer call() throws Exception { // your business logic goes here...<br>        System.out.println(&quot;Hello &quot; + greeting);<br>        return 0;<br>    }<br>}</pre><p>Upon execution, you’ll observe that it already provides a basic set of command-line options.</p><pre>$ ./cli.java -h<br>Usage: cli [-hV] &lt;greeting&gt;<br>cli made with jbang<br>      &lt;greeting&gt;   The greeting to print<br>  -h, --help       Show this help message and exit.<br>  -V, --version    Print version information and exit.</pre><p>The CLI template in JBang is built upon <a href="https://picocli.info/">picocli</a>, a powerful and popular CLI framework for Java.</p><h3>JBang-based CLIs</h3><p>Several Java frameworks and applications already provide CLIs developed using JBang and picocli:</p><ul><li><a href="https://camel.apache.org/manual/camel-jbang.html">Apache Camel</a> — A versatile framework for system integration</li><li><a href="https://hawt.io/docs/get-started.html">Hawtio</a> — A JMX-based web management console</li><li><a href="https://citrusframework.org/samples/jbang/">Citrus</a> — A BDD integration testing framework</li></ul><h3>Catalog</h3><p>JBang further enhances script distribution through a mechanism called “catalog.” The combination of CLI development and these catalogs forms the bedrock of the JBang-based ecosystem.</p><p>A catalog is a JSON file named jbang-catalog.json. If this file is hosted in a GitHub repository (e.g., https://github.com/user/repo), you can directly invoke scripts from that repository using the following syntax:</p><pre>jbang my-cli@user/repo</pre><p>Specifically, if the repository name is jbang-catalog, you can execute the script with a more concise command &lt;command&gt;@&lt;user&gt;, as shown below:</p><pre>jbang my-cli@user</pre><h3>Catalog Example</h3><p>Let’s examine the Apache Camel JBang catalog as a practical illustration.</p><p><a href="https://github.com/apache/camel/blob/main/jbang-catalog.json">https://github.com/apache/camel/blob/main/jbang-catalog.json</a></p><pre>{<br> &quot;catalogs&quot;: {},<br> &quot;aliases&quot;: {<br>   &quot;camel&quot;: {<br>  &quot;script-ref&quot;: &quot;dsl/camel-jbang/camel-jbang-main/dist/CamelJBang.java&quot;,<br>  &quot;description&quot;: &quot;Run Apache Camel routes easily&quot;<br>   }<br> }<br>}</pre><p>The script referenced by script-ref is a straightforward example that launches a CLI by loading a specific version of the Camel library as a dependency:</p><p><a href="https://github.com/apache/camel/blob/main/dsl/camel-jbang/camel-jbang-main/dist/CamelJBang.java">https://github.com/apache/camel/blob/main/dsl/camel-jbang/camel-jbang-main/dist/CamelJBang.java</a></p><pre>///usr/bin/env jbang &quot;$0&quot; &quot;$@&quot; ; exit $?<br><br>/*<br> * Licensed to the Apache Software Foundation (ASF) under one or more<br> * contributor license agreements.  See the NOTICE file distributed with<br> * this work for additional information regarding copyright ownership.<br> * The ASF licenses this file to You under the Apache License, Version 2.0<br> * (the &quot;License&quot;); you may not use this file except in compliance with<br> * the License.  You may obtain a copy of the License at<br> *<br> *    http://www.apache.org/licenses/LICENSE-2.0<br> *<br> * Unless required by applicable law or agreed to in writing, software<br> * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,<br> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br> * See the License for the specific language governing permissions and<br> * limitations under the License.<br> */<br><br>//JAVA 17+<br>//REPOS central=https://repo1.maven.org/maven2,apache-snapshot=https://repository.apache.org/content/groups/snapshots/<br>//DEPS org.apache.camel:camel-bom:${camel.jbang.version:4.12.0}@pom<br>//DEPS org.apache.camel:camel-jbang-core:${camel.jbang.version:4.12.0}<br>//DEPS org.apache.camel.kamelets:camel-kamelets:${camel-kamelets.version:4.12.0}<br><br>package main;<br><br>import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;<br><br>/**<br> * Main to run CamelJBang<br> */<br>public class CamelJBang {<br><br>    public static void main(String... args) {<br>        CamelJBangMain.run(args);<br>    }<br><br>}</pre><p>This Camel CLI can be invoked with the following command:</p><pre>jbang camel@apache/camel</pre><h3>Install as an App</h3><p>JBang also offers an “app” feature, which allows you to install a catalog script locally as a command-line executable.</p><p>Continuing with the Camel CLI example, you can install the camel command locally with a single command:</p><pre>jbang app install camel@apache/camel<br><br>camel --version</pre><p>These combined features complete JBang’s robust ecosystem for code distribution.</p><h3>Official Catalogs</h3><p>Finally, there’s a growing trend of major vendors publishing JBang catalogs, further expanding the ecosystem.</p><pre>$ jbang catalog list<br>alibaba<br>   https://github.com/alibaba/jbang-catalog/blob/HEAD/jbang-catalog.json<br>apache/camel<br>   Run Apache Camel routes easily<br>   https://github.com/apache/camel/blob/HEAD/jbang-catalog.json<br>jbangdev<br>   JBang&#39;s own catalog of small utilities<br>   https://github.com/jbangdev/jbang-catalog/blob/HEAD/jbang-catalog.json<br>jbanghub [importing]<br>   JBangHub - Unleashing the Java community<br>   https://raw.githubusercontent.com/jbanghub/jbang-catalog/main/jbang-catalog.json<br>jbanghub/apple<br>   Apple cli&#39;s<br>   https://github.com/jbanghub/apple/blob/HEAD/jbang-catalog.json<br>jbanghub/eclipse<br>   Eclipse Foundation developed tools<br>   https://github.com/jbanghub/eclipse/blob/HEAD/jbang-catalog.json<br>jbanghub/h2<br>   H2 Database Engine<br>   https://github.com/jbanghub/h2/blob/HEAD/jbang-catalog.json<br>jbanghub/jvm-profiling-tools<br>   A collection of JVM profiling tools<br>   https://github.com/jvm-profiling-tools/ap-loader/blob/HEAD/jbang-catalog.json<br>jbanghub/sqlline<br>   Shell for issuing SQL to relational databases via JDBC<br>   https://github.com/jbanghub/sqlline/blob/HEAD/jbang-catalog.json<br>jreleaser<br>   Release projects quickly and easily with JReleaser<br>   https://github.com/jreleaser/jbang-catalog/blob/HEAD/jbang-catalog.json<br>jupyter-java<br>   Make it easy to use java from jupyter notebooks<br>   https://github.com/jupyter-java/jbang-catalog/blob/HEAD/jbang-catalog.json<br>jvm-profiling-tools/ap-loader<br>   Sampling CPU and HEAP profiler for Java featuring AsyncGetCallTrace + perf_events via JBang<br>   https://github.com/jvm-profiling-tools/ap-loader/blob/HEAD/jbang-catalog.json<br>maveniverse<br>   The missing pieces from Apache Maven universe<br>   https://github.com/maveniverse/jbang-catalog/blob/HEAD/jbang-catalog.json<br>microsoft<br>   Catalogue for JBang Artifacts<br>   https://github.com/microsoft/jbang-catalog/blob/HEAD/jbang-catalog.json<br>oracle/graalpython<br>   A Python 3 implementation built on GraalVM<br>   https://github.com/oracle/graalpython/blob/HEAD/jbang-catalog.json<br>quarkusio<br>   Subsonic and Subatomic Quarkus cli and plugins<br>   https://github.com/quarkusio/jbang-catalog/blob/HEAD/jbang-catalog.json</pre><ul><li><a href="https://github.com/alibaba/jbang-catalog">Alibaba</a></li><li><a href="https://github.com/jbanghub/apple">Apple</a></li><li><a href="https://github.com/microsoft/jbang-catalog">Microsoft</a></li><li><a href="https://github.com/oracle/graalpython">Oracle (GraalPy)</a></li></ul><h3>Conclusion</h3><p>I hope this article encourages more developers to explore and adopt JBang for their future Java development endeavours.</p><p>It’s genuinely enjoyable to simply install JBang and start experimenting with it, so please give it a try!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1636a1913ea8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Operating Java applications verbally with LLMs via Jolokia MCP Server]]></title>
            <link>https://tadayoshi-sato.medium.com/operating-java-applications-verbally-with-llms-via-jolokia-mcp-server-da5215c469f7?source=rss-b42746ddc587------2</link>
            <guid isPermaLink="false">https://medium.com/p/da5215c469f7</guid>
            <category><![CDATA[jolokia]]></category>
            <category><![CDATA[mcps]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[mcp-server]]></category>
            <dc:creator><![CDATA[Tadayoshi Sato]]></dc:creator>
            <pubDate>Wed, 28 May 2025 04:15:03 GMT</pubDate>
            <atom:updated>2025-05-28T04:17:22.417Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FEd0UdlF_erg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DEd0UdlF_erg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FEd0UdlF_erg%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/edbba9501cbca05a5961a6171d74ef84/href">https://medium.com/media/edbba9501cbca05a5961a6171d74ef84/href</a></iframe><p>Java has the standard API for application management, <a href="https://docs.oracle.com/en/java/javase/21/docs/api/java.management/javax/management/package-summary.html">JMX (Java Management Extensions)</a>. Most Java application servers and frameworks provide the JMX-based management APIs, which have been used by system management tools for various monitoring purposes.</p><p>By leveraging JMX, any Java application can be operated with complex commands from an LLM via MCP, without introducing yet another mechanism or framework into Java.</p><p>To operate Java applications with MCP, we can use Jolokia, a JMX-over-HTTP technology.<br><a href="https://github.com/jolokia/jolokia-mcp-server">https://github.com/jolokia/jolokia-mcp-server</a></p><h3>What is Jolokia?</h3><p><a href="https://jolokia.org/">Jolokia</a> is a library that provides HTTP access to JMX. Jolokia offers <a href="https://jolokia.org/reference/html/manual/agents.html">agents</a> and <a href="https://jolokia.org/reference/html/manual/clients.html">clients</a>. Essentially, attaching a Jolokia agent to a Java application enables JMX over HTTP.</p><p>There are two main types of agents: JVM agents and WAR agents. JVM agents are attached to the JVM at startup, while WAR agents deploy a Jolokia endpoint to a web application.</p><figure><img alt="Jolokia architecture" src="https://cdn-images-1.medium.com/max/666/1*P7XZMySROuyoRrRQI-VIyQ.png" /><figcaption>Jolokia arcihtecture <a href="#9343">¹</a></figcaption></figure><h3>Jolokia MCP Server</h3><p><a href="https://github.com/jolokia/jolokia-mcp-server">Jolokia MCP Server</a> transforms a Jolokia-attached JVM into an MCP server.</p><p>First, let’s watch the video at the beginning of the post to see what you can do by connecting a Java app with Jolokia MCP Server. In the video, the instruction is:</p><blockquote>check the memory state of the java app</blockquote><p>This demo just runs a simple operation only using java.lang:type=Memory, which is provided by Java by default. However, if application servers or frameworks provide more advanced MBeans (i.e. JMX API), the AI model can automatically check available JMX MBean attributes and operations, then devise and run the necessary operations to achieve the task for you.</p><p>This also means that if you want to operate a Java application under development in a specific way from an LLM prompt, you only need to implement that specific functionality as an MBean and register it with the MBean server.</p><h3>Features/Tools</h3><p>Each instance of Jolokia MCP Server connects to a single JVM and serves the following functionalities to the MCP host:</p><ul><li>Get a list of available MBeans</li><li>Get a list of an MBean’s operations</li><li>Get a list of an MBean’s attributes</li><li>Read and write an MBean’s attributes</li><li>Execute an MBean’s operations</li></ul><p>They correspond to the following 6 MCP tools:</p><ol><li><strong>listMBeans<br></strong>Get a list of MBeans available from the JVM<br>Output (List&lt;String&gt;): A list of all MBean object names in the JVM</li><li><strong>listMBeanOperations<br></strong>Get a list of available operations for the specified MBean<br>Input:<br> - mbean (String): MBean name<br>Output (String): Definition of available operations for the specified MBean (JSON format)</li><li><strong>listMBeanAttributes<br></strong> Get a list of available attributes for the specified MBean<br>Input:<br> - mbean (String): MBean name<br>Output (String): Definition of available attributes for the specified MBean (JSON format)</li><li><strong>readMBeanAttribute<br></strong>Read the value of the specified MBean attribute<br>Input:<br> - mbean (String): MBean name<br> - attribute (String): Attribute name<br>Output (String): String representation of the specified attribute’s value, or “null”</li><li><strong>writeMBeanAttribute<br></strong>Set the value of the specified MBean attribute<br>Input:<br> - mbean (String): MBean name<br> - attribute (String): Attribute name<br> - value (Object): Attribute value<br>Output (String): String representation of the specified attribute’s previous value, or “null”</li><li><strong>executeMBeanOperation<br></strong>Execute an operation of the specified MBean<br>Input:<br> - mbean (String): MBean name<br> - operation (String): Operation name<br> - args (Object[]): Arguments<br>Output (String): String representation of the operation’s return value, or “null”</li></ol><h3>How to use</h3><ol><li><strong>Add Jolokia Agent to Your Java App</strong></li></ol><p>Here, we will use the JVM agent so that existing Java applications can be used as is. First, download jolokia-agent-jvm-&lt;version&gt;-javaagent.jar.</p><p>⬇️ <a href="https://repo1.maven.org/maven2/org/jolokia/jolokia-agent-jvm/2.2.9/jolokia-agent-jvm-2.2.9-javaagent.jar">jolokia-agent-jvm-2.2.9-javaagent.jar</a></p><p>Next, launch your Java app (app.jar) with the -javaagent option.<a href="#a391">²</a></p><pre>java -javaagent:jolokia-agent-jvm-2.2.9-javaagent.jar -jar app.jar</pre><p>If the Jolokia agent is attached successfully, you will see a message like this at the beginning. By default, the Jolokia endpoint URL will be: <a href="http://localhost:8778/jolokia/">http://localhost:8778/jolokia/</a></p><pre>I&gt; No access restrictor found, access to any MBean is allowed<br>Jolokia: Agent started with URL http://127.0.0.1:8778/jolokia/</pre><p><strong>2. Install Jolokia MCP Server</strong></p><p>First, download the Jolokia MCP Server JAR.</p><p>⬇️ <a href="https://github.com/jolokia/jolokia-mcp-server/releases/download/v0.3.5/jolokia-mcp-server-0.3.5-runner.jar">jolokia-mcp-server-0.3.5-runner.jar</a></p><p>Next, add it to the configuration of your MCP host (e.g., Claude, Cline, Cursor, etc.). The Jolokia MCP Server itself can be launched as follows:</p><pre>java -jar jolokia-mcp-server-0.3.5-runner.jar</pre><p>So, configure your MCP host like below. Replace &lt;path-to-the-runner-jar&gt; with the appropriate absolute path.</p><pre>{<br>  &quot;mcpServers&quot;: {<br>    &quot;jolokia&quot;: {<br>      &quot;command&quot;: &quot;java&quot;,<br>      &quot;args&quot;: [<br>        &quot;-jar&quot;,<br>        &quot;&lt;path-to-the-runner-jar&gt;/jolokia-mcp-server-0.3.5-runner.jar&quot;<br>      ]<br>    }<br>  }<br>}</pre><p><strong>NOTE:</strong> If you set the Jolokia endpoint to something other than the default (http://localhost:8778/jolokia/), specify that endpoint URL as the third argument in args.</p><p><strong>3. Launch MCP Host</strong></p><p>Launch your MCP host and confirm that Jolokia MCP Server is properly installed.</p><p>For Claude Desktop, it’s successfully installed if jolokia is recognised and the tools are loaded as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kA6idW7Np9UBMSt0dq9Mwg.png" /></figure><p>Then, try entering a prompt like:</p><blockquote>check memory usage</blockquote><p>If it works, try various other prompts.</p><h3>Wrap up</h3><p>We introduced Jolokia MCP Server, which allows you to operate Java applications from LLMs.</p><p>By attaching the Jolokia agent to your Java application, existing JMX MBeans can be transformed into MCP tools, enabling direct interaction and operation of Java applications through LLMs.</p><p>This opens up new possibilities for Java application management and automation using LLMs and MCP. It can be considered one future direction for LLM utilisation in enterprise Java.</p><p>Jolokia MCP Server is planned for further improvements in the future. For example, the following are under consideration:</p><ul><li><a href="https://github.com/jolokia/jolokia-mcp-server/issues/12">Integration of Jolokia agent and MCP Server</a></li><li><a href="https://github.com/jolokia/jolokia-mcp-server/issues/13">Support for streaming HTTP</a></li><li><a href="https://github.com/jolokia/jolokia-mcp-server/issues/14">Provision of boilerplate prompts</a></li></ul><p>Please give Jolokia MCP Server a try!</p><ol><li>Quoted from <a href="https://jolokia.org/reference/html/manual/architecture.html#agent-mode">https://jolokia.org/reference/html/manual/architecture.html#agent-mode</a> <a href="#0e87">^</a></li><li>For Spring Boot, ensure spring-boot-starter-actuator and JMX are enabled. See: <a href="https://docs.spring.io/spring-boot/reference/actuator/jmx.html">https://docs.spring.io/spring-boot/reference/actuator/jmx.html</a> <a href="#b9d1">^</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da5215c469f7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using OpenShift Routes with Microshift]]></title>
            <link>https://tadayoshi-sato.medium.com/using-openshift-routes-with-microshift-fe78c7735f50?source=rss-b42746ddc587------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe78c7735f50</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[microshift]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[openshift]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Tadayoshi Sato]]></dc:creator>
            <pubDate>Wed, 20 Oct 2021 10:23:36 GMT</pubDate>
            <atom:updated>2021-10-21T03:31:04.630Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xnX9nEBJGHqtSaUo" /><figcaption>Photo by <a href="https://unsplash.com/@laurenmancke?utm_source=medium&amp;utm_medium=referral">Lauren Mancke</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><a href="https://github.com/redhat-et/microshift">Microshift</a> is a research project that aims to downsize OpenShift to the extreme so that it can run on IoT and resource-constrained machines.</p><p><a href="https://github.com/redhat-et/microshift">GitHub - redhat-et/microshift: A small form factor OpenShift/Kubernetes optimized for edge computing</a></p><p>I’m working on <a href="https://github.com/container-tools/microshift-action">a GitHub action that makes Microshift available as an OpenShift cluster in a GitHub workflow.</a></p><h3>Making Routes available with Microshift</h3><p>Since Microshift is a new project, it still has rough edges and does not provide the same seamless experiences as Minikube and <a href="https://github.com/code-ready/crc">CRC</a> yet.</p><p>You can create an OpenShift <a href="https://docs.openshift.com/container-platform/4.8/rest_api/network_apis/route-route-openshift-io-v1.html">Route</a>, but it won’t be available right away with the assigned hostname.</p><p>(This article assumes that <a href="https://github.com/redhat-et/microshift/blob/main/CONTRIBUTING.md#optional-developing-with-vagrant">you have installed Microshift on Vagrant.</a>)</p><p>To test this, let’s deploy an app to Microshift and publish a route for it.</p><pre>oc create deploy hello --image=quay.io/tasato/hello-js<br>oc expose deploy hello --port 8080<br>oc expose svc hello</pre><p>A service and a route will be created.</p><pre>$ oc get svc,route<br>NAME                          TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE<br>service/hello                 ClusterIP   10.43.122.106   &lt;none&gt;        8080/TCP   6s<br>...</pre><pre>NAME                             HOST/PORT                     PATH   SERVICES   PORT   TERMINATION   WILDCARD<br>route.route.openshift.io/hello   hello-default.cluster.local          hello      8080                 None</pre><p>However, we can’t still access hello-default.cluster.local as it is.</p><h3>Exposing the Router</h3><p>The first thing we need to do is to expose the OpenShift Router as a NodePort service, which is already running in the openshift-ingress namespace.</p><pre>$ oc get pods -n openshift-ingress<br>NAME                              READY   STATUS    RESTARTS   AGE<br>router-default-6d8c9d8f57-wjfk7   1/1     Running   1          4d21h</pre><p>Publish this as a NodePort service with 30080-&gt;80 (HTTP) and 30443-&gt;443 (HTTPS). This will allow access to the Router from outside the cluster on ports 30080 and 30443.</p><pre>$ cat &lt;&lt;EOF | oc apply -f -<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: router<br>  namespace: openshift-ingress<br>spec:<br>  type: NodePort<br>  selector:<br>    ingresscontroller.operator.openshift.io/deployment-ingresscontroller: default<br>  ports:<br>    - name: http<br>      port: 80<br>      targetPort: 80<br>      nodePort: 30080<br>    - name: https<br>      port: 443<br>      targetPort: 443<br>      nodePort: 30443<br>EOF</pre><p>(Thanks <a href="https://github.com/mangelajo">Miguel Angel Ajo Pelayo</a> for <a href="https://github.com/redhat-et/microshift/issues/334#issuecomment-943168797">the original solution</a>.)</p><p>By the way, in addition to the router service we just created there is also a ClusterIP service called router-internal-default.</p><pre>$ oc get svc -n openshift-ingress<br>NAME                      TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE<br>router                    NodePort    10.43.205.107   &lt;none&gt;        80:30080/TCP,443:30443/TCP   4d2h<br>router-internal-default   ClusterIP   10.43.95.166    &lt;none&gt;        80/TCP,443/TCP,1936/TCP      36d</pre><p>If you just want to access Route from within a Microshift cluster node (e.g. for usages with GitHub Actions), you can use the router-internal-default without creating a router service.</p><h3>Configuring the client-side DNS</h3><p>At this point, you should be able to access hello-default.cluster.local from port 30080 on the Vagrant VM. Given that the IP address of the VM is 192.168.99.11, you can access it by specifying the route name in HTTP Host header as the dispatch destination, as follows:</p><pre>$ curl -H &#39;Host: hello-default.cluster.local&#39; 192.168.99.11:30080<br>Hello ::ffff:10.42.0.51 from hello-64c47c44c8-5bbjg</pre><p>Now, all you need is to make the name resolved to the Vagrant VM IP address 192.168.99.11 when you access hello-default.cluster.local on the client side.</p><h3>dnsmasq</h3><p>It is most straightforward to use dnsmasq when you want to assign a specific IP address to dynamically created URLs *.cluster.local. If dnsmasq is not installed yet, install it first.</p><p><strong>Fedora/RHEL/CentOS:</strong></p><pre>$ sudo dnf install dnsmasq</pre><p><strong>Ubuntu:</strong></p><pre>$ sudo apt install dnsmasq</pre><p>Then edit /etc/dnsmasq.conf and assign the IP address of the Vagrant VM 192.168.99.11 to the cluster.local domain by adding a line address=/cluster.local/192.168.99.11.</p><p>Also, uncomment #bind-interfaces to enable interface binding.</p><p><strong>/etc/dnsmasq.conf</strong></p><pre>address=/cluster.local/192.168.99.11<br>...<br>bind-interfaces</pre><p>It is because otherwise dnsmasq won’t start as it conflicts with 127.0.0.53:53 which is occupied by the default DNS service systemd-resolved.</p><p>Restart dnsmasq.</p><pre>$ sudo systemctl restart dnsmasq</pre><h3>systemd-resolved</h3><p>For the recent Linux distributions, systemd-resolved is the default DNS service.</p><p>Modify /etc/systemd/resolved.conf so that it looks up dnsmasq (127.0.0.1).</p><p><strong>/etc/systemd/resolved.conf</strong></p><pre>DNS=127.0.0.1 8.8.8.8</pre><p>Then switch the symlink /etc/resolv.conf from /run/systemd/resolve/stub-resolv.conf to /run/systemd/resolve/resolv.conf.</p><pre>$ sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf</pre><h3>/etc/nsswitch.conf</h3><p>If you are using Fedora, you will need to tweak the settings in /etc/nsswitch.conf.</p><p>Since *.local resolution is primarily handled by mDNS, if your nsswitch.conf has the settings to return immediately after mDNS resolution, you will need to change it as well.</p><p>Specifically, if your nsswitch.conf has [...=return] instructions in hosts: as follows, remove all of them so that the host resolution always reaches dns.</p><p><strong>/etc/nsswitch.conf (before change)</strong></p><pre>hosts: files myhostname mdns4_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns</pre><p><strong>/etc/nsswitch.conf (after change)</strong></p><pre>hosts: files myhostname mdns4_minimal resolve dns</pre><p>Restart systemd-resolved.</p><pre>$ sudo systemctl restart systemd-resolved</pre><h3>Configuring port-forwarding on VM side</h3><p>By now, you can access the application as hello-default.cluster.local:30080.</p><pre>$ curl hello-default.cluster.local:30080<br>Hello ::ffff:10.42.0.51 from hello-64c47c44c8-5bbjg</pre><p>To make it accessible with curl hello-default.cluster.local, you need to set up port forwarding from 30080 to 80 on the VM side.</p><h3>redir</h3><p>The easiest way to do this job is to use redir. Let’s install redir.</p><p><strong>Fedora/RHEL/CentOS</strong></p><pre>$ sudo dnf install redir</pre><p><strong>Ubuntu</strong></p><pre>$ sudo apt install redir</pre><p>Start redir in the background on the VM.</p><pre>sudo redir -l debug :80 localhost:30080</pre><p>You can check the log of redir in the syslog on the VM.</p><pre>$ sudo tail -f /var/log/syslog | grep redir<br>Oct 18 06:29:31 ubuntu-focal redir[142824]: peer IP is 192.168.99.1<br>Oct 18 06:29:31 ubuntu-focal redir[142824]: peer socket is 33402<br>Oct 18 06:29:31 ubuntu-focal redir[142824]: target IP address is 127.0.0.1<br>Oct 18 06:29:31 ubuntu-focal redir[142824]: target port is 30080<br>Oct 18 06:29:31 ubuntu-focal redir[50856]: target is localhost:30080<br>Oct 18 06:29:31 ubuntu-focal redir[50856]: Waiting for client to connect on server socket ...<br>Oct 18 06:29:31 ubuntu-focal redir[142824]: Connecting 192.168.99.1:33402 to 192.168.99.1:30080<br>Oct 18 06:29:31 ubuntu-focal redir[142824]: Entering copyloop() - timeout is 0<br>Oct 18 06:29:31 ubuntu-focal redir[142824]: Disconnect after 0 sec, 332 bytes in, 91 bytes out</pre><h3>Conclusion</h3><p>Now you will be able to access it with hello-default.cluster.local.</p><pre>$ curl hello-default.cluster.local<br>Hello ::ffff:10.42.0.51 from hello-64c47c44c8-5bbjg</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe78c7735f50" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deploy your JBang script to Kubernetes/OpenShift]]></title>
            <link>https://tadayoshi-sato.medium.com/deploy-your-jbang-script-to-kubernetes-openshift-5a6346e8a614?source=rss-b42746ddc587------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a6346e8a614</guid>
            <category><![CDATA[openshift]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[apache-camel]]></category>
            <category><![CDATA[jbang]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Tadayoshi Sato]]></dc:creator>
            <pubDate>Thu, 24 Jun 2021 06:17:52 GMT</pubDate>
            <atom:updated>2021-06-24T06:44:50.778Z</atom:updated>
            <content:encoded><![CDATA[<p>Normally, if you want to run a Java app on Kubernetes/OpenShift, you would have to generate a project with <a href="http://start.spring.io/">start.spring.io</a> or <a href="http://code.quarkus.io/">code.quarkus.io</a> and then deploy it with a Maven command. It’s still blazing fast, but you can be even faster with <a href="https://www.jbang.dev/">JBang</a>.</p><p>Here is how you can make a JBang script into a Pod and run it directly on Kubernetes/OpenShift.</p><h3>What is JBang?</h3><p>Before jumping into the actual steps, JBang is a dev tool/execution environment for Java that makes it easy to run Java programs like a script.</p><p><a href="https://www.jbang.dev/">JBang</a></p><p>It takes a little time to set up a Java project from Maven or IDE, adding dependencies to pom.xml, and so on, before you are ready to execute the first “Hello World!” in Java. However, with JBang, you can immediately jump into writing code and execute it just like a scripting language.</p><p>The primary purpose of JBang would be for small scripting and experimentation with Java code, but JBang also has support for IDE and native compilation using GraalVM, so it has a full potential of becoming a Next Java development and execution environment.</p><p>As a Java engineer, once you get used to JBang, it will become a tool you can’t live without.</p><h3>How to use JBang</h3><p>Here’s how to use it. First, generate a code template with jbang CLI:</p><pre>$ jbang init hello.java<br>[jbang] File initialized. You can now run it with &#39;jbang hello.java&#39; or edit it using &#39;jbang edit --open=[editor] hello.java&#39; where [editor] is your editor or IDE, e.g. &#39;eclipse&#39;</pre><p>It will generate a Java class like the following:</p><pre>///usr/bin/env jbang “$0” “$@” ; exit $?<br>// //DEPS &lt;dependency1&gt; &lt;dependency2&gt;</pre><pre>import static java.lang.System.*;</pre><pre>public class hello {<br> public static void main(String… args) {<br> out.println(“Hello World”);<br> }<br>}</pre><p>You can directly execute the code with jbang like this:</p><pre>$ jbang hello.java <br>[jbang] Building jar...<br>Hello World</pre><h3>Deploy JBang script to Kubernetes</h3><p>Here is the subject of the article.</p><p>The steps to deploy JBang script to Kubernetes are as follows:</p><ul><li>Make a ConfigMap of the script to be executed (script.java)</li><li>Create a Pod from the <a href="https://github.com/jbangdev/jbang-action">jbang-action</a> container image with mounting the ConfigMap as a volume</li><li>Run the script on k8s</li></ul><h3>Write code</h3><p>First, generate script.java and write some code that you want to run.</p><pre>$ jbang init script.java<br>[jbang] File initialized. You can now run it with &#39;jbang script.java&#39; or edit it using &#39;jbang edit --open=[editor] script.java&#39; where [editor] is your editor or IDE, e.g. &#39;netbeans&#39;<br><br># Edit the code with the editor of your choice<br>$ code `jbang edit script.java`</pre><h3>Create ConfigMap</h3><p>Then, create ConfigMap jbang-script from script.java.</p><pre>$ kubectl create configmap jbang-script --from-file=script.java</pre><p>You should get a ConfigMap like this:</p><pre>$ kubectl get configmaps jbang-script -oyaml<br>apiVersion: v1<br>data:<br>  script.java: |<br>    ///usr/bin/env jbang &quot;$0&quot; &quot;$@&quot; ; exit $?<br>    // //DEPS &lt;dependency1&gt; &lt;dependency2&gt;</pre><pre>    import static java.lang.System.*;</pre><pre>    public class script {</pre><pre>        public static void main(String... args) {<br>            out.println(&quot;Java running on k8s...&quot;);<br>        }<br>    }<br>kind: ConfigMap<br>metadata:<br>  creationTimestamp: &quot;2021-06-23T07:26:10Z&quot;<br>  name: jbang-script<br>  namespace: test<br>  resourceVersion: &quot;2122129&quot;<br>  selfLink: /api/v1/namespaces/test/configmaps/jbang-script<br>  uid: 65f43430-3e3d-4cdc-87ce-aa7d6974cb33</pre><h3>Run the Pod</h3><p>Create a Pod with the script script.java in ConfigMap mounted under /scripts and the path to the script /scripts/script.java set to the environment variable INPUT_SCRIPT, so that the jbangdev/jbang-action image can execute it.</p><p>You can copy and paste the following command to do the job:</p><pre>$ kubectl run jbang-script \<br>    --image=jbangdev/jbang-action \<br>    --restart=Never \<br>    --overrides=&#39;<br>{<br>  &quot;apiVersion&quot;: &quot;v1&quot;,<br>  &quot;spec&quot;: {<br>    &quot;containers&quot;: [<br>      {<br>        &quot;name&quot;: &quot;jbang-script&quot;,<br>        &quot;image&quot;: &quot;jbangdev/jbang-action&quot;,<br>        &quot;env&quot;: [<br>          {<br>            &quot;name&quot;: &quot;INPUT_SCRIPT&quot;,<br>            &quot;value&quot;: &quot;/scripts/script.java&quot;<br>          }<br>        ],<br>        &quot;volumeMounts&quot;: [<br>          {<br>            &quot;name&quot;: &quot;scripts&quot;,<br>            &quot;mountPath&quot;: &quot;/scripts&quot;<br>          }<br>        ]<br>      }<br>    ],<br>    &quot;volumes&quot;: [<br>      {<br>        &quot;name&quot;: &quot;scripts&quot;,<br>        &quot;configMap&quot;: {<br>          &quot;name&quot;: &quot;jbang-script&quot;<br>        }<br>      }<br>    ]<br>  }<br>}<br>&#39;</pre><p>Alternatively, you can create the following YAML and kubectl apply -f it.</p><pre>cat &lt;&lt;EOF | kubectl apply -f -<br>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: jbang-script<br>  labels:<br>    app: jbang-script<br>spec:<br>  containers:<br>    - name: jbang-script<br>      image: jbangdev/jbang-action<br>      env:<br>        - name: INPUT_SCRIPT<br>          value: /scripts/script.java<br>      volumeMounts:<br>        - name: scripts<br>          mountPath: /scripts<br>  volumes:<br>    - name: scripts<br>      configMap:<br>        name: jbang-script<br>  restartPolicy: Never<br>EOF</pre><h3>Execution result</h3><p>The output log would look like this:</p><pre>$ kubectl logs -f jbang-script <br>jbang /scripts/script.java<br>[jbang] Building jar...<br>Java running on k8s...</pre><h3>Run some more serious code</h3><p>The power of JBang is that you can specify and download dependency JARs in Maven GAV format in the header part of a script. It even supports BOM, although there is a limitation that you can only specify one.</p><p>Let’s try running some integration code using an <a href="https://camel.apache.org/">Apache Camel</a> route with JBang.</p><pre>///usr/bin/env jbang &quot;$0&quot; &quot;$@&quot; ; exit $?<br>//DEPS org.apache.camel:camel-bom:3.10.0@pom<br>//DEPS org.apache.camel:camel-core<br>//DEPS org.apache.camel:camel-main<br>//DEPS org.apache.camel:camel-stream<br>//DEPS org.slf4j:slf4j-nop:1.7.30</pre><pre>import org.apache.camel.*;<br>import org.apache.camel.builder.*;<br>import org.apache.camel.main.*;<br>import org.apache.camel.spi.*;</pre><pre>import static java.lang.System.*;</pre><pre>public class script {<br>    public static void main(String... args) throws Exception {<br>        out.println(&quot;Running Camel route...&quot;);</pre><pre>        Main main = new Main();<br>        main.configure().addRoutesBuilder(new RouteBuilder() {<br>            public void configure() throws Exception {<br>                from(&quot;timer:hello?period=3000&quot;)<br>                    .setBody().constant(&quot;Hello Camel!&quot;)<br>                    .to(&quot;stream:out&quot;);<br>            }<br>        });<br>        main.run();<br>    }<br>}</pre><p>After following the same steps as above, you’ll get the ouput log like this:</p><pre>$ kubectl logs -f jbang-script <br>jbang /scripts/script.java<br>[jbang] Resolving dependencies...<br>[jbang] Loading MavenCoordinate [org.apache.camel:camel-bom:pom:3.10.0]<br>[jbang]     Resolving org.apache.camel:camel-core...Done<br>[jbang]     Resolving org.apache.camel:camel-main...Done<br>[jbang]     Resolving org.apache.camel:camel-stream...Done<br>[jbang]     Resolving org.slf4j:slf4j-nop:1.7.30...Done<br>[jbang] Dependencies resolved<br>[jbang] Building jar...<br>Running Camel route...<br>Hello Camel!<br>Hello Camel!<br>Hello Camel!<br>...</pre><p>JBang can even <a href="https://www.jbang.dev/documentation/guide/latest/organizing.html">load multiple source files</a>, so there are no limits in what you can run with it!</p><h3>Wrap up</h3><p>Once you’ve created the script file script.java, ConfigMap jbang-script, and the YAML definition of Pod jbang-script, you won’t need to create another set again just for the purpose of running some Java code on Kubernetes/OpenShift. You can just modify script.java and run another experiment.</p><p>The sample code used in this article is also found here:</p><ul><li><a href="https://github.com/tadayosi/jbang-sandbox/tree/main/k8s">https://github.com/tadayosi/jbang-sandbox/tree/main/k8s</a></li></ul><p>I recommend this method if you want to verify something or run a brief task using Java on a Kubernetes/OpenShift cluster.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a6346e8a614" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install hawtio v1 on Apache Karaf 4.2.0 M2]]></title>
            <link>https://tadayoshi-sato.medium.com/install-hawtio-v1-on-apache-karaf-4-2-0-m2-b05fcd2cc141?source=rss-b42746ddc587------2</link>
            <guid isPermaLink="false">https://medium.com/p/b05fcd2cc141</guid>
            <category><![CDATA[hawtio]]></category>
            <category><![CDATA[apache-karaf]]></category>
            <dc:creator><![CDATA[Tadayoshi Sato]]></dc:creator>
            <pubDate>Fri, 02 Mar 2018 08:16:35 GMT</pubDate>
            <atom:updated>2018-03-02T08:16:35.719Z</atom:updated>
            <content:encoded><![CDATA[<p>If you want to install hawtio v1 on Apache Karaf 4.2.0 M2, simply doing the following doesn’t install hawtio unfortunately.</p><pre>&gt; repo-add hawtio<br>&gt; feature:install hawtio</pre><p>There are two additional features to install before hawtio.</p><pre>&gt; feature:install aries-blueprint<br>&gt; feature:install shell-compat</pre><p>Now you should be able to install hawtio.</p><p>In the future, we may need to add those required features to the hawtio feature so that users won’t be required to do the above steps. In the meantime, you can install hawtio by the above steps.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b05fcd2cc141" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[hawtio — How to change logging levels for hawtio-app?]]></title>
            <link>https://tadayoshi-sato.medium.com/hawtio-how-to-change-logging-levels-for-hawtio-app-94b501f86dc?source=rss-b42746ddc587------2</link>
            <guid isPermaLink="false">https://medium.com/p/94b501f86dc</guid>
            <category><![CDATA[logging]]></category>
            <category><![CDATA[hawtio]]></category>
            <category><![CDATA[jboss-fuse]]></category>
            <dc:creator><![CDATA[Tadayoshi Sato]]></dc:creator>
            <pubDate>Fri, 22 Sep 2017 07:11:23 GMT</pubDate>
            <atom:updated>2017-09-22T07:12:24.263Z</atom:updated>
            <content:encoded><![CDATA[<p>By default hawtio-app.jar runs with INFO logging level, but sometimes you may want to run it with DEBUG logging level to see what’s really happening under the hood.</p><p>In fact, hawtio-app.jar runs with an embedded Jetty server that uses theorg.eclipse.jetty.util.log.Slf4Log logging implementation and slf4j-simple, which enables you to configure the logging levels via org.slf4j.simpleLogger.xxxxx system properties.</p><p>Let’s change the default logging level toDEBUG. To do so, you can use -Dorg.slf4j.simpleLogger.defaultLogLevel=DEBUG:</p><pre>$ java -Dorg.slf4j.simpleLogger.defaultLogLevel=DEBUG -jar hawtio-app-1.5.4.jar</pre><p>In turn, if you only want to turn on DEBUG logging for a specific package or class (e.g. com.example.app), you can use -Dorg.slf4j.simpleLogger.log.&lt;namespace&gt;=DEBUG:</p><pre>$ java -Dorg.slf4j.simpleLogger.log.com.example.app=DEBUG -jar hawtio-app-1.5.4.jar</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94b501f86dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Securing Hawtio]]></title>
            <link>https://tadayoshi-sato.medium.com/securing-hawtio-f5fbfd5afcf0?source=rss-b42746ddc587------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5fbfd5afcf0</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[hawtio]]></category>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[jboss-fuse]]></category>
            <dc:creator><![CDATA[Tadayoshi Sato]]></dc:creator>
            <pubDate>Fri, 25 Aug 2017 09:23:21 GMT</pubDate>
            <atom:updated>2018-10-01T02:57:24.656Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://hawt.io/">Hawtio</a> is an awesome management tool for Java and JVM applications built on top of JMX. Hawtio utilises <a href="https://jolokia.org/">Jolokia</a> at its core, a library that opens up JMX with JSON over HTTP. Jolokia is a fantasitc library that makes JMX really easy and pleasant to use, but at the risk of unsolicited manipulations of MBeans from outside.</p><p>You might not need to be too nervous about security on Hawtio under development, but it is very important to make sure Hawtio is secured in your production system.</p><p>Just recently, two CVEs (XSS and CSRF) were reported against Hawtio:</p><ul><li><a href="https://access.redhat.com/security/cve/cve-2017-2589">CVE-2017–2589</a> hawtio: Proxy is sharing cookies among all the clients</li><li><a href="https://access.redhat.com/security/cve/cve-2017-7556">CVE-2017–7556</a> Hawtio: CSRF flaw via jolokia</li></ul><p>Good news is that solutions for both vulnerabilities are already built-in and available since Hawtio 1.5.0. In this blog post, I’d like to explain what you need to do to protect Hawtio from those two security vulnerabilities in production.</p><p>In summary, the following two things are mandatory to secure Hawtio before putting it into production:</p><ol><li>Review and (as necessary) configure thehawtio.proxyWhitelist system property</li><li>Set up jolokia-access.xml to limit allowed hosts and enable &lt;strict-checking /&gt; for CORS</li></ol><h3>Secure Hawtio proxy servlet by proxy whitelist</h3><p>To protect it from XSS (<a href="https://access.redhat.com/security/cve/cve-2017-2589">CVE-2017–2589</a>), Hawtio 1.5.0 introduced the whitelist for accessing Hawtio proxy servlet. By default only the IP addresses bound to the local machine (including localhost / 127.0.0.1) are whitelisted. So, out of the box Hawtio is safe against CVE-2017–2589! However, in turn you cannot connect to a remote Jolokia unless you explicitly add its hostname / IP address to the whitelist.</p><p><a href="https://stackoverflow.com/questions/43206932/unable-to-connect-to-remote-server-from-hawtio-dashboard">Unable to connect to remote server from Hawtio dashboard</a></p><p>If you don’t connect to a remote node from Hawtio, the default settings should be sufficient and you are already secured.</p><p>If you need to connect to a remote node, then the whitelist has to be configured via the hawtio.proxyWhitelist system property. For Karaf container, you can declare the system property in $KARAF_HOME/etc/system.properties like this:</p><pre>hawtio.proxyWhitelist = myserver1, myserver2, myserver3</pre><p>Note since Hawtio 1.5.1 you can also use regular expressions for the whitelist by prefixing them with r: like this:</p><pre>hawtio.proxyWhitelist = r:.+[.]example[.]com, r:192[.]168[.]1[.].+</pre><h3>Protect Jolokia from CSRF attacks</h3><p>The second thing to do is tighten up Jolokia. By default, Jolokia is open to CORS requests from every remote host for maximum availability. It is because Hawtio/Jolokia cannot know in advance which hostnames/IP addresses an user is going to use in their setup. However, this leaves out-of-the-box Hawtio vulnerable to CORS accesses from an unknown site and even CSRF attacks (<a href="https://access.redhat.com/security/cve/cve-2017-7556">CVE-2017–7556</a>)!</p><p>What you need to do is to define your own CORS policy with jolokia-access.xml and allow only trusted sites to send requests to and get responses from MBeans via Jolokia.</p><p><a href="https://ro14nd.de/Jolokia-CORS">Jolokia and CORS - Roland Huß</a></p><p>The jolokia-access.xml file should look something like this:</p><pre>&lt;<strong>restrict</strong>&gt;<br>  [...]<br>  &lt;<strong>cors</strong>&gt;<br>    &lt;<strong>allow</strong>-origin&gt;http*://localhost:*&lt;/<strong>allow</strong>-origin&gt;<br>    &lt;<strong>allow</strong>-origin&gt;http*://127.0.0.1:*&lt;/<strong>allow</strong>-origin&gt;<br>    &lt;<strong>allow</strong>-origin&gt;http*://*.example.com&lt;/<strong>allow</strong>-origin&gt;<br>    &lt;<strong>allow</strong>-origin&gt;http*://*.example.com:*&lt;/<strong>allow</strong>-origin&gt;<br>    <br>    &lt;<strong>strict</strong>-checking /&gt;<br>  &lt;/<strong>cors</strong>&gt;<br>&lt;/<strong>restrict</strong>&gt;</pre><p>Note the &lt;strict-checking /&gt; setting is really important for protecting from CSRF, as otherwise a malicious request to invoke a MBean operation may still be executed.</p><p>Once the jolokia-access.xml file is defined, you can use the jolokia.policyLocation system property to apply the policy to Hawtio’s Jolokia servlet. Again, for Karaf container, you can declare the system property in $KARAF_HOME/etc/system.properties like this:</p><pre>jolokia.policyLocation=file:///opt/hawtio/jolokia-access.xml</pre><p>Now your Hawtio is secured and ready for production!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5fbfd5afcf0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Remove CVS plugin from Eclipse]]></title>
            <link>https://tadayoshi-sato.medium.com/remove-cvs-plugin-from-eclipse-9a9c423b791c?source=rss-b42746ddc587------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a9c423b791c</guid>
            <category><![CDATA[eclipse]]></category>
            <dc:creator><![CDATA[Tadayoshi Sato]]></dc:creator>
            <pubDate>Fri, 08 Jan 2016 06:17:48 GMT</pubDate>
            <atom:updated>2017-08-25T04:18:02.176Z</atom:updated>
            <content:encoded><![CDATA[<p>The CVS plugin is tightly integrated with Eclipse, so it’s hard to uninstall it once installed unlike other plugins. To manually purge the plugin from Eclipse, remove the following directory &amp; jars:</p><pre>eclipse/<br> ├── features/<br> │    └── org.eclipse.cvs_1.4.100.v20150204-1700/<br> └── plugins/<br>      ├── org.eclipse.cvs_1.4.100.v20150204-1700.jar<br>      ├── org.eclipse.team.cvs.core_3.3.600.v20131112-1442.jar<br>      ├── org.eclipse.team.cvs.ssh2_3.2.400.v20131112-1442.jar<br>      └── org.eclipse.team.cvs.ui_3.3.600.v20130514-1224.jar</pre><p>Note I use Eclipse 4.4.2. Your versions of those items may be different. It works for me. I hope it works for you, too.</p><p><em>Originally published at </em><a href="https://tadayosi.wordpress.com/2016/01/08/remove-cvs-plugin-from-eclipse/"><em>tadayosi.wordpress.com</em></a><em> on January 8, 2016.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a9c423b791c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>