JNA 编译-Djava.library.path

本文介绍了Java中使用native方法的方法,包括设置classpath和java.library.path的途径,并解释了为什么需要使用native方法。此外,还详细说明了如何配置native-hadoop库以避免警告信息。

转自:

http://yeelor.iteye.com/blog/1991075

 

一。如何使用native方法?

java一般使用两个path:classpath 和 java.library.path

classpath是指向jar包的位置。也就是JDK的lib目录

java.library.path是非java类包的位置如(dll,so)

配制方法:

1:LINUX下的系统变量LD_LIBRARY_PATH来添加java.library.path

2:在vm arguments里添加-Djava.library.path=所在目录

3:在 一个工程的Java Build Path中配置,如下图

 

 

二。为什么要使用native方法?

Java不是完美的,Java的不足除了体现在运行速度上要比传统的C++慢许多之外,Java无法直接访问到操作系统底层(如系统硬件等),为此Java使用native方法来扩展Java程序的功能。

 

 

 

 

三。Native Hadoop Libraries

默认没有配制native hadoop在跑MapReduce时会出现

13/12/18 10:57:59 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

13/12/18 10:57:59 WARN snappy.LoadSnappy: Snappy native library not loaded

 

如果选择自己编译Hadoop

提示:Execute failed: java.io.IOException: Cannot run program "autoreconf" 

yum install autoconf  automake  libtool

 

配置native-hadoop library 

1.配制Hadoop Library

2.在Hadoop Library里配置 native hadoop 目录

 

 

D:\JDK\bin\java.exe -Xmx700m -Djava.awt.headless=true "-Djna.boot.library.path=D:\实训\IntelliJ IDEA\IntelliJ IDEA 2025.2.1/lib/jna/amd64" -Djna.nosys=true -Djna.noclasspath=true --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED -Dpreload.project.path=D:/新建文件夹/620 -Dpreload.config.path=C:/Users/13978/AppData/Roaming/JetBrains/IntelliJIdea2025.2/options -Dcompile.parallel=true -Drebuild.on.dependency.change=true -Didea.IntToIntBtree.page.size=32768 -Djdt.compiler.useSingleThread=true -Daether.connector.resumeDownloads=false -Dio.netty.initialSeedUniquifier=860575406354421900 -Djps.use.dependency.graph=true -Dfile.encoding=UTF-8 -Duser.language=zh -Duser.country=CN -Didea.paths.selector=IntelliJIdea2025.2 "-Djps.language.bundle=D:/实训/IntelliJ IDEA/IntelliJ IDEA 2025.2.1/plugins/localization-zh/lib/localization-zh.jar" "-Didea.home.path=D:/实训/IntelliJ IDEA/IntelliJ IDEA 2025.2.1" -Didea.config.path=C:/Users/13978/AppData/Roaming/JetBrains/IntelliJIdea2025.2 -Didea.plugins.path=C:/Users/13978/AppData/Roaming/JetBrains/IntelliJIdea2025.2/plugins -Djps.log.dir=C:\Users\13978\AppData\Local\JetBrains\IntelliJIdea2025.2\log\build-log "-Djps.fallback.jdk.home=D:/实训/IntelliJ IDEA/IntelliJ IDEA 2025.2.1/jbr" -Djps.fallback.jdk.version=21.0.8 -Dio.netty.noUnsafe=true -Djava.io.tmpdir=C:/Users/13978/AppData/Local/JetBrains/IntelliJIdea2025.2/compile-serve
10-14
D:\jdk\bin\java.exe -Xmx700m -Djava.awt.headless=true "-Djna.boot.library.path=D:\idea安装\IntelliJ IDEA Community Edition 2025.2.3/lib/jna/amd64" -Djna.nosys=true -Djna.noclasspath=true --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED -Dexternal.project.config=C:\Users\y\AppData\Local\JetBrains\IdeaIC2025.2\projects\sims1.adf622b2\external_build_system -Dcompile.parallel=true -Drebuild.on.dependency.change=true -Didea.IntToIntBtree.page.size=32768 -Djdt.compiler.useSingleThread=true -Daether.connector.resumeDownloads=false -Dio.netty.initialSeedUniquifier=-5612769882385696046 -Djps.use.dependency.graph=true -Dfile.encoding=UTF-8 -Duser.language=zh -Duser.country=CN -Didea.paths.selector=IdeaIC2025.2 "-Djps.language.bundle=D:/idea安装/IntelliJ IDEA Community Edition 2025.2.3/plugins/localization-zh/lib/localization-zh.jar" "-Didea.home.path=D:/idea安装/IntelliJ IDEA Community Edition 2025.2.3" -Didea.config.path=C:/Users/y/AppData/Roaming/JetBrains/IdeaIC2025.2 -Didea.plugins.path=C:/Users/y/AppData/Roaming/JetBrains/IdeaIC2025.2/plugins -Djps.log.dir=C:\Users\y\AppData\Local\JetBrains\IdeaIC2025.2\log\build-log "-Djps.fallback.jdk.home=D:/idea安装/IntelliJ IDEA Community Edition 2025.2.3/jbr" -Djps.fallback.jdk.version=21.0.8 -Dio.netty.noUnsafe=true -Djava.io.tmpdir=C:/Users/y/AppData/Local/JetBrains/IdeaIC2025.2/compile-server/sims1_c0fff7a1/_
最新发布
10-23
C:\Users\小姚\.jdks\openjdk-23.0.2\bin\java.exe -Xmx700m -Djava.awt.headless=true "-Djna.boot.library.path=C:\Program Files\JetBrains\IntelliJ IDEA 2024.3.4.1/lib/jna/amd64" -Djna.nosys=true -Djna.noclasspath=true --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED -Dpreload.project.path=C:/Users/小姚/IdeaProjects/untitled2 -Dpreload.config.path=C:/Users/小姚/AppData/Roaming/JetBrains/IntelliJIdea2024.3/options -Dcompile.parallel=true -Drebuild.on.dependency.change=true -Didea.IntToIntBtree.page.size=32768 -Djdt.compiler.useSingleThread=true -Daether.connector.resumeDownloads=false -Dio.netty.initialSeedUniquifier=-5578464900214876872 -Djps.use.dependency.graph=true -Dfile.encoding=UTF-8 -Duser.language=zh -Duser.country=CN -Didea.paths.selector=IntelliJIdea2024.3 "-Djps.language.bundle=C:/Program Files/JetBrains/IntelliJ IDEA 2024.3.4.1/plugins/localization-zh/lib/localization-zh.jar" "-Didea.home.path=C:/Program Files/JetBrains/IntelliJ IDEA 2024.3.4.1" -Didea.config.path=C:/Users/小姚/AppData/Roaming/JetBrains/IntelliJIdea2024.3 -Didea.plugins.path=C:/Users/小姚/AppData/Roaming/JetBrains/IntelliJIdea2024.3/plugins -Djps.log.dir=C:/Users/小姚/AppData/Local/JetBrains/IntelliJIdea2024.3/log/build-log "-Djps.fallback.jdk.home=C:/Program Files/JetBrains/IntelliJ IDEA 2024.3.4.1/jbr" -Djps.fallback.jdk.version=21.0.6 -Dio.netty.noUnsafe=true -Djava.io.tmpd
03-20
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值