1

I have created app that uses jnetpcap. It should be multiplatform and runs on 32 and 64 platforms. I have never worked with maven befor, so how to add all versions of jnetpcap to project?

I found a solution that uses nar https://github.com/sugree/jnetpcap, but I don't understand how to use it properly.

Should I copy the structure of the project and compile jnetpcap in there? If this is nar, not dependency, how to add it to project, so I can use jnetpcap in java classes?

PS Also I have tried to add jnetpcap as dependency using conf from here: https://www.versioneye.com/clojure/jnetpcap:jnetpcap/1.4.r1425-1d

I have added this lines to my pom.xml:

  <repositories>
<repository>
  <id>clojars</id>
  <url>http://clojars.org/repo/</url>
</repository>

<dependency>
<groupId>jnetpcap</groupId>
<artifactId>jnetpcap</artifactId>
<version>1.4.r1425-1d</version>

It compiles with no errors, but when I try to execute project with command: exec:java -Dexec.mainClass="org.sample.Main" it crushes with error: "no jnetpcap in java.library.path".

Troir1
  • 53
  • 1
  • 9

1 Answers1

1

Your POM file is correct, but jnetpcap has a runtime dependency on a native library, which is why you are getting an error when you try to run your application. In order to resolve this you will have to specify the directory which contains native library during startup.

For example, on Windows this would look something like this:

java -Dexec.mainClass="org.sample.Main" -Djava.library.path=C:\jnetpcap-1.4.r1425

You can also include this directory as an environment variable - see the jnetpcap FAQ for more information on this.

Ben Damer
  • 906
  • 7
  • 13
  • This is not working in my case. Can you suggest me https://stackoverflow.com/questions/45220894/how-to-execute-maven-main-class-with-required-user-libraries/ – ketan Jul 21 '17 at 05:36
  • I've added an answer with more details to your specific use case. – Ben Damer Jul 24 '17 at 19:27