Hi I made one jar file with 3 classes.They work fine they are supporting file for getting HXM data.Now when i made jar i want to use it in my next project.I imported it and now it is in referenced libraries.But i can not find how can i use the libraries. in old project from i take the 3 .class file they have the paths: sk.csabi.hxm.*
but now how can i import and use them?
thanks
Your question isn't very clear but it seems like you're asking how to add the JAR to your project classpath in Eclipse.
What you're looking to do is add the libraries to your project's build path (the class path that will be used while compiling). In Eclipse, you can do this by right-clicking your project and choosing Properties (or hitting [Alt]+[Enter] when the project is selected in Project Explorer, Navigator or Package Explorer views) and then Java Build Path from the sidebar and the Libraries tab where you can add JARs.
Note the difference between Add JARs and External JARs is that External JARs will add an external dependency in your project since the absolute path to the JAR on your filesystem will be put into your project's configuration. With Add JARs you can select JARs from within your workspace.
I find it to be a good practice to create a lib folder (at the same level as my src folder) and put all my JARs in there and then add them to the build path with the Add JARs option. This makes the project portable since there are only relative paths referring to resources within the project rather than absolute paths or resources from other workspace projects.
Related
I'm building a Java Swing Application. This project requires a jar file called JCalender. I've added this to Libraries folder and everything works fine on my computer in NetBeans. But when i open the same project in my friends NetBeans, it doesn't recognizes this library. I've to manually select the file placed inside the projects dist/lib folder. How to avoid this? please help!
But when i open the same project in my friends NetBeans, it doesn't
recognizes this library. I've to manually select the file placed
inside the projects dist/lib folder. How to avoid this?
You can't avoid this because it's not a problem actually. To compile and run a project you need to have access to the external libraries involved in the development, so if you open your NetBeans project in a different computer than yours you will definitely need to resolve the reference to the external libraries. There's no way for the IDE to do it automatically as far as I know.
Can't i give the relative path to the lib folder for that specific
library somewhere in project properties?
You could just give it a try. IMHO if the real goal is to share a project with other developers then I'd change the strategy. I'd create a Library (Tools -> Libraries) and tell my mates to create the very same library including the JCalendar JAR files in the library's classpath. I'd include this library in the project properties and finally I'd use a versioning tool like Git or SVN to share the project.
By doing this your mates still need a copy of the JAR file wrapped in a NetBeans Library, but the project properties won't point to a fixed/relative path looking for a JAR file but wil include a reference to a given Library. The Library itself will resolve the dependency to the JAR file. If you take a look to the project.properties file you'll see something like this:
javac.classpath=\
${file.reference.jcalendar-1.4.jar}
But if you as I've suggested then you'll see something like this:
javac.classpath=\
${libs.JCalendar.classpath}
Here libs.JCalendar.classpath will resolve the dependency so your mates can have the actual JAR file located in whatever folder they like and the project should compile just fine.
Another option is using Maven to manage the projects dependencies but honestly I'm not a Maven expert so I can't help you in this path.
You need to do a "clean and build" and your jar will be in the dist folder. It will include the external jars
You can read more about it here
I think your problem is due to you are providing absolute path of jar file.
while choosing jar on write side of filechooser there is option of
Relative path and Absolute path there you should click on Absolute path.
i am new to java , but anyway , i have faced the same problem and found a solution for my project
If you are in Netbeans , its would be very easy for you
Let you project name is ABC and all your dependent jar file is under the
the folder MyResourceCollection
now we need to permanently import all jars under this folder ,
So from Netbeans ,
right click on your project name
go to properties
go to library
in the library page , check the "libraries folder" label
you can find a browse button at the right side of the label
click browse and select the MyResourceCollection folder
a new window will come , just press Next-->Next--->Finish
all is done , now check yourself by moving the folder into different location
I am new to Eclipse and Java, and I know that .jar files I need to add into libs derectory so that compiler could recognize them. How I can add .jars not only in libs folder but also in other folder too. How can I configure Eclipse to do that?
It's easiest if you have the jar files visible in the package explorer to start with, i.e. within your project directory. At that point, you can just right-click on the jar file, go to the "Build path" section of the context menu, then select "Add to build path".
If the jar file is elsewhere and you don't want to move it, you can right-click on the project, and under the "Build path" part of the context menu, select "Add external archives...". Then find the jar file in the file browser, and hit OK.
All of this can also be done from the project properties dialog, in the Java Build Path section.
Right Click project
Select Properties
Select Java Build Path
Under Tab Libraries Click on add jars or add external jar to add the required jars
The Java build path is used while compiling a Java project to discover dependent classes . It is made up of the following items:
Code in the source folders
Jars and classes folder associated with the project
Classes and libraries exported by projects referenced by this
project
Our goal is to feed our classes with the dependent classes present in the jars during compile time. Eclipse provies with number of easy ways to do it .Here you can find a good article about how to add the jars in the projects with screenshorts attached to it http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)
I have an existing java project and in that project there is a procedure that should programmatically create packages with source files inside them. It uses the standard File.mkdir() method to create all the unexisting directories for the package and then creates and writes the source files in there.
All works fine except that only the top folder created for a package path is marked by Eclipse as a package. The lower level folders remain just folders. For example, if I create a directory structure for package "org.prj.hey.this.is.cool", where "org.prj" is the existing path for my main project package, it then creates the rest of the path "/hey/this/is/cool" and only "hey" becomes an Eclipse package. I have found no way to make Eclipse recognize the "this", "is" and "cool" folders as packages. I haven't found any clues on this in the .project and .classpath files either..
So how do I make the whole branch of created folders be recognized by Eclipse as packages?
UPDATE:
(screenshot)
Found out that the issue is due to the file extension (see the picture). Is there any way to make Eclipse recognize .clj files as source files?
Problem exists in your current eclipse workspace buildpath configuration. Perform rightclick on your project name, then "Build path->configure build path..." and add newly created dirs to your current build path in SOURCE tab.
How to include (NOT ONLY reference) JAR file into existing project? I added it by using Project properties - Build path - add external jar's. But when I export my project, and then import it in another computer, this library was missing.
Drag it into your project view so it appears in the project as any other file.
Right-click the jar in the project view and add to build path.
Put your jars into a directory of your project e.g yourproject/lib so that external libraries are accessed through a relative path. And then use "Add JARs" option to add the jar to build path as in eboix's link.
You want to export your project as an archive (Export -> General -> Archive File), and then import your project as an existing project (Import -> General -> Existing Projects into Workspace). This way the project will be identical to the exported version and all of the configuration will be right.
Oh, and do what the other people suggest and copy the Jar file into the project so you don't have to reference it as an external Jar file (and everything is in one place).
EDIT: I appreciate the suggestions for Ivy or Maven, but this is just not an option for me at this time. I do not have the authority to use those tools. I am simply looking for a way to get my referenced .classpath JARs into a folder inside my project.
I have created a project that uses about 50 external JAR files that I referenced from other projects inside the same workspace.
Thus, my project's directory strucure looks like:
MyProject
src/
test/
Referenced Libraries/
... 50+ JARs
lib/
My project compiles and runs beautifully inside Eclipse. But now I need to add a buildscript so other developers can pull the project down from SVN and run it standalone. To do that, I'd like to place all the JARs that are currently in Eclipse's in-house directory Referenced Libraries and copy them into my project's lib directory which I will JAR-up with the final distribution.
I'm in Package Explorer, and have tried to just copy + paste the files from Referenced Libraries to lib/ and no dice. I get the following Eclipse error:
Cannot paste the clipboard contents into the selected elements.
Anybody have any idea how I can force this copy operation to work? If I right-click any JAR inside Referenced Libraries I see an Eclipse option called Migrate JAR file, but I'm afraid that would cut-n-paste the JARs from their current location to the new lib/ directory. This isn't feasible because there are many other projects that need these JAR files exactly where they are.
Thanks for any insight here!
Have you considered Maven? It's an exceptional tool for situations like this. For file operations it's best to use Navigator view.
I don't find another way to go but to copy yourself the jars into your lib folder, add the references to your lib files (not to external jars on your machine) and upload it to SVN.
EDIT to clarify:
Remove all references from your build path. Now you can't compile the project.
Copy every jar file you need to your project's lib folder.
Go again to build path and add the references to your jars (the ones on lib) one by one. Use the button that says "Add JARs...", not the one that says "external JARs".
Compile, and if everything is fine,
Upload the whole project to SVN.