Problems with jar - java

I have a project in Eclipse, that inculdes some files with data(not in classpath), and I want to pack this project to the runnable jar-file, but the problem is, that after I pack it to the jar, it's not located there. How can i add it to the jar?

Create an additional source folder and put your files in there. Unless explicitly told to Eclipse only jars things up in the classpath.
If you cannot do that due to some unmentioned restriction then please revise your question.

I would try making sure it's in the src folder. Eclipse tends to add everything in there into the JAR. If that's not an option, let me know in the comments.

Did you actualised your project's content in Eclipse before making the jar?
Right click on package explorer -> refresh.

Related

Jar disappearing from libs (source) folder in Eclipse after adding it to build path - is it bug or my doing something wrong?

I copied httpcore-4.4.4.jar into libs source folder in Eclipse (Photon, extends version) - like this:
As I see the jar is not on the build path. So I right-click on it and add it to the build-path. But after that the jar disappears from the libs folder! Yes, now I can see this jar in Referenced Libraries in Project Explorer but the fact that it disappears from libs folder is confusing.
Is it a bug or a feature? Or is it me doing something wrong?
Although everything works OK (despite that disappearing), it seems it was my mistake to make libs a source folder.
I should have made libs just a plain folder (File->New->Folder). Then everything works the same, but nothing suddenly disappears from that folder:
It is OK though to make a resources folder to be a source folder - the essence of source folder is that if Eclipse can't compile its content it would just copy it to output folder (bin by default).
The disappearing jar is a feature, please see step 5 in the following link:
https://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-(Java)
You might want to consider using a build/dependency management tool such as Maven, Ivy etc. which will manage dependencies to external libraries for you. This is especially useful if you are a group of people working on the code. If you use the lib folder, then you would have to add the libs to the source control system you are using, and add updates to libraries there. With Maven, you can just define which libs you want, and they will be downloaded and used automatically.

unable to find a lib folder in my project

I've been working on some project that involves Jar files to be added to build path. but one of my colleagues said that adding the jars to lib folder is advantageous compared to adding it normally.
Now my problem is, in eclipse, I right click and add a java project, but to my surprise I don't find a lib, earlier when I used to do J2EE apps, I used to find that. please let me know how can I fix this.
Thanks
In eclipse when you create a Java project, it doesn't create the lib folder along with it. This is something you want to do manually. At project level you can right click and add the folder. Then you can paste the jars into the folder, select the jars, right click, build path, Add to Build path.
Alternatively you can directly drag and drop to your Referenced Library. Both the ways are similar in effect, no difference.

Getting NoClassDefFoundError when using common.lang.StringUtils in android java code?

I am getting this error:-NoClassDefFoundError wherever the code is using StringUtils class or methods .I have correctly added the jar files to the code and is not showing any kind of error in my code(Using Eclipse Indigo).
Is there any kind of point I am missing out. I have used this jar file in other projects but they worked properly.
Please help If any one is getting similar kind of problem?Thanks
Yes, this because of your .jar file didn't import properly. Follow below steps -
Place your .jar file in your project's libs folder .
Import it into your project. And, GoTo project -> properties -> Java build path -> order tab.
Check, whether your .jar file checked and placed in order of 1st. This is the main thing.
Hope these steps helps you. Have a look at below image -
Note that the build classpath is different from the runtime classpath. You must add the required JARs to both.
It's one of the things I don't like in Eclipse...
EDIT: To add JARs to the runtime classpath: in Eclipse, double click the plugin.xml file associated with your project. On the Runtime tab there is a Classpath category. From there, you can add JARs to the runtime classpath.
Here is a screenshot to illustrate this:
Are the jar files in a lib folder or a libs folder?
Newer SDKs require the jar files to be in a libs folder.
I do not know how you execute your code, but it clearly means that the jar is not properly added to your classpath, especially if your code compiles in Eclipse.
Add it to your classpath -or re-check it is well added- when executing and it should work.
Right click on project, Select Build Path -> Configure Build Path and Select Libraries tab. Then with add Jars, add the jar in question.(if you are using eclipse)

Where the heck is the Android app's lib folder?

I've been trying to find the so-called lib folder, to install some 3rd-party tools (this) there. They tell you to: "place it (downloaded jar file) in your Android app’s libs/ folder". But, in Eclipse, I could not find the lib folder even after expanding all of the directories shown in the navigator area. Will someone tell me where this lib folder is? Thanks.
If you use Eclipse do the following:
Right-click your project and hit 'Project Properties'.
Choose 'Java Build Path'.
Choose the 'Libraries' tab.
Hit 'Add External JARs...'.
Navigate to your desired .jar-file and hit 'Open'.
Click 'OK'.
Then you should be able to reference your external library.
You have to create it if it's not already there. It should be in the top level of your project folder, at the same level as the src and res folders.
Your lib folder is indeed used for storing external libraries.
This is commonly used to hold external .jars for external libraries, similar to how a .dll works.
You need to place the files in this folder yourself, then add them to the project as an existing archive to use them.
Let me know if this is unclear or you have any more questions!
EDIT:
You need to make sure you're putting this in your imports:
import myLib.fullyQualifiedClassName.*;
Hope this helps!

Problem with imports in java?

I'm having a problem with imports in one of my java applications.
I've Taken a working JSP out of one Eclipse project, Jar'd up all the classes from that project and put it into a new project.
In the new Project I've imported the jar file generated from the original, and pasted the jsp code into a new JSP document.
I'm getting "The import XX could not be resolved errors".
Anyone one have any idea how to diagnose this, everything seems to be in order.
I have an issue like this once in awhile. Try removing the JAR, rebuilding, and adding the JAR again. This should fix it.
It's an Eclipse bug.
Edit: The above answer is assuming the jar is actually on the build path.
When you say "I've imported the jar file" you mean you have copied it or put it in the classpath?
When you add a Jar file, instead of Import, right click on the project and choose "Add External Library" or "Add External Jar"
It sounds like the jar you imported doesn't appear in your build path. Try right-clicking the project, select Build Path > Add External Archives...
This should put a reference to your jar in the project build path.
Check inside the Jar (just open it from the build path) and see if the paths are correct. If you have foo.Bar as something else than foo/Bar.class that might be it.

Categories