Eclipse, Java: How to import a library in zip-format?
Asked Answered
S

2

0

Ok, this is basic, but it seems that the normal way of doing this doesn't work for me.

I'm trying to import the jSSC library, for communication with serial ports etc. The newest library is jSSC-0.9.0-Release

So, I've tried the following:

  • Placed the zip file in the workspace and added it as "external jar" in the project properties -> java build path -> libraries.

Then I try including something from the library:

import jssc.SerialPortList;

Error: The import jssc cannot be resolved

  • Then I placed the zip file in a folder called /libs in the project root, and added it as "jar" (not external).

Result: Same error.

What basic info/action am I missing here, for this simple operation of importing a library?

Seabolt answered 17/1, 2013 at 9:26 Comment(2)
What is in the zip file? Are there the plain .class files or a .jar file?Unspoiled
It was a .jar file. My bad :-)Seabolt
V
5

Are you sure you should include the zip directly? In most releases, the zip contain a jar + readme + some documentation. I think you should take a look at the content of this zip file, perhaps extract it and only include the jar in your project.

Vert answered 17/1, 2013 at 9:29 Comment(2)
Oh my god. I read that the library could be in zip og jar format, so I actually didn't think about that. Also, I was sure I've imported a zipped library before. However, you're right of course. There was indeed (among other things) a jar file in the zipped archive, and using that solved it. Thanks.Seabolt
Glad it helped, if it is the right answer please mark it as such. The jar format is only a renamed zip file, but if you want the compiler to find classes inside it, they have to be at the root of the archive, they can't be found inside a sub-jar file.Vert
A
2

I believe that your zip file contains a lot of files including jar file with all classes you need, documentation etc. So, extract zip file, find jar you have to add to your eclipse project and do that.

The zip probably contains readme instructions. Read them. This will probably help you to install and use the library.

Amata answered 17/1, 2013 at 9:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.