{"id":1503,"date":"2016-10-03T15:40:06","date_gmt":"2016-10-03T13:40:06","guid":{"rendered":"http:\/\/blog.rabahi.net\/?page_id=1503"},"modified":"2017-05-10T17:41:37","modified_gmt":"2017-05-10T15:41:37","slug":"java-jna","status":"publish","type":"page","link":"https:\/\/blog.rabahi.net\/?page_id=1503","title":{"rendered":"Java &#8211; JNA"},"content":{"rendered":"<blockquote><p>Java Native Access (JNA) is a community-developed library that provides Java programs easy access to native shared libraries without using the Java Native Interface. JNA&#8217;s design aims to provide native access in a natural way with a minimum of effort. No boilerplate or generated glue code is required.<br \/>\n<a href=\"https:\/\/en.wikipedia.org\/wiki\/Java_Native_Access\">Wikipedia<\/a>\n<\/p><\/blockquote>\n<h1>Dependencies<\/h1>\n<p>If you use maven, add this to your pom.xml:<\/p>\n<pre lang=\"xml\">\r\n<dependency>\r\n  <groupId>net.java.dev.jna<\/groupId>\r\n  <artifactId>jna<\/artifactId>\r\n  <version>${jna.version}<\/version>\r\n<\/dependency>\r\n\t\r\n<dependency>\r\n  <groupId>net.java.dev.jna<\/groupId>\r\n  <artifactId>jna-platform<\/artifactId>\r\n   <version>${jna.version}<\/version>\r\n<\/dependency>\r\n<\/pre>\n<h1>Example<\/h1>\n<p>Define map the java interface to the native library interface :<\/p>\n<pre lang=\"java\">\r\npublic interface CLibrary extends Library \r\n{ \r\n  \/**\r\n   * If we are under windows, load msvcrt.dll, overwise load c library.\r\n   *\/\r\n  CLibrary INSTANCE = (CLibrary) Native.loadLibrary((Platform.isWindows() ? \"msvcrt\" : \"c\"), CLibrary.class);\r\n\t\t\r\n  public int puts(String str);\r\n\t      \r\n  void printf(String format, Object... args);\r\n} \r\n<\/pre>\n<p>And use it like this :<\/p>\n<pre lang=\"java\">\r\nCLibrary.INSTANCE.puts(\"Hello World!\");\t    \r\nCLibrary.INSTANCE.printf(\"Hello World!\");\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Java Native Access (JNA) is a community-developed library that provides Java programs easy access to native shared libraries without using the Java Native Interface. JNA&#8217;s design aims to provide native access in a natural way with a minimum of effort. No boilerplate or generated glue code is required. Wikipedia Dependencies If you use maven, add [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1538,"menu_order":7,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1503","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1503"}],"version-history":[{"count":6,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1503\/revisions"}],"predecessor-version":[{"id":1943,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1503\/revisions\/1943"}],"up":[{"embeddable":true,"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=\/wp\/v2\/pages\/1538"}],"wp:attachment":[{"href":"https:\/\/blog.rabahi.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}