I created one maven project in which only one class is available. I want to use jnetpcap API in this class. For this purpose, I followed jnet eclipse setup tutorial with Setup 1 approach (user library) and created one user library and added it to my project.
JnetTest.java - This class is same as jnetpcap clasic example
My system is Ubuntu 16.10.
I'm using openjdk version "1.8.0_131".
Library creation steps -
- I downloaded 1.3 version jar package, source package and javadoc package of jnetpcap and added libjnetpcap.so, jnetpcap.jar, jnetpcap-src-1.3.zip, jnetpcap-javadoc-1.3.zip to lib folder created under main project folder.
- created new library. Java-> Build Path -> User Libraries -> New -> Give Any Name.
- Add jar file. Add external jars -> workspace radio button -> selected lib/jnetpcap.jar
- fulfill the required dependency. expand jar -> source -> edit -> selected lib/jnetpcap-src-1.3.zip. javadoc -> edit -> selected lib/jnetpcap-javadoc-1.3.zip. Native library location -> edit -> selected lib directory. -> APPLY -> OK
- add library to project. right click on project -> Build Path -> Configure Build Path -> Libraries -> Add Library -> User Library -> select newly created library.
Note - I didn't added vm argument to my main class. i.e. -Djava.library.path="location to parent directory of .so file"
After that I right click on my project and clicked on a run as a java application. This will work in eclipse fine.
Actual problem - I want to run this maven project on one different machine with command line only. How I can run this project using command line?
My approach -
I added below plugin in pom.xml for main class configuration.
<!-- language: lang-xml --> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <executions> <execution> <goals> <goal>java</goal> </goals> </execution> </executions> <configuration> <mainClass>com.example.Main</mainClass> </configuration> </plugin>
I used mvn exec command to run my main class
mvn exec:java -Dexec.mainClass="com.example.Main"
But I got below exception -
Exception in thread "main" java.lang.UnsatisfiedLinkError:
com.slytechs.library.NativeLibrary.dlopen(Ljava/lang/String;)J
at com.slytechs.library.NativeLibrary.dlopen(Native Method)
at com.slytechs.library.NativeLibrary.(Unknown Source)
at com.slytechs.library.JNILibrary.(Unknown Source)
at com.slytechs.library.JNILibrary.loadLibrary(Unknown Source)
at com.slytechs.library.JNILibrary.register(Unknown Source)
at com.slytechs.library.JNILibrary.register(Unknown Source)
at com.slytechs.library.JNILibrary.register(Unknown Source)
at org.jnetpcap.Pcap.(Unknown Source)
My approach is correct or not to execute my project's main class? If yes then what will be the solution to my problem? If no please suggest useful approach.