I am new to Java and JNA. I was trying to access the native interfaces of a third party applications using JNA from Java eclipse. So I was trying to set the jna.library.path from Command line using the command
java -Djna.library.path=<path to your library> MainClass
I have given the "path to your library" as the path of the folder where my .dll file and its dependencies are there. for ex: D:Adrin\Library\Dll.
"MainClass" I have given the name of the class with main() in my application(Jnaexe.java). But an error occurs saying
Error: Could not find or load main class Jnaexe.java
I have also tried by giving the package name and also the whole path of the Jnaexe.java. Still it does't work. I tried running from the src folder and even the folder where Jnaexe.java file is there(example folder) in command prompt. But the error was same.What I am missing here. Any help will be highly appreciated. Thank you in advance
I've downloaded JAR archive from here. I want to know which class is the main. I checked Manifest file for main class specification Main-Class: com.some.className but it's not there. Where else could the main class be specified?
OkHttp is meant to be used as a library. One of the easiest ways to build java programs that need library dependencies is to use Maven. In the absence of Maven or other tools you can get the program running by copying the jar to a folder. You will also need to download okio.
To try the library out, create a java file in the same folder that contains the 2 jars and call this file GetExample.java . Paste the example source from the OkHttp site.
To compile the program, open a terminal/command prompt window and go to the location where you have GetExample.java and the jar files. Run the command:
javac -cp okhttp-2.1.0.jar GetExample.java
This should compile the file and create GetExample.class for you.
To run the program use the command:
java -cp okhttp-2.1.0.jar:okio-1.0.1.jar:. GetExample
or, if you are using windows (replace : with ;):
java -cp okhttp-2.1.0.jar;okio-1.0.1.jar;. GetExample
You should see the content of a README.md file.
I hope this helps.
I have a native android extension that referencing an android library project.
Inside referenced android library project I have several "JARs" in the "lib" folder.
I use eclipse to export a final "JAR" that referenced by the "extesion.xml" file.
All other jars that used to be included in the "libs" folder are referenced by dependancies xml file. that looks like this :
<platform xmlns="http://ns.adobe.com/air/extension/14.0">
<packagedDependencies>
<packagedDependency>async-http-client-1.8.6.jar</packagedDependency>
<packagedDependency>netty-3.9.0.Final.jar</packagedDependency>
<packagedDependency>slf4j-api-1.7.7.jar</packagedDependency>
<packagedDependency>slf4j-nop-1.7.7.jar</packagedDependency>
<packagedDependency>wasync-1.3.2.jar</packagedDependency>
</packagedDependencies>
<packagedResources>
</packagedResources>
Here how I export the final JAR using eclipse :
Now here is the command line that I use to build my ANE file :
adt -package -target ane GDAndroidNativeExtention.ane extension.xml -swc GDAndroidNativeExtention.swc -platform Android-ARM -platformoptions platform-options-android.xml -C android . -platform default -C default .
That builds me a nice ANE file which I then copy pasting into my IntelliJ IDEA 13.1.4 .
However when I am trying to compile to android the following error appears :
aapt tool failed:ERROR: 'C:\Program Files (x86)\Adobe Gaming SDK 1.3\AIR SDK\lib\android\lib\resources\android-res.jar' is not a directory
Well I would really like to know what it means and how it can be fixed.
I do know that the same extension works when I am compiling it without "platformoptions" command .But when I do that application runs but does not executes the code that referenced in jars. I can clearly see in the logcat messages like :
Could not find class 'com.ning.http.client.AsyncHttpClientConfig$Builder', referenced from method com.gd.server.connector.internal.http.TRXAtmosphereConnection.createConfigurableSocket
And I did already try to include those jars while exporting my extension from eclipse.It didn't see references to those jars even in that case.
Bottom line all I need is my extension to work.And I will be happy to know of any alternatives.
Thanks in advance.
I am trying to call a java program in a batch file. My java program calls a dll with JNA. When running batch file, it says it cannot find jna library class. I have already put jna jar files to my batch file folder. What can be the missing point?
My batch file:
#ECHO OFF
java -cp .;jna-4.1.0.jar com/sun/jna/Library
java MyBenchmark
I am getting below error:
java.lang.NoClassDefFoundError: com/sun/jna/Library
My jna jar file also same folder with my benchmark batch file too.
When use java -cp .;jna-4.1.0.jar com/sun/jna/Library, cmd gives that error also:
Main method not found in class com.sun.jna.Library
Library is an interface and my called java program uses that interface. But cmd says it cannot load it without main. I have to use it for reaching jna.
You must specify the ClassPath "-cp": java -cp [path to your jar] [class file to run]
Check this
If you use JNA and want to call a java program which use its library from batch file, you must avoid using java file. Because it can not load classes at runtime when you call jna.jar from batch too.
My code was like:
#ECHO OFF
java -jar jna-4.1.0.jar
java MyBenchmark
I tried many other solution too but nothing works(I also used code at question part too).
Lastly I tried export my project as jar and used it. First of all I want to state that my IDE was Intellij IDEA. It cannot put project dependency to my manifest file(jna path) although I put jar dependency already. So if you use IDEA, you must enter that from artifact screen manually, otherwise your jar cannot work right. Then you can put your jar under same folder with your bacth and call it like below:
java -jar MyJarFile.jar
I have been following this tutorial accordingly.
Up to running the FirstExample class in the command prompt is when it starts to freak out for some reason. After attempting to run the following command:
java FirstExample
I get the following exception:
Exception in thread "main" java.lang.NoClassDefFoundError: FirstExample
I understand that it can't find the FirstExample class due to the classpath (for some reason) so I executed the following command:
java -cp . FirstExample
And now it returns a new exception:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Now it can't find the JDBC Driver. This confuses me because for starters, I ran the exact same coding through Eclipse and it works as expected, and secondly, I went as far as to ensure that I execute the same class file that Eclipse is executing, and the command prompt still returns exceptions. I also went as far as to put the FirstExample file in a separate folder, just for the purpose of copying and pasting the MySQL Connector into the same folder, and I still get exceptions.
I just don't understand whats going on, can someone help me please?
Many thanks.
The file path to the connector is as followed:
C:\Program Files\MySQL\mysql-connector-java-3.1.14\mysql-connector-java-3.1.14-bin.jar
Hope this helps.
For testing purposes, I have placed the FirstExample class under the following path:
C:\java
This confuses me because for starters, I ran the exact same coding through Eclipse and it works as expected
This is because in Eclipse you add the libraries to the Build Path, and it will use all the libraries specified there in the classpath automatically when running your project. This can be noted here:
In order for you to execute your project using third party libraries from command line tools, you should specify the libraries manually in your classpath explicitly:
java -cp <path/to/mysql_jar/goes/here>:. FirstExample
By your comment:
the path to the MySQL file is: C:\Program Files\MySQL\mysql-connector-java-3.1.14\mysql-connector-java-3.1.14-bin.jar (...) I have placed the FirstExample class under C:\java
This should be the command line to use:
java -cp "C:\Program Files\MySQL\mysql-connector-java-3.1.14\mysql-connector-java-3.1.14-bin.jar; ." FirstExample
Note that it is better to store all the third party libraries in a single folder within your project, usually called lib, and put a reference to there. Assuming your current folder has a lib folder and all the third party libraries are copied there, the command line would be:
java -cp "lib\*; ." FirstExample
Use the next example to add your jars to the classpath:
java -cp "jdbc.jar;lib/*" my.package.FirstExample
You need to have the class com.mysql.jdbc.Driver (and all the imported classes) in the classpath too.
You should download the jar (http://dev.mysql.com/downloads/connector/j/5.0.html) and add it to the classpath.
The ClassNotFound Exception rises when there is an issue with the class name that you have written in Class.forName() or if the package is not set to the classpath variable. Make sure that you have added the jar file to the classpath ( C:............\jarfilename.jar;).
This is applicable for any JDBC Driver and jar files. The .jar files that are added to the classpath will not be visible to IDEs, in this case, you need to add the jar files to buildpath (in eclipse) or you can also copy the jar files to ext folder available in the Java installation folder.
Also note that the jar files of the DB Softwares may vary based on the DB software version that you are using for example if you are using the Oracle 11g, you need ojdbc6.jar file, in other versions of Oracle the number changes like ojdbc14.jar etc.