Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
java-jni-test
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
java-jni-test
Commits
07843f4d
Commit
07843f4d
authored
Sep 07, 2017
by
fangzhipeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
0 deletions
+121
-0
lib/libhello.jnilib
lib/libhello.jnilib
+0
-0
pom.xml
pom.xml
+38
-0
src/main/java/com/paul0523/HelloWorld.java
src/main/java/com/paul0523/HelloWorld.java
+45
-0
src/test/java/com/paul0523/AppTest.java
src/test/java/com/paul0523/AppTest.java
+38
-0
No files found.
lib/libhello.jnilib
0 → 100755
View file @
07843f4d
File added
pom.xml
0 → 100644
View file @
07843f4d
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.paul0523
</groupId>
<artifactId>
java-jni-test
</artifactId>
<version>
1.0-SNAPSHOT
</version>
<packaging>
jar
</packaging>
<name>
java-jni-test
</name>
<url>
http://maven.apache.org
</url>
<properties>
<project.build.sourceEncoding>
UTF-8
</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<artifactId>
maven-compiler-plugin
</artifactId>
<version>
3.6.2
</version>
<configuration>
<source>
1.8
</source>
<target>
1.8
</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
<version>
4.12
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
</project>
src/main/java/com/paul0523/HelloWorld.java
0 → 100644
View file @
07843f4d
package
com
.
paul0523
;
import
java.io.IOException
;
import
java.lang.reflect.Field
;
public
class
HelloWorld
{
public
native
void
hello
();
static
{
try
{
//设置查找路径为当前项目路径,注意直接设置java.library.path属性无效
addDir
(
"/Users/fangzhipeng/Documents/workspace-idea/java-jni-test/lib"
);
//加载动态库的名称
System
.
loadLibrary
(
"hello"
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
static
void
main
(
String
[]
args
){
new
HelloWorld
().
hello
();
}
public
static
void
addDir
(
String
s
)
throws
IOException
{
try
{
Field
field
=
ClassLoader
.
class
.
getDeclaredField
(
"usr_paths"
);
field
.
setAccessible
(
true
);
String
[]
paths
=
(
String
[])
field
.
get
(
null
);
for
(
int
i
=
0
;
i
<
paths
.
length
;
i
++)
{
if
(
s
.
equals
(
paths
[
i
]))
{
return
;
}
}
String
[]
tmp
=
new
String
[
paths
.
length
+
1
];
System
.
arraycopy
(
paths
,
0
,
tmp
,
0
,
paths
.
length
);
tmp
[
paths
.
length
]
=
s
;
field
.
set
(
null
,
tmp
);
}
catch
(
IllegalAccessException
e
)
{
throw
new
IOException
(
"Failed to get permissions to set library path"
);
}
catch
(
NoSuchFieldException
e
)
{
throw
new
IOException
(
"Failed to get field handle to set library path"
);
}
}
}
src/test/java/com/paul0523/AppTest.java
0 → 100644
View file @
07843f4d
package
com
.
paul0523
;
import
junit.framework.Test
;
import
junit.framework.TestCase
;
import
junit.framework.TestSuite
;
/**
* Unit test for simple App.
*/
public
class
AppTest
extends
TestCase
{
/**
* Create the test case
*
* @param testName name of the test case
*/
public
AppTest
(
String
testName
)
{
super
(
testName
);
}
/**
* @return the suite of tests being tested
*/
public
static
Test
suite
()
{
return
new
TestSuite
(
AppTest
.
class
);
}
/**
* Rigourous Test :-)
*/
public
void
testApp
()
{
assertTrue
(
true
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment