unable to find a lib folder in my project - java

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.

Related

Project is missing required library - but correct JAR exists?

One of my eclipse projects gives me the Project X is missing required library: 'somelib.jar' error, but when I go to Configure Build Path > Libraries the library is present, and no error is indicated there.
I tried the usual things:
Clean build (all projects in the workspace)
Exited eclipse multiple times
My coworkers, using the same git checkout with the same status as mine, and also using eclipse Neon2, have no build errors.
Just to be sure, I navigated into the corresponding directory and removed a different jar file, and when I look at my build path configuration that jar shows up with a red "x" indicating that the library is missing.
I checked that somelib.jar sits in the expected place and is a valid JAR file.
How do I fix this?
These steps did resolve the problem:
closing / re-opening the corresponding project
another "full" clean of all projects in the workspace
In other words: it seems that a simple F5 "refresh" and a even a "clean project" isn't sufficient sometimes. So closing the project is the key element here!
Some times eclipse becomes naughty following steps should be taken to nicely add the jar library in project
First remove the library from libs folder
Also remove the refrence from java build path in external library tab
Clean the project let it actually realize the library is missing :D
Again copy the jar file in libs folder
Add the refrence of library in java build path library tab
set the priority of this library to top (important) because its
possible the order of library export is not ok in your project
Clean the project and build
hope so it will solve your problem
If you have multiple projects opened in such way that one depends on another, and the problematic project depends on others, refreshing all dependent projects will fix the 'missing library' issue for the main project.

IntelliJ external jar relative path

I'm just trying out IntelliJ IDE and I want to add an external jar to my java project.
I have already figured out how to add external jars to my project in ProjectSettings -> Modules -> Dependencies. But the path is always absolute. I haven't found a way to make the path relative to the project folder (my lib folder is inside my project folder).
e.g. I don't want this
C:\Users\AUser\IdeaProjects\AProject\lib\alibrary.jar
Instead I want this. ...\AProject\lib\alibrary.jar
In Netbeans this was possible by just checking a checkbox.
Is there something similar in IntelliJ?
If not, how do you deal with the situation when someone else is trying to open up your project? Does he need to edit all library paths?
I observed everything in .\lib\ are always automatically re-mapped correctly when the project is moved or when I open a shared project.

Including external jars permanently in NetBeans

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

Java runtime error "NoClassDefFoundError" when referencing external project in Eclipse Android Project

I am struggling with this issue for some time now and I think it is time that I appeal to the SO community.
When creating a new Android Project in Eclipse I am trying to reference an external project [for the time being, it is a simple class with a function that returns a string]. I have tried adding a reference to the project itself, I have tried exporting a .JAR file [adding it to the libs folder] but none of these solutions work, though at compile time the classes are seen, at run time I get the dreaded NoClassDefFoundError.
Because the JAR file is present both in the filesystem and the .classpath file, I believe there might be an issue with the way I exported the JAR.
I am not sure why it doesn't work or what the proper workflow is for adding such [non-Android] modules to a project. Any help would be greatly appreciated!
I have come across this issue in a lot of SO questions but I could not find any solutions that would work
I've actually had the same problem before. There are a couple things you can try.
Make sure that in the project properties for your external project that you have the the "Is Library" checked in the Android tab.
Then export the project as a jar file. (make sure you don't include and files other than the actual java class files. No AndroidManifest.xml etc...)
Include the jar file into your other project in the "libs" folder like you were doing before.
and you should be able to reference the class from the jar now.
If that still doesn't work, you might have an ordering issue, so right click the jar file, and select "Build Path" -> "add to build path", then go to the project properties of your non-library project and select Java Build Path -> Order and Export and move the jar file to the top of the list.
Hopefully this helps!
Cheers

After building the project from pom.xml using Maven, how do I use its resources

It's been tedious. This is the API I am trying to use. Its resources were set up in a pom.xml which I built using Maven. On built up, it gave me the project socrata-publisher that has
src/main/java the source folder with packages com.socrata.api com.socrata.data, com.socrata.util where each contains only .java
files
JRE System Library and Maven Dependency hierarchies where each contains a number of jar files
Problem is com.socrata.api and the 2 other contains classes which I want to deploy in a project outside socrata-publisher. I tried using import com.socrata.api but it didn't work. Moreover, since its a Java project and not android it doesn't have the is Library option in preferences which could rather give me the solution. Both socrata-publisher and tutorial (where i want to use the resources and which is the android application) lie in the same directory eclipseApps in My Documents.
Here's a little visual queue. Help will be greatly appreciated.
You will need to first of all get the output of the socrata project and all its dependencies.
In command line, going to the project folder of the socrata project, where the pom.xml file is, run MVN INSTALL. You shall see a jar file called socrata-api.jar in $HOME/.m2/repository. If you are using windows and installed MAVEN by default, $HOME should be your user profile folder. Once you see the jar file, add it to your tutorial build path.
I think what you actually want to do is just set up the "socrata-publisher" as a project dependency for your "tutorial" project. That will allow you to reference the built Socrata libraries from the code in your project.
Right click on the project and select "Properties". From within that dialog select "Java Build Path" on the left, then the "Projects" section, and click the "Add" button to add the "socrata-publisher" project.
I think that'll work better than creating a separate jar file that you then include, and then you can also keep the socrata-publisher code up to date using Git.

Categories