How to use JNA in Netbeans - netbeans

I downloaded jna.jar and I added it to my project, and I'm getting errors such as com.sun.jna does not exist, and I think the reason why my project doesn't work is because I can't import com.sun.jna.Native and the others.
Can someone please tell me how can I fix this?
Thanks in advance!

Had a similar problem myself and found that I needed to add the jar files to the Compile-time libraries. This automatically adds it to the run-time libraries. It's likely you only added the libraries as run time libraries, but not compile-time.
To do this you can do Project->Project Properties then select Libraries. On the Compile tab, click Add JAR/Folder for each library (jna-4.1.0.jar and jna-platform-4.1.0.jar, for example.)
After clicking OK, your compile errors should go away.
If you plan to use JNA in several projects, create a new library in Tools Libraries. Click on New Library... Type in JNA in the Library Name. In the Classpath tab, add the two .jar files by clicking on Add JAR/Folder... Click OK. To add the files to each project, then simply Project->Project Properties and Select Libraries. In the Compile tab simply click on Add Library... and select your new "JNA" library. Click OK. You'll see your JNA .jars as two stack of books icons under Libraries in the Projects view.

Related

Did not find "JAVADB_DRIVER_LABEL" in NetBeans IDE 8.0.2

I have installed NetBeans IDE 8.0.2.
When I am importing .zip file of my old project on which I was working, it's showing
"JAVADB_DRIVER_LABEL" could not be found (in projectNAME)
When I was adding that driver library it was not there in NetBeans' Library list. So what should I do to run my project ?
This is an old question, but for anyone searching in the future, here is my experience. When I shared a project with a customer which used Derby database, they needed to load the Java DB Driver, which in my case includes the derby.jar, derbyclient.jar, and derbynet.jar files. Until those where added, they got the JAVADB_DRIVER_LABEL error. In Netbeans, to do this you can either locate the *.jar files I referenced and add them in your Libraries folder in the project as jars, or use the "add library" option (right click on Libraries, Add Library) and select the "Java DB Driver" library which will add the necessary files.
I got that. We just Have to make New class Library and give it name "JAVADB_DRIVER_LABEL" and simply press OK button !
I have solved the problem:
You need to right click library and click add library
Create library
Put name whatever you want
Add jar for class path
Choose -derby.jar -derbyclient.jar -derbynet.jar
OK
Go to the beginning and add the library which is created by you

F3 on Eclipse doesn't go to the class that was selected

Background
I have multiple android libraries, each has its own classes.
The problem
For some reason, for classes that extend from one of those libraries' classes, when I click F3 to go to the class itself, I get an error:
"The Jar of this class file belongs to container 'Android Dependencies' which does not allow modifications to source attachments on its entries"
What i've tried
I've done some searching of this issue, and found multiple solutions (for example here, here and here), but none has worked for me:
clean project
set the order of the build path to have src at the end, while gen folder is before it.
update ADT, as it was probably fixed.
add "Source attachment", but this is impossible for android libraries (blocked for some reason).
The question
Why does it occur?
How come it's still occuring even on the newest ADT ( i have 22.3.0.v201310242005-887826 )?
Quoting from mik3y In Eclipse, how can I quickly access the source of an "android library project" from the source of a project that uses it?, which worked for me:
Right click on the non-library project (Project B) and select Build Path:
In the Projects tab, add the library project Project A as a dependency.
In the Order and Exports tab, be sure Project A is given higher precedence than the placeholder/bundle Library Projects.
I had to do both of these steps in order to fix this issue, with ADT15, Eclipse 3.7 and new projects.
EDIT:

Attempting to install library into netbeans (Xstream)

I am currently using the NetBeans IDE 7.3 for my Java development.
I downloaded a file called XStream.
http://x-stream.github.io/
I attempted to add the library to my project by right clicking on libraries and choosing Add Library. I then selected the top level folder for the downloaded Xstream; I was unable to import any of the Xstream files into my project. I am sure I am missing a simple step but Googling "Installing XStream in netbeans" does not reveal any how-tos.
I also right clicked Libraries and chose Add Jar/Folder and I still cannot import XStream.
Can someone please point me in the direction of a simple explanation for installing XStream in Netbeans so I can use it in a java project?
I tried the same thing as you, #Aaron and got the same result. However, when I drilled down and selected the xstream-1.4.8.jar instead of just the top level folder, I had success. I realize this is a couple years late, I'm just hoping this'll be useful for future readers.
In order to easily add libraries in Netbeans you must -
Locate your project in the project viewer window. Then click to drop down the project information.
Locate the "Libraries Folder"
Right click on the "Libraries Folder"
You may add a library there or a jar using that list
After you add the library you may want to make sure that the jar is in an easy to find location. I normally create a folder in my project and store the JAR file or libraries there in order to simplify locating them.

Installing a library (WiiRemoteJ) into NetBeans

I downloaded the WiiRemoteJ java library from here:
http://dl.qj.net/wii/homebrew/wiiremotej-v14.html
But I don't know how to install it into netbeans to use with a project!
I went to tools>Libraries, then clicked New Library... then typed "wiiremotej" as the name. Under class path, I navigated to the "WiiRemoteJ.jar" file. Then I added the JavaDocs folder.
When I created a new project and tried to import the library, (import WiiRemoteJ.*;) it gives me an error and says "Package WiiRemoteJ does not exist"!
The same thing happened with another wii remote library I tried (motej)
Does anyone know what i am doing wrong?
Well, the most straight forward approach would be to right click the project's Libraries node, and select Add JAR/Folder. This way you can use the JAR right away, without any additional registration.

Import Libraries in Eclipse?

I just recently downloaded the dom4j library, but for the life of me I have no idea how to access it. I dropped it in the plug-ins folder and rebooted Eclipse, without success. For some reason finding a straight answer for this is more difficult that I thought it would be.
No, don't do it that way.
From your Eclipse workspace, right click your project on the left pane -> Properties -> Java Build Path -> Add Jars -> add your jars here.
Tadaa!! :)
Extract the jar, and put it somewhere in your Java project (usually under a "lib" subdirectory).
Right click the project, open its preferences, go for Java build path, and then the Libraries tab. You can add the library there with "add a jar".
If your jar is not open source, you may want to store it elsewhere and connect to it as an external jar.
For the Android library projects, I do it as in the attached screenshot:
Right click the project, select Properties->Android and in the library section click Add. From here you can select the available libraries.
If you are importing a jar file, then importing them as jar or external jar, as other posters posted would work. I prefer to copy/paste jar file in the libs folder (create one if it doesn't exist) and then import as jar.
If you want to get this library into your library and use it, follow these steps:
You can create a new folder within Eclipse by right-clicking on your project, and selecting New Folder. The library folder is traditionally called lib.
Drag and drop your jar folder into the new lib folder, and when prompted select Copy Files.
Selecting the Project tab at the top of the screen, and click Properties.
Select Java Build Path followed by the Libraries tab.
Click the Add JARs… button and select your JAR file from within the lib folder.
Your JAR file will now appear in both the lib and Referenced Libraries folders. You can explore the JAR's resources by clicking Referenced Libraries.