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)
- Host: GitHub
- URL: https://github.com/tamimattafi/jni-calculator
- Owner: tamimattafi
- License: apache-2.0
- Created: 2025-05-28T18:56:00.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-28T19:11:52.000Z (about 1 year ago)
- Last Synced: 2025-05-28T20:05:33.802Z (about 1 year ago)
- Topics: ai, ai-agents, c, cpp, cursor, dll, dylib, gpt, gpt-4, java, jni, jni-android, jni-java, native, so
- Language: Shell
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.