npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

java2faas

v0.3.2

Published

Transpiler to run Java code on ~any FaaS

Downloads

6

Readme

java2faas

Transpiler to run your Java code on both Amazon & IBM FaaS

GitHub

Install

npm i java2faas -g

Basic Usage

$ java2faas OPTIONS... 
  
  Options
    --path YOURAPPDIR 
    --name FUNCTIONNAME 
    --entry-file FPATH 
    --entry-method MNAME 
    --aws-role AWSROLEARN
    [--request-file FPATH] 
    [--response-file FPATH]
  • --path is the path to the root of your Java project.
  • --name (alphanumeric) is the name your FaaS function will have in your AWS / IBM console.
  • --entry-file should point to the Java file containing your Entry method.
  • --entry-method The method name you want to run inside --entry-file.
  • --aws-role The ARN of the Amazon IAM role your Lambda should have

Optional

These can be ommitted if you name the files accordingly, and place them with --entry-file.

  • --request-file (defaults to Request.java) should point to the class that describes your Input payload.
  • --response-file (defaults to Response.java) should point to the class that describes your Output payload.

java2faas will transpile your Java code, and put it into the newly created directories amazon and ibm, respectively.

Dependencies with Maven (pom.xml) are supported and automatically included.

Deploy your code

To Amazon Lambda

cd amazon
sh deploy.sh # afterwards, `sh update.sh`

To IBM Functions

cd ibm
sh deploy.sh # afterwards, `sh update.sh`

Tips

  • Maven is supported. You can specify something inside pom.xml (Dependencies...) and use it in your function.
  • The functions will run on Java 8, on both Amazon and IBMs

Example

.
└── src
    └── main
        └── java
            ├── Hello.java
            ├── Request.java 
            └── Response.java 

Hello.java

A class containing the entry point of the cloud function

// Class and method can have any name. Just specify it when running java2faas
public class Hello {
  public Response hello(Request inp) { 
    String greetingString = String.format("Hello %s %s.", inp.firstName, inp.lastName);
    return new Response(greetingString);
  }
}

Request.java

How the input to your cloud function will look. Make sure to include getters and setters.

public class Request {
  String firstName;
  String lastName;

  public String getFirstName() {
      return firstName;
  }

  public void setFirstName(String firstName) {
      this.firstName = firstName;
  }

  public String getLastName() {
      return lastName;
  }

  public void setLastName(String lastName) {
      this.lastName = lastName;
  }

  public Request(String firstName, String lastName) {
      this.firstName = firstName;
      this.lastName = lastName;
  }

  public Request() {
  }
}

Response.java

How the output will look. Make sure to include getters and setters.

public class Response {
  String greetings;

  public String getGreetings() {
      return greetings;
  }

  public void setGreetings(String greetings) {
      this.greetings = greetings;
  }

  public Response(String greetings) {
      this.greetings = greetings;
  }

  public Response() {
  }
}

Run java2faas

java2faas
    --path . 
    --name myFirstFn 
    --entry-file src/main/java/Hello.java 
    --entry-method hello
    --aws-role xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Note: If you don't name your files Request.java and Response.java, just specify --request-file FPATH and/or --response-file FPATH instead.

├── amazon
│   ├── pom.xml
│   ├── deploy.sh
│   ├── update.sh
│   └── src/main/java 
├── ibm
│   ├── pom.xml
│   ├── deploy.sh
│   ├── update.sh
│   └── src/main/java 
└── src
    └── main
        └── java

Deploy the function

Note: Make sure you are logged into the respective Provider CLI tool when you deploy (aws, ibmcloud)

cd amazon
sh deploy.sh 
# --

cd ibm
sh deploy.sh

Licence

MIT