# java2faas

> Transpiler to run Java code on ~any FaaS

Latest version **0.3.2** (published 2020-06-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install java2faas
pnpm add java2faas
yarn add java2faas
bun add java2faas
```

Provides the command `java2faas`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2020-06-11 |
| First published | 2020-02-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 56.7 KB |
| Known vulnerabilities | 0 (+3 in 2 direct dependencies) |
| Install scripts | no |
| Author | qngapparat |
| Maintainers | jakob.wallnoefer |

## Links

- npm: https://www.npmjs.com/package/java2faas
- npm.io page: https://npm.io/package/java2faas

## Dependencies (4)

- [arg](https://npm.io/package/arg.md) ^4.1.2
- [uuid](https://npm.io/package/uuid.md) ^7.0.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^8.1.0
- [fast-xml-parser](https://npm.io/package/fast-xml-parser.md) ^3.16.0

## Recent versions

- 0.3.2 (latest) — 2020-06-11
- 0.3.1 — 2020-05-30
- 0.3.0 — 2020-05-30
- 0.2.30 — 2020-03-16
- 0.2.29 — 2020-03-13
- 0.2.28 — 2020-03-13
- 0.2.27 — 2020-03-12
- 0.2.26 — 2020-03-12
- 0.2.25 — 2020-03-12
- 0.2.24 — 2020-03-12
- 0.2.23 — 2020-03-12
- 0.2.22 — 2020-03-11
- 0.2.21 — 2020-03-11
- 0.2.20 — 2020-03-11
- 0.2.19 — 2020-03-11
- … 35 more at https://npm.io/package/java2faas/versions

## README

# java2faas

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

[GitHub](https://github.com/qngapparat/java2faas)

## Install
```shell
npm i java2faas -g
```

## Basic Usage

```shell
$ 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

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

```

### To IBM Functions

```shell
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

```java
// 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.

```java
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.

```java
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`**

```shell
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

---
_Source: https://npm.io/package/java2faas · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
