An open API service indexing awesome lists of open source software.

https://github.com/tamimattafi/jni-calculator

A simple Java calculator demonstrating the use of native methods via JNI (Java Native Interface) with a C implementation. This project shows how to connect Java and native code for basic arithmetic operations. (AI Generated)
https://github.com/tamimattafi/jni-calculator

ai ai-agents c cpp cursor dll dylib gpt gpt-4 java jni jni-android jni-java native so

Last synced: 4 months ago
JSON representation

A simple Java calculator demonstrating the use of native methods via JNI (Java Native Interface) with a C implementation. This project shows how to connect Java and native code for basic arithmetic operations. (AI Generated)

Awesome Lists containing this project

README

          

FULLY GENERATED BY CURSOR AND GPT 4.1 (Including the README file)

# JNI Calculator

A simple Java calculator demonstrating the use of native methods via JNI (Java Native Interface) with a C implementation. This project shows how to connect Java and native code for basic arithmetic operations.

## Structure

```
project-root/
├── src/
│ ├── main/
│ │ ├── java/com/attafitamim/demo/jni/calculator/ # Java source files
│ │ └── jni/ # Native C source files
├── build/ # Build output (classes, headers, native libs, JAR)
│ ├── classes/ # Compiled Java classes
│ ├── headers/ # Generated JNI headers
│ ├── lib/ # Compiled native libraries (.dylib/.so)
│ ├── output/ # Final runnable JAR, manifest, and native library
│ │ ├── calculator-demo.jar # Runnable JAR
│ │ ├── MANIFEST.MF # Manifest with native library info
│ │ └── libcalculator.* # Native library for your platform
│ └── ...
├── scripts/ # Helper scripts for building, cleaning, running
│ ├── build.sh # Build everything and produce runnable JAR
│ ├── clean.sh # Clean build output
│ ├── gen_jni.sh # Generate JNI headers and C stubs
│ └── run.sh # Run the generated JAR
└── README.md # Project documentation
```

- **src/main/java/com/attafitamim/demo/jni/calculator/**: Java source code for the calculator and JNI interface.
- **src/main/jni/**: C source code implementing the native methods.
- **build/**: All build artifacts, including compiled classes, JNI headers, native libraries, and the output JAR.
- **build/headers/**: Generated JNI headers.
- **build/output/**: Final runnable JAR and manifest. The manifest includes information about the native library path used by the application.
- **scripts/**: Shell scripts to automate building, cleaning, and running the project.

## Available Scripts

- **gen_jni.sh**: Generates JNI headers and C stubs for Java classes with native methods.
- **build.sh**: Cleans, generates JNI headers, builds native and Java code, and produces a runnable JAR.
- **clean.sh**: Removes all generated files in the build directory.
- **run.sh**: Builds the project (if needed) and runs the generated JAR, linking the native library.

## Running

Run the following commands from a bash-compatible shell (Unix/macOS, or Windows with Git Bash):

```bash
# Build the project and generate the runnable JAR
./scripts/build.sh

# Run the generated JAR (after building)
./scripts/run.sh
# The native library will be loaded from the same directory as the JAR (build/output)

# Clean the build output
./scripts/clean.sh
```

---

- Edit `src/main/jni/Calculator.c` to implement native methods.
- All generated files are in `build/`.
- The JAR can be used as a library or executed as a standalone program.

## Environment Variables

All common environment variables used by the build and run scripts are defined in `scripts/env/variables.sh`. You can edit this file to customize paths, output locations, and other settings for your project.