I am working with Java and Eclipse, which are both a bit out of my comfort zone (yup , this is an assignment...).
I have 2 class
files which I need to use in my project. So far I have tried:
I tried adding an external class folder
:
classes\legacy
folder.Properties > Java Build Path > Libraries
I Clicked on the Add External Class Folder
classes
folder created in step 1.import legacy.*;
Result:
I can use the classes in the class
files but getting the following errors:
(seems to occur when the classes are attempting to use one another)
The project was not built since its build path is incomplete. Cannot find the class file for IshKesher. Fix the build path then try building this project
The type IshKesher cannot be resolved. It is indirectly referenced from required .class files
Note: tried for class folder
as well - same results.
Someone suggested that using jar files should be easier, so I gave it a try:
jar
file containing the class
files: jar cvf classes.jar ContactsList.class IshKesher.class
jar
file to the build path using this tutorial. Result:
Getting an error for each usage of classes in the jar file:
XYZ Cannot be resolved to a type
Any Ideas how make the class files available in my code?
EDIT:
It turned out that Attempt #2
worked once using my source files in the default package
(cannot figure out why though...).
Try my instructions.
If you don't want to include copy of Borat.jar, but only want to reference it from an external folder, then just do this one step -
No copy step -
Your java project > Right click > Build path > Configure
build path > add EXTERNAL jars button > select your jar
> ok.
If you want that jar to become a part of your java app, ie create a copy of the jar in your java app, then use the steps below.
Step 1- Create a lib folder in your app to store all jars
Your java project > Right click > New Folder > Folder Name = lib
Step 2 - Import all copies of the necessary jars into lib folder
Your java project > lib folder > Right click > import > General -->
File System > From Directory = The directory where you stored your jar files.
> ...You should now see the jars in that folder. Lets say we want to import
Borat.jar > Finish.
Step 3 - To check if step 2 is done correctly
Your java project > lib folder > Expand the lib folder to see its
contents. Borat.jar should be listed there. Nice !
Step 4 - Finally, to add the jars to the project
Your java project > lib folder > Right click > Build path > Configure
build path > add jars button > expand your project > expand lib folder
> Select Borat.jar > ok.