Skip to content

Commit 442a897

Browse files
rajatkrishnailya-lavrenovlikholat
authored
[JAVA_API] Reorganize project structure and automatically load native libraries (openvinotoolkit#668)
* [JAVA_API] Restructure project directories to improve code organization * Moved java files to src/main/java * Moved cpp files to src/main/cpp * Moved tests to src/test/java * Updated gradle build script, CMake script and sphinx build config * [JAVA_API] Add gitignore Added .gitignore * [JAVA_API] Load native libraries in static initializer blocks * Add static initializer blocks to automatically load the required native libraries when the class is loaded * Introduce the NativeLibrary class to encapsulate the logic for finding and loading native libs * Fix java code style * Remove unused imports Remove unused imports to fix java code style * [JAVA_API] Remove static blocks from subclasses to avoid code duplication * [JAVA_API] Load native libraries in compatibility classes * Add static initializer block in compatibility classes to automatically load native libraries when the class is loaded * [JAVA_API][DOCS] Add instructions for running java tests * Add documentation for instructions on running Java tests in IntelliJ IDEA * [JAVA_API][DOCS] Build and IDE instructions * Add additional build instructions and dev env setup steps using IntelliJ IDEA * [JAVA_API] Fix Java samples * Remove explicit native library loads * Remove duplicate helper methods * [JAVA_API] Move test README * [JAVA_API][DOCS] Add instructions for running samples in IDE * Add instructions to run java benchmark app and face detection samples using IntelliJ IDEA * Fix typos * Update Java API test instructions Co-authored-by: Anna Likholat <aniali201398@gmail.com> * [JAVA_API] Restructure sample projects * Restructure Java sample applications to improve code organization * Fix OpenCV build/install path resolution for non-linux platforms * [JAVA_API][DOCS] Instructions for Java and Kotlin samples * Revert IDE formatting changes * [DOCS] Fix broken link * Fix link to test readme --------- Co-authored-by: Ilya Lavrenov <ilya.lavrenov@intel.com> Co-authored-by: Anna Likholat <aniali201398@gmail.com>
1 parent 6fdd359 commit 442a897

File tree

101 files changed

+524
-430
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+524
-430
lines changed

modules/java_api/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.gradle
2+
**/build/

modules/java_api/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ if(NOT OpenVINODeveloperPackage_FOUND)
1818
find_package(OpenVINO REQUIRED)
1919
endif()
2020

21-
file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/cpp/*.cpp)
21+
file(GLOB_RECURSE sources ${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/*.cpp)
2222

2323
add_library(${PROJECT_NAME} SHARED ${sources})
2424

2525
target_link_libraries(${PROJECT_NAME} PRIVATE openvino::runtime)
2626
target_include_directories(${PROJECT_NAME} PRIVATE ${JNI_INCLUDE_DIRS})
27-
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cpp)
27+
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp)
2828

2929
install(TARGETS ${PROJECT_NAME}
3030
RUNTIME DESTINATION ${IE_CPACK_RUNTIME_PATH} COMPONENT java_api

modules/java_api/README.md

+27-6
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@
99
To install OpenJDK:
1010

1111
* Ubuntu systems:
12-
```bash
13-
sudo apt-get install -y default-jdk
14-
```
12+
```bash
13+
sudo apt-get install -y default-jdk
14+
```
1515

16-
### Build
16+
## Build
17+
18+
To build OpenVINO so that it includes this module, use the following CMake command:
19+
```shell
20+
cd <openvino_build>
21+
cmake -DBUILD_java_api=ON -DOPENVINO_EXTRA_MODULES=<openvino_contrib>/modules <openvino_source_directory>
22+
cmake --build . -j8
23+
```
1724

18-
Set environment OpenVINO variables:
25+
Set OpenVINO environment variables:
1926
```bash
2027
source <openvino_install>/setupvars.sh
2128
```
@@ -26,6 +33,20 @@ cd openvino_contrib/modules/java_api
2633
gradle build
2734
```
2835

29-
### Import
36+
## Import
3037

3138
Use `import org.intel.openvino.*;` for OpenVINO Java API 2.0 or `import org.intel.openvino.compatibility.*;` for deprecated API.
39+
40+
## Set up the development environment
41+
42+
### Import to IntelliJ IDEA
43+
44+
- Install and enable the **Gradle** IntelliJ Plugin by navigating to **Settings** > **Plugins**. Search for the
45+
Gradle plugin and install it, if not already installed.
46+
- Clone the repository
47+
```shell
48+
git clone https://github.com/openvinotoolkit/openvino_contrib.git
49+
```
50+
- To import the project into IntelliJ IDEA, select **File** > **Open** and locate the java api module in `<openvino_contrib>/modules/java_api`.
51+
52+
See [here](src/test/README.md) for instructions on running tests.

modules/java_api/build.gradle

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
}
44

55
import org.gradle.internal.os.OperatingSystem
6+
67
println 'Operating system: ' + OperatingSystem.current()
78
def arch = System.getProperty("os.arch")
89
def ov_arch = arch;
@@ -60,26 +61,26 @@ native_resources.each {
6061
}
6162
}
6263
}
63-
file('native').mkdirs()
64-
file('native/resources_list.txt').text = "${resources_list}"
64+
file('src/main/native').mkdirs()
65+
file('src/main/native/resources_list.txt').text = "${resources_list}"
6566
sourceSets {
6667
main {
6768
java {
68-
srcDirs = ["org"]
69+
srcDirs = ["src/main/java"]
6970
}
7071
resources {
7172
srcDirs = native_resources
72-
srcDir 'native'
73+
srcDir 'src/main/native'
7374
}
7475
}
7576
test {
7677
java {
77-
srcDirs = ["."]
78-
include "tests/compatibility/*.java", "tests/*.java"
78+
srcDirs = ["src/test/java"]
79+
include "org/intel/openvino/compatibility/*.java", "org/intel/openvino/*.java"
7980
}
8081
}
8182
}
82-
repositories{
83+
repositories {
8384
mavenCentral()
8485
}
8586
dependencies {
@@ -90,4 +91,4 @@ test {
9091
systemProperty 'MODELS_PATH', System.getProperty('MODELS_PATH')
9192
systemProperty 'device', System.getProperty('device')
9293
}
93-
test.onlyIf { project.hasProperty('run_tests') }
94+
test.onlyIf { project.hasProperty('run_tests') }

modules/java_api/docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
html_title = 'OpenVINO for Java'
5454

5555
import subprocess # nosec
56-
subprocess.call('javadoc ../org/intel/openvino/*.java', shell=True)
56+
subprocess.call('javadoc ../src/main/java/org/intel/openvino/*.java', shell=True)
5757

5858
html_extra_path = ['.']

modules/java_api/org/intel/openvino/compatibility/IECore.java

-193
This file was deleted.

0 commit comments

Comments
 (0)