How do I use API's in Netbeans for JAVA? - java

Ok so there are tonnes of API's out there. I need to use some of them like JIntellitype, iText, docx4j etc. But the problem is I do not know how to go about it in Netbeans.
I tried following the instructions in readme for all these API's but it does not work since there is something I am doing wrong. I am a newbie at JAVA and Netbeans.
Thanks!
[Update]
This is what I tried to do.
I downloaded the JIntellitype API. It contains lots of files including JAR,DLL,CPP etc. When viewed through File->Open Project from Netbeans this folder is displayed as a project.
I created a new JAVA Application project from Netbeans.
I right clicked the Project->Properties->Library and added the API folder there.
Then I tried importing one of the classes from the API called HotkeyListener as follows:
import jintellitype.HotkeyListener;
I received an error saying package does not exist.

Generally you have to add your API jar to your project. Open project properties, find where external libraries are added and add them. Once you are done you can import library classes and use them.

like AlexR said, you should add the jar file with the jintellitype.HotkeyListener in it, not just the directory. You can open jar files with winrar, winzip, 7zip etc...
Regards

Related

Import processing.video.* on Intellij

I am trying to run a mp4 video in Java using Processing.
I'm trying to use Intellij IDEA, but when I try to import processing.video.* it doesn't find the video library.
Where can I find and how can I import this library?
You need to do two things:
Find the .jar files (and any other files) required by the library.
Add those files to your classpath.
You can find the library files in your Processing directory. For me mine are in C:\Users\kevin\Documents\Processing\libraries\video\library, but it's going to depend on your OS and where you installed Processing.
You can also build the library yourself from this GitHub repo.
Now that you have those files, you can add them to your classpath. Since you're using Intellij, the links in Slaw's comment should get you pretty far:
Correct way to add external jars (lib/*.jar) to an IntelliJ IDEA project
Working with libraries - Intellij

Trouble importing libraries from Processing into Eclipse

I had a problem loading sound using the sound.processing library, so I am trying to use the ddf.minim library.
My Instructor imported the sound.processing library into processing AND Eclipse, and I don't remember how he did it. I tried going into processing and downloading minim from the sketch
When I try to import ddf.minim into my project, I get a red line under ddf. I also manually downloaded ddf.minim from github, removed the one previously installed, and I believe I had replaced it with the github files. I then went to add libraries in processing, and I still can't even import ddf.minim in Processing, let alone Eclipse!
Please help, I am just trying to get my sound to work in my Java project!
You need to add the Processing library and the Minim library to your classpath.
In Eclipse, to set your project’s classpath, right-click your project, and then click the Properties option. This brings up a dialog with all the settings you can specify for your project. Click the Java Build Path menu, and then the Libraries tab, which takes you to this screen:
This is your project’s classpath, and any library jars you want to use should be added here. Click the Add External JARs... button and select the .jar files that come with Processing. For basic sketches, I believe you only need the core.jar file.
Then for Minim, you can download the library .zip file from here. Unzip that wherever you want, and it should contain the .jar files that you need to add to your classpath.
Shameless self-promotion: here is a tutorial on using Processing as a Java library, and here is a tutorial on using Eclipse.

Referencing .jar files in NetBeans

I am trying to use FEST automation software. I am currently dealing with NetBeans 6.8 because it is what I have to use at work and am unable to upgrade the software at this time because of our system requirements
[TLDR: don't tell me to upgrade NetBeans because I can't]
I have downloaded the jar files from the google code repository and am trying to get a very simple application to work. I have tried adding the jar files to Libraries through the property panel for my project. NetBeans still cannot find these methods. Where else/how do I add these jar files to the class paths?
In order to use .jar files in NetBeans, you can either add the jar file to your global libraries or your local libraries. It sounds like you tried doing it locally without much success. I recommend adding a library such that you can just pick from your list of libraries without needing to reload it. I use NetBeans 8.1 so it may be just a bit different for 6.8.
What you need to do is go to Tools->Library
Then you need to click on New Library at the bottom left of the dialogue box.
AddLibrary
Name it and hit 'Ok'. Then, you'll add a new jar file by specifying your jar path. Hit 'Ok' again to save everything.
In order to use your new library, you'll need to then click on your Libraries folder in your project and add a new library. Select from the list of libraries the library you just created.
SelectLibrary
Finally, you import your individual files in your library using the #import keyword as per usual. If you want to import everything, you'd type something akin to
import MyNewLibrary.*;
To load a library the way you tried to do it, you'd right click the libraries folder and click "Add JAR/folder" instead of "Add Library". Then you'd import everything.
If you still for some reason cannot get your library to work, then you probably aren't importing using the right name. Or, you might be trying to load a static library without using the static keyword.

Android Studio: How to import java class from outside the project?

I'm working on an android game that requires a server. We've set up a git in which there are three folders: Client, Server and Shared:
Client contains the Android-Studio project.
Server contains an Eclipse project which is our server and database.
Shared contains java classes that I would like to use in both the Eclipse and Android-Studio project.
In Eclipse I successfully loaded the files from Shared by importing them as "file system". (It created a package and everything works great)
In Android-Studio, I can't find a solution that doesn't require me to copy-paste the classes in the project. The aim here is to have those file at only one location as they're susceptible to change but must me identical in both the projects... So those solutions don't fit my needs.
I'm looking for something like a way to link files from outside the project. (I managed to link libraries from inside the project already but not from outside)
The simple solution is to copy the desired java files into your project structure. Of course, you may have to change package names manually.
Found a solution that might not be optimal but at least in my case it solved the problem.
In Android-Studio:
Create a folder called something like "CommonEclipseAndroid" following a path similar to this one: project/Android/app/src/main/java/com/example/myapplication/CommonEclipseAndroid
Paste the code you need to use in both project inside this folder.
In Eclipse:
Right click on your project: Properties > Java Build Path > Source > Link Source and choose the folder we've just created.
Now your projects use the same code. You only need to modify it once for both projects and there's no risk of error.
Hope I helped :).
You can import the shared folder as a module .
go to file> new> import module
Now use the same imported folder in eclipse as well.

Jar file too big

I created a simple project using WindowBuilder in Eclipse and my goal is to send it by email. I don't know what kind of computer the person is using, so I exported my project into a 'Runnable JAR File' and checked the option 'Extract required libraries into generated JAR'.
The problem is that the generated JAR file is 20MB in size!!! The project has only one simple window - nothing complicated or fancy.
I found that some people use ProGuard to include only what is really needed.
I would like to know if there is a way to optimize it 'manually'? Are there libraries that are automatically included when creating a WindowBuilder project, and how may I determine which libraries I can remove?
Thank you.
I've had the same Problem using WindowBuilder. My solution was to look for the imports in my .java file, e.g.: import org.eclipse.swt.SWT;
In the Project Explorer in Eclipse you can see that there are much more imports than needed. Those 'Build Paths' can be removed carefully.
Simply rightclick on a .jar import like "com.ibm.icu_52.1.0.v201404241930.jar" and click on "Build Path" and "Remove from Build Path". Unfortunately, you can't remove or delete the packages inside the .jars.
But using this method, I managed to reduce the size from 20.7MB to 3.87MB. It's something...
Like fge said, send the source. Or upload the .jar to dropbox if you require you partner to access all of the files in the .jar.
If you don't like dropbox, find some other cloud storage solutions through a google search. Github or Bitbucket could also be an alternative to dropbox.
Cheers.
Use the Eclipse plugin FatJar. FatJar shows you which libraries are getting imported and allows you to specify which .jars, libraries, etc., that you want built into your JAR.
FatJar
Your jarfile is too big due of the project template. Create a sample java project, then use windowdbuilder components. Do not create a project Swing Template, by this way eclipse is gonna import all eclipse gui toolkits.
Tried it out with my way, my application's length equals to 3Ko against 24MO with the template project

Categories

Resources