The code in my Java project isn't finding the imports from a referenced library [message #1839437] |
Sun, 21 March 2021 14:09 |
Inas Zadi Messages: 4 Registered: March 2021 Location: England |
Junior Member |
|
|
Hi, I'm writing a project that uses two classes generated by a different program (Weka generates source code for a decision tree produced when providing one of its classifiers (in my case the J48 algorithm) with training data (recording occupancy of a room (T/F) based on 5 other attributes) that I found online).
I am using Eclipse, so I created a new Java Project in the default workspace, added an external archive to its build path (as I describe below), created two empty Java classes, and pasted in the Weka-generated code. These classes import various classes from the weka.jar file (originally in the program files of the Weka software) which I already added to the project's build path, but all the import lines come up with "Import X cannot be resolved" errors (X being the imported class).
I have two versions of the project:
- one where weka.jar is in a "lib" folder (at the same level as the "src" folder containing the two classes) which I right-clicked on in the package navigator of eclipse and selected Build Path->Add to build path
- the other where I right-clicked on the project and selected Build Path->Add External Archives, and navigated to and selected the weka.jar file (in its original location, the program files of the Weka software) as prompted.
I've done this before in the past with success, and I'm not sure why it's not working now? I've checked the classpath variable in Eclipse and added the path to weka.jar because it wasn't there previously as suggested by someone but the imports still aren't working. I've provided some screenshots to try and help illustrate the error and what seems to me to be no issue with the location of the jar file and classpath. Thanks for any help :)
Edit: UPDATE The error is now "The package weka.classifiers.trees.j48 is not accessible" instead of the previous "Import X is not available"
[Updated on: Thu, 25 March 2021 12:47] Report message to a moderator
|
|
|
|
Re: The code in my Java project isn't finding the imports from a referenced library [message #1839482 is a reply to message #1839473] |
Mon, 22 March 2021 12:04 |
Inas Zadi Messages: 4 Registered: March 2021 Location: England |
Junior Member |
|
|
Thanks for the reply :) in the attachment "Screenshot eclipse3" of my original post, I share a photo of the Classpath variable section of the Preferences window where we can see the path to the weka.jar file at the bottom.
I tried removing the jar from the classpath variable and adding it to the modulepath instead (eclipse did not allow for the same jar file to be added to both classpath and modulepath), refreshed the project and tried to run it again but the imports were still not working. I've attached screenshots of the jar file in the classpath and then the modulepath in case I did it incorrectly? I also saw there was the option to add a variable (rather than a jar) to the classpath and modulepath so I tried using those instead of the jar file directly, but this did not work either.
And after rereading your answer and seeing that you were talking about the library not the jar file, I added the library to the module path. For this I had to create a new user library which I called weka, and the imports still do not work. I've included this screenshot as well again in case I've done it incorrectly.
Edit: grammar
[Updated on: Mon, 22 March 2021 12:15] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05702 seconds