giving 'java.library.path' in netbeans for .dll/.so files - java

How do i give the path for the .dll or .so file in netbeans to load the library using
System.loadLibrary("Foo")
I read this on netbeans page but couldn't help me. as it gives the unsatisfied link error.
These are the two things i tried :
In the following snapshot i created a lib folder inside the netbeans project and placed the dll files inside it.
In the second snapshot i created a lib folder inside the modules folder and placed all the dll files inside lib folder as stated in the link.
But both of them give me unsatisfied link error exception. How do i set java.library.path in netbeans so that i can directly test the application from netbeans,
without having to go and write on the terminal ?

Its working now. Some little bit setting you have to do with your Netbean IDE.Only of Netbean IDE.
Follow the Steps :-
==>Right click on the Project
==>Properties
==>Click on RUN
==>VM Options : -Djava.library.path="C:\Your Directory where Dll is present"
==>Ok
Its working 100%. I have done this in my own project.

I'm using Mac OS X Yosemite and Netbeans 8.02, I got the same error and the simple solution I have found is like above, this is useful when you need to include native library in the project. So do the next for Netbeans:
1.- Right click on the Project
2.- Properties
3.- Click on RUN
4.- VM Options: java -Djava.library.path="your_path"
5.- for example in my case: java -Djava.library.path=</Users/Lexynux/NetBeansProjects/NAO/libs>
6.- Ok
I hope it could be useful for someone.
The link where I found the solution is here:
java.library.path – What is it and how to use

To me JDeveloper's suggestion didn't work. However, the method that I came across this early afternoon works handy.
It is for netbeans 8.02, and Visual Studio 2013 generated dll.
create a package(eg, "dll") under [Source Packages] node of netbeans
project
put/copy a dll file(eg, simpleDLL.dll) into the package(eg,
"dll")
on the [Libraries] node of the netbeans project, right-click
and choose "Add Jar/Folder...",
navigate to the folder("src") that contains the folder("dll") for the package that you created in step 1 above (it could be "...\src\dll" in my example), select package folder("dll") and click [Open] button to select it.
-- now you should have added a folder("dll") (which contains the dll file{simpleDLL.dll}) to the Libraries node of the project.
That's it. It should work!
Good luck.

IF you are working on "NetBeans Modules"
DLLs or SOs can be placed in the folder release/modules/lib/ in a module project's sources (look in the Files tab). This will make them appear in the final NBM or application in a lib subdirectory beneath where the module's JAR resides. Then just use System.loadLibrary as usual.

Related

To create an eclipse project from just the folders

I work in an organisation where i am provided with a folder having codes and other things for particular application.
I want to open this folder in eclipse and be able to navigate to all the classes that are used through resources(ctrl + click).
The problem is when I imported the folder the eclipse worked same as that of a notepad. Any changes no error would be shown.
I even added the required jar files for that project.
What should I do? I just need to navigate and check out the classes that are used and declared. Pls Help.
P.S. - I work on Ubuntu Machine.
If you have a java project, you may need to configure the source directory(s).
This can be done by right clicking on your folder -> Build Path -> Use as Source Folder.

Full java code from Netbeans Project

How can I get the full java code of a netbeans project? I have created a project for a contest, but need to submit the whole code. In Netbeans alot of the libraries and classes code is hidden. I need to submit all this. Even if a plugin needs to be installed.
Thank You :)
Assuming you have a NetBeans Project named HelloWorld in your system,let's assume that the default directory of storage of NetBeans Projects is in
C:\Users\USERNAME\Documents\NetBeansProjects\HelloWorld // On Windows OS
/home/NetBeansProjects/HelloWorld // On *nix(Linux,Unix) based OS
If it is different from the above,then please switch to the default directory of the Netbeans Projects.
Select your project folder from that,HelloWorld here.
It'll have several directories(folders) inside.
Switch over to src folder. All the .java files are placed in that directory. Those are the source code in Java. You can open and check and verify those files using any text-editor like Notepad,Gedit,etc.
NOTE :- DON'T DELETE ANY OTHER FOLDER/FILES unnecessarily,else,your NetBeans project won't be recognised/won't run properly.

Attach the Source in Eclipse of a jar

I added a Student.jar into my Build Path in my eclipse like this-
Right click on the project->BuildPath->Configure Build
Path->Libraries->Add External Jars
There is one class named StudentTest in Student.jar file. When I was debugging my code in eclipse, I stepped into that StudentTest class in the Student.jar.
And after that eclipse shows me like this-
The JAR file S:\some_location\Student.jar has no source attachment.
You can attach the source by clicking Attach Source below
Now I am not sure how should I attach the source in my eclipse. And from where? Can anyone provide me step by step what I need to do.
Update:-
I tried unzipping the Student.jar and I got Student folder. And after that I tried pointing the source to Student folder But still I am not able to see the class properly so that I can debug it properly, it shows the same above behavior.
Use Java Source Attacher !
It does what eclipse should do - a right click context menu that says "Attach Java Source.
It automatically downloads the source for you and attaches it. I've only hit a couple libraries it doesn't know about and when that happens it lets you contribute the url back to the community so no one else will have a problem with that library.
Eclipse is showing no source found because there is no source available . Your jar only has the compiled classes.
You need to import the project from jar and add the Project as dependency .
Other option is to go to the
Go to Properties (for the Project) -> Java Build Path -> Libraries , select your jar file and click on the source , there will be option to attach the source and Javadocs.
A .jar file usually only contains the .class files, not the .java files they were compiled from. That's why eclipse is telling you it doesn't know the source code of that class.
"Attaching" the source to a JAR means telling eclipse where the source code can be found. Of course, if you don't know yourself, that feature is of little help. Of course, you could try googling for the source code (or check wherever you got the JAR file from).
That said, you don't necessarily need the source to debug.
This worked for me for Eclipse-Luna:
Right Click on the *.jar in the Referenced Libraries folder under your project, then click on Properties
Use the Java Source Attachment page to point to the Workspace location or the External location to the source code of that jar.
Go back in to where you added the jar. I believe its the libraries tab, I don't have Eclipse open but that sounds right. to the left of the jar file you added there should be an arrow pointing right, click that and 3 or 4 options expand, one of them being the source file of the library. Click on that and click edit(I think you can also double click it) then locate the file or folder on your hard disk, you probably have to click apply or okay and you're good to go, same with javadoc and i think the last one is native libraries. I don't pay much attention when I'm in there anymore if you couldn't tell. That's what you were asking, right?
I Know it is pretty late but it will be helpful for the other user, as we can do Job using three ways... as below 1)1. Atttach your source code using i.e, Right click on the project then properties --> Java build path--> attach your source in the source tab or you can remove jar file and attach the source in the libraries tab
2. Using eclipse source Analyzer In the eclipse market you can download the plugin java source analyzer which is used to attach the open source jar file's source code. we can achieve it after installing the plugin, by right click on the open source jar and select the attach source option.
3. Using Jadclipse in eclipse you can do it last not the least, you can achieve the decompile your code using this plugin. it is similar way you can download the plugin from the eclipse market place and install in your eclipse.
in jadclipse view you can see your .class file to decomplile source format note here you cannot see the comment and hidden things I think in your scenario you can use the option one and option three, I prefer option three only if i want to the source code not for the debug the code. else i ll code the option 1, as i have the source already available with.
Simply import the package of the required source class in your code from jar.
You can find jar's sub packages in
Eclipse -- YourProject --> Referenced libraries --> yourJars --> Packages --> Clases
Like-- I was troubling with the mysql connector jar issue
"the source attachment does not contain the source"
by giving the path of source folder it display this statement
The source attachment does not contain the source for the file StatementImpl.class
Then I just import the package of mysql connector jar which contain the required class:
import com.mysql.jdbc.*;
Then program is working fine.
I faced the same issue and solved using the below steps. Go to Windows->preferences->Editors->File Associations
Here click on Add
then type .class
click on OK
again click on Add
then type .classwithoughtsource
click on OK
Now you will be able to see JadClipse option under Java section in Windows->Preferences
Please provide the path of jad.exe file as shown below.
Path for Decompiler-C:\Users\ahr\Documents\eclipse-jee-galileo-SR2-win32\jad.exe
Directory for temporary Files-C:\Users\ahr.net.sf.jadclipse
click on Apply
Now you should be able to see the classfiles in proper format.
It is quite possible, just go to the jar in the Build Path and choose to attach a source just like follow.
Download JDEclipse from http://java-decompiler.github.io/
Follow the installation steps
If you still didn't find the source, right click on the jar file and select "Attach Library Source" option from the project folder, as you can see below.
I am using project is not Spring or spring boot based application.
I have multiple subprojects and they are nested one within another.
The answers shown here supports on first level of subproject.
If I added another sub project for source code attachement, it is not allowing me saying folder already exists error.
Looks like eclipse is out dated IDE. I am using the latest version of Eclipse version 2015-2019.
It is killing all my time.
My intension is run the application in debug mode navigate through the sub projects which are added as external dependencies (non modifiable).
I have faced same problem and resolved it by using following scenario.
First we have to determine which jar file's source code we want along with version number. For Example "Spring Core" » "4.0.6.RELEASE"
open https://mvnrepository.com/ and search file with name "Spring Core" » "4.0.6.RELEASE".
Now Maven repository will show the the details of that jar file.
In that details there is one option "View All" just click on that.
Then we will navigate to URL "https://repo1.maven.org/maven2/org/springframework/spring-core/4.0.6.RELEASE/".
there so many options so select and download "spring-core-4.0.6.RELEASE-sources.jar" in our our system and attach same jar file as a source attachment in eclipse.
Try removing the breakpoints. :)

Eclipse giving errors whenever I try to export to executable jar

I'm trying to export a small program that I have made in Eclipse Indigo today to an executable, however, every time I do so one of two problems occur. The program uses one resource which I was hoping to put inside of the JAR but Eclipse will not put in the executable jar no matter which option I tick when I export or which folder the resource is in - the first problem!
The second problem is that whenever I tell eclipse to "Extract required libraries into generated JAR" I receive the following error when I double click on the executable Jar:
Could not find the main class: main.Launcher. Program will exit.
I don't suppose that the second problem is too much of an issue at the minute but the first one is extremely frustrating so I would appreciate any help or advice. Thanks in advance.
(Strangely, and even more frustrating, if I go through the same process with a project I made a while ago with a previous version of Eclipse it works perfectly.)
The folder structure of the project is as follows:
In the project folder there are the following directories .settings, bin, src as default. I have put the resource, which is a png in the bin folder but I have also tried it in the src folder.
Can you give some details?
What is the structure of your eclipse project?
Of what type is the resource?
More important where in the project structure resides the resource file?
Is the folder of that resource file included as a source folder ? (seems to be a prerequiste to get exported to the jar)
Is it copied over to the bin folder when the project is built?
Many Thanks
Michael
Update:
I have built a very simple java project 1 Java class with a main method and put a sample png file in the source folder. I refreshed the project to have the png visible in the project, then I cleaned the project to have it build again, then I ran the Main class inside eclipse. This will give you a run configuration when exporting throught the wizard. Thereafter I exported the complete project as "runnable jar", selected the run configuration and selected "Copy required libraries in a sub-folder next to the generated JAR". The png was included and the Main class was found. The executable JAR could be executed.
(Environment: Eclipse Indigo R1, Ubuntu, JDK 6)
You might want to play through the complete sequence of steps I went through. Maybe eclipse just did not pick up a file or other updates.
regards, Mike
First of all, I would like to thank Mike (marksml) for being so helpful and attempting to provide a solution for my problem. Unfortunately, his answer did not work for me!
I began to look at all of my previous projects and noticed that the one I was having trouble with was the odd one out (because it was the only one that didn't work) and the factor that made it the odd one out, I found to be the JRE system library version. The project was using the JavaSE-1.7 library but when I changed it to the JavaSE-1.6 like my other projects were using it miraculously worked and exported flawlessly! I'm still curious as to why this is the case, but at least I have it working now...
With thanks and kind regards, Andy

No projects are found to import - Helios eclipse

When downloading the 64 bit for Helios eclipse claims that there are no projects found to import - the file is swt-3.6-win32-win32-x86_64.zip
This should be fairly straight forward!!!!
On top of what Joe said:
The build path page is located in Properties (right click on project) -> Java Build Path. You can find the Libraries tab there.
I'd add one more step to the aforementioned workaround:
1) Extract the swt-3.6-win32-win32-x86.zip file (or another version, whichever you need)
2) The extracted folder contains 2 jar files swt.jar and swt-debug.jar
3) On the Java build path page of your project, open the Libraries tab. And add the swt.jar as an external jar.
4) Expand swt.jar on this tab, double click "Source attachment" and point to the archive named swt.zip (also comes in the top-level SWT archive), so that the javadoc will also be available for you.
And that's it - SWT should work like a charm from now on. Hope that helps.
There is a bug report on this: https://bugs.eclipse.org/bugs/show_bug.cgi?id=318680
I tried the recommended workaround (included below), but could not find the build path page, nor the Libraries tab, referenced in the workaround.
Instead, I right-clicked on the HelloWorldSWT package (in the Package Explorer window), selected Build Path -> Add External Libraries, and selected the jar file swt.jar. As the tutorial warns, there were compile errors, so I selected Source -> Organize Imports. The program now compiles and runs, but does not do anything. Inserting System.out.println() statements shows that it dies in creating the new Display().
I don't know if this helps [anyone], but I figured I'd share what I've tried so far. If anyone has any suggestions, they would be welcome.
For reference, in case it matters, I'm running Eclipse Helios (3.6) on Mac OS X (64-bit).
Here's the aforementioned workaround:
Lakshmi Shanmugam 2010-07-02 11:16:01 EDT
The step to import the SWT project from the zip is no longer valid. The
cheatsheet needs to be updated.
Please follow the below steps:
1) Extract the swt-3.6-win32-win32-x86.zip file
2) The extracted folder contains 2 jar files swt.jar and swt-debug.jar
3) On the Java build path page of your project, open the Libraries tab. And add
the swt.jar as an external jar.
Can't confirm - I just downloaded said file from the download page with no problem.
Importing projects is a workbench activity and not related to the eclipse installation process. Try a fresh install of a full 64Bit platform (one of the distributions from eclipse.org).
I have the same problem. There are instructions in the SWT HelloWorld tutorial linked from the Helios welcome page that instruct the user to first import the SWT project using File > Import ... then selecting Existing Projects into Workspace. When you specify the SWT archive, you get the error mentioned above "no projects found to import"
I think the problem is that the tutorial needs to be updated to reflect the fact that this archive is not an eclipse project and so cannot be imported in this fashion.
While it cannot be imported as a project, the jar can be linked; or, the source files can be turned into an eclipse project and the otherwise erroneous instructions can be followed from there.

Categories

Resources