refactor: 将 JNI Java 示例从 jni/java 移至根目录 examples-jni
- 将 jni/java/ 整体迁移到 examples-jni/ - 更新 release.yml 中 JAR 构建路径为 examples-jni - 更新 build.gradle 默认 lib.path 为 ../target/release - 更新 README 与示例注释中的路径说明 Made-with: Cursor
This commit is contained in:
@@ -32,7 +32,7 @@ jobs:
|
||||
java-version: '11'
|
||||
|
||||
- name: Build fat JAR
|
||||
working-directory: jni/java
|
||||
working-directory: examples-jni
|
||||
run: |
|
||||
chmod +x gradlew 2>/dev/null || true
|
||||
gradle shadowJar -PprojectVersion=${{ github.event.inputs.version }} --no-daemon
|
||||
@@ -42,7 +42,7 @@ jobs:
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
tag_name: ${{ github.event.inputs.version }}
|
||||
files: jni/java/build/libs/dht-crawler-jni-example-${{ github.event.inputs.version }}.jar
|
||||
files: examples-jni/build/libs/dht-crawler-jni-example-${{ github.event.inputs.version }}.jar
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────
|
||||
# 各平台 Rust 构建(example 可执行 + JNI so/dll/dylib)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
## 项目结构
|
||||
|
||||
```
|
||||
java/
|
||||
examples-jni/
|
||||
├── build.gradle # Gradle 构建脚本
|
||||
├── settings.gradle
|
||||
└── src/main/java/cn/lmcw/dht/
|
||||
@@ -52,10 +52,10 @@ cargo build --release --features jni
|
||||
|
||||
#### 2. 运行 Java 示例
|
||||
|
||||
在本目录(`jni/java/`)执行:
|
||||
在本目录(`examples-jni/`)执行:
|
||||
|
||||
```bash
|
||||
# 使用默认库路径(../../../target/release)
|
||||
# 使用默认库路径(../target/release)
|
||||
gradle run
|
||||
|
||||
# 自定义库路径
|
||||
@@ -22,17 +22,17 @@ repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
// 运行时将 native 库路径传入 JVM
|
||||
// 运行时将 native 库路径传入 JVM(默认指向仓库根 target/release)
|
||||
tasks.withType(JavaExec).configureEach {
|
||||
def libPath = project.findProperty('lib.path') ?: '../../../target/release'
|
||||
def libPath = project.findProperty('lib.path') ?: '../target/release'
|
||||
jvmArgs "-Djava.library.path=${libPath}"
|
||||
}
|
||||
|
||||
// Fat JAR(含所有依赖 + Main-Class):执行 `gradle shadowJar` 生成
|
||||
shadowJar {
|
||||
archiveBaseName = 'dht-crawler-jni-example'
|
||||
archiveBaseName = 'dht-crawler-jni-example'
|
||||
archiveClassifier = ''
|
||||
archiveVersion = version
|
||||
archiveVersion = version
|
||||
manifest {
|
||||
attributes 'Main-Class': 'cn.lmcw.dht.DhtCrawlerExample'
|
||||
}
|
||||
+3
-3
@@ -14,9 +14,9 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
* <li>在仓库根目录编译 Rust JNI 产物:
|
||||
* <pre>cargo build --release --features jni</pre>
|
||||
* </li>
|
||||
* <li>在 {@code jni/java/} 目录下运行({@code lib.path} 指向 so/dll/dylib 所在目录):
|
||||
* <pre>gradle run -Plib.path=../../target/release</pre>
|
||||
* 或直接用默认路径({@code ../../../target/release}):
|
||||
* <li>在 {@code examples-jni/} 目录下运行({@code lib.path} 指向 so/dll/dylib 所在目录):
|
||||
* <pre>gradle run -Plib.path=../target/release</pre>
|
||||
* 或直接用默认路径({@code ../target/release}):
|
||||
* <pre>gradle run</pre>
|
||||
* </li>
|
||||
* </ol>
|
||||
Reference in New Issue
Block a user