Adding JAR to build path under a folder - java

New to Eclipse, and I'm trying to figure out how to add a JAR to a build path UNDER a (what looks like) a library or class path? Here's what I have right now:
And this is what I want to have:
You see how in the second image, the JARs "core.jar" "ext.jar" and "frameworks.jar" appear under "2231 Libs"? I can't get that to happen, and I've tried everything I can think of. I would really appreciate help with this. Thank you.

Java->Build Path->User Libraries preference page. There, define a library and add all your jars to it. Then add the library to your class path in the build dialog box that you show in your screenshot.
Eclipse Java Help Contents: User Libraries

Related

Eclipse not recognizing class after import of jar file

I have tried creating new projects. Removing and adding the jar file. Nothing is getting this thing to recognize it. I don't know if I am adding this correctly or not. Could someone please direct me, thanks.
EDIT: After some research using the help from the comments, it seems the problem is that the jar file only works if I am using a default package. I obviously don't want to use the default package so how can I change the Jar to fix this?
I don't know if this is a workaround or fix. I had to exclude the folders from my build path to use the jar file that had a default package. I did figure out how to deconstruct/reconstruct but for future reasons, I would not want to do this everytime someone hands me a file using the default pkg. So here is a screenshot of a working setup:
Please click it if it is not big enough for you. The summ/wint folders are excluded and I am able to use a class from the jar file without editing the jar file.
Money dd = new Dollar();
Thanks for all the comments.

BlueJ Importing custom class library

Ok the deal is, I've made a small class library (*.Jar file) to help make a more visually organized code and to help with some common tasks.
Before you tell me to go to: Tools > Preferences > Libraries.
I have done that, over and over and over again.. I also tried to manually add it to: C:\Program Files\BlueJ\lib\userlib\"jar file here"
And yes, i did restart BlueJ to load the newly added libraries.
No matter what i seem to try it won't let me import it to my project using the import command, but without it, it just won't compile.
I know i can just add the classes manually, but as the class library slowly grow, so does the effort of adding all the classes in that library.
In advance, thanks for your help and consideration.
If adding your jar file in the Preferences > Libraries tab doesn't work, you can try adding the jar to the "userlib" directory at <bluej-dir>/lib/userlib (where <bluej-dir> is the folder where BlueJ was installed).
A third option you can try is adding your jar file directly to a project by creating a +libs directory inside your project directory and copying the jar to that directory. This has the drawback that you have to manually copy the jar to each project +libs subfolder that needs your library. On the plus side, it allows you to distribute your project (library jars included) just by zipping up the root project directory.
On Windows I create directory named "+libs" on my blueJ project directory,
then add .jar to that directory, and restart blueJ ,
that´s help me, and import after that work fine
Despite the post's oldness for who stumble upon i can say with the newest version of BlueJ (actually 4.1.3) in an old Ubuntu distro(Lucid Lynx aka 10.04LTS) all work as intended per default without any hack

Adding external .jar file in Eclipse

I'm having trouble adding a .jar file I downloaded for my Java project. This is really the first time I've used eclipse, so please bear with me and for some reason (I have no clue why), I just find it somewhat confusing.
I know that in order reference different class files you simply need to create a class library and add it to the build path. From there, all which needs to be done (unless I'm misunderstanding this for whatever reason) is use the "import" keyword to import whatever .jar, .java, or .class/.interface file necessary into the project.
I've tried that with my .jar. I have it referenced in the build path (all I did was just copy the jar to the project directory, and then use the build path option to add it externally), but when ever try to call the object "Delegator", which obviously is a part of the .jar file, it won't read.
Am I missing something here? Seriously, anyone who knows the answer to this - you're relieving a mother of a headache. And before anyone asks - yes, I've searched this one to death. I've found similar questions, but nothing which quite hit what I was looking for. Either that, or I really just lack the common sense.
Right click on project->BuildPath->Libraries->Addexternaljar and then press ok and if it doesnot worked then you should go to the Order and Export tab and checked the jar you have just added in your project. It will solved your problem.
There are several possible reasons, for the question hasn't mentioned the specific failure, and where it has occurred. The following is a list of possible reasons I could think of, but this may not be exhaustive:
You can import a class, in a different package only if the class is public. The only exception is when you are using the class in the same package. If the class is an inner class marked as private, then you're well and truly out of luck. The Delegator class in question might not be public, and that's why you may be unable to use it. This issue ought to be caught by the compiler.
The directory structure within the JAR might not match your package import statements in your classes. This might not be necessary, for Eclipse ought to provide possible fixes, but it is better to verify that nevertheless. Again, the compiler should complain if this is the case.
If the issue is at runtime, then, it is most likely that the JAR is not available in the runtime classpath. You'll need to configure the Runtime configuration, to add the JAR to the runtime classpath. Refer to the Eclipse documentation on run configurations, if you need to know how to change the runtime classpath.
Note:
Exporting the build classpath entries would matter to other projects that depend on the pertinent project; unexported entries will have to be re-imported if required in other projects. This would not apply to a run configuration.
Update
Every Java application needs a main(String[] args] method to start execution. This is the entrypoint for the application. From the comment, it appears that the main method is in a different class. If so, the said class ought to be used to start the application. In Eclipse, a "Run configuration" might be used for the class that lacks this entrypoint, resulting in the described error. One can rectify this by creating a new Run configuration for the class with the said entrypoint. This may be done by one of the following:
editing the existing Run configuration to use the desired Class (the one with the main method). See the above link, in the third bullet point. Edit the value of the class to be launched.
creating a new Run configuration for the desired Class. Usually, you'll need to traverse to the desired class, and run your application (using the Alt+Shift+X+J shortcut) from the said class.
i was facing similar issue with spring jar files but then tried with different jar files and it work so I think , classes defined in jar files were private and not available outside of jar hence you were not able to access the file .
thanks ,
Raju Rathi
Right click on the project--->Build Path--->Configure Build Path...--->In left side you have to choose Java Build Path--->Libraries--->Add External JARs--->ok--->ok
Steps to add jar file in eclipse
1. right click on project
2. click on Bulid Path->configure path
3. click on java Build path
4. Click on libraries tab
5. click on add external jar tab
6. choose jar file
7 click on ok
Copy the .jar file in libs folder which you want to add in your project.
Right click on .jar file -> Add Build Path
Done.

lambdaj installation

we have downloaded jar files for lambdaj and its dependencies which are again jar files.
we do not know how to go about it. we have copied these files in the
C:\Program Files\Java\jre6\lib\ext
have set the class path in environment variales as:
variable: classpath
path: C:\Program Files\Java\jre6\lib\ext
but we do not know how to go further. we want to run some lambdaj programs.
can anyone suggest how to run lambdaj programs?
You would run a Java program that requires lambdaj in exactly the same way you'd run any other java program with an external dependency, i.e. by invoking the java executable passing in the fully-qualified name of the Main class, or the JAR with an appropriate manifest, or by deploying it in a servlet container, etc. Additionally you should be putting the LambdaJ JAR on the classpath for this invocation, not in the lib folder for your entire JVM.
What have you tried so far and why/how is it not working? Your question at the moment is a bit analogous to "I want to use Microsoft Word to view some Word documents, how do I do this?".
Update for comment 1: You said "it's not working". That doesn't help anyone address your problem as it gives no clue what you expected to happen and what you observed, only that they were different. As for where JAR files can be stored - you can put them in any directory, so long as that directory is on the classpath (or you add it to the classpath) of the Java application that runs. The canonical place to put external dependencies is in a folder called lib below the root of your project, but the important thing is that you choose somewhere consistent and sensible.
It sounds like you don't quite grok Java and classpaths yet. If you have followed some tutorials and are still stuck, ask for help to let you understand. Adding more detail to your question, including the layout of your files, the commands you issued, and the response that came back would be useful too.
If you are using Netbeans create a project and right click on the Libraries folder within the desired project. Click Add JAR/Folder...

Export Native library to external Package in Eclipse not working. is it a Bug?

I was about to report a but to Eclipse, but I was thinking to give this a chance here first:
If I add an external package, the application cannot find the referenced native library, except in the case specified at the below:
If my workspace consists of a single project, and I import an external package 'EX_package.jar' from a folder outside of the project folder, I can assign a folder to the native library location via:
mouse over package ->
right click ->
properties ->
Native Library ->
Enter your folder.
This does not work. In runtime the application does not load the library, System.mapLibraryName(Path) also does not work.
Further more, if I create a User Library, and add the package to it and define a folder for the native library it still does not.
If it works for you then I have a major bug since it does not work on my computer I test this in any combination I could think of, including adding the path to the windows PATH parameter, and so many other ways I can't even start to remember, nothing worked, I played with this for hours and had a colleague try to assist me, but we both came up empty.
Further more, if I have a main project that is dependent on few other projects in my workspace, and they all need to use the same 'EX_package.jar' I MUST supply a HARD COPY INTO EACH OF THEM, it will ONLY (I can't stress the ONLYNESS, I got freaked out by this) work if I have a hard copy of the package in ALL of the project folders that the main project has a dependency on, and ONLY if I configure the Native path in each of them!!
This also didn't do the trick.
please tell me there is a solution to this, this drives me nuts...
Update:
if anyone wants to try this for them selfs you can try to use JMF.jar and to refer to the native dlls, or the jmf.properties file, on my XP, I refer to the dll files and I don't need the jmf.properties file.
Thanks,
Adam Zehavi.
I missed the point that Eclipse does not export the native library.
here is a solution to what I was facing: Other answer

Categories