Link to home
Start Free TrialLog in
Avatar of Peter Chan
Peter ChanFlag for Hong Kong

asked on

Way to create the library

Hi,
Is there any demonstration/shared way, to create Java libraries, using Eclipse?

if I create one Java library, is there one place that I can register/put it, like, to one .com or .org site, to further share/use it?

When I'm to create one Java library, should I choose "Plug in Project", within Eclipse?
Avatar of Naitik Gamit
Naitik Gamit
Flag of India image

You must not create any library, if you use the same workspace.

Please read this points:
->Just use the source

In the properties of the project which has the dependencies you can add another source-folder:

Properties > Java Build Path > Tab: Source > Add Folder...

In the Project Tab you can "add" the whole project to the other project, too. There are many ways to achieve your goal.

->Create and add the library to the Build-Path

Adding an existing Jar (your own library):

If it is in the workspace:

Properties > Java Build Path > Tab: Libraries > Add JARs...

If it is somewhere on the drive:

Properties > Java Build Path > Tab: Libraries > Add External JARs...

->Exporting a source folder as a library

text Menu of Source Folder > Export > Jar File

There are two types: Executable Jars and "normal" Jars. You don't need an executable Jar.
Avatar of Peter Chan

ASKER

Thanks a lot.
Does it mean Jar file is executable, which can also be used as a library?
Is there any tutorials to create library/jar files?
I create one project
https://dl.dropboxusercontent.com/u/40211031/JLib.zip

using Eclipse. How to find out jar file from it?
How to get the Jar file to the recent project? Thanks
Right click on your project.
Choose Export -> Java -> JAR file
Choose included files and name output jar, click "Next"
Check "Save the description of this JAR in the workspace" and chose a name for the new jardesc file.
Many thanks. I try to run against the Jar file like

C:\Eclipse\JLib>java -jar JLib.jar
no main manifest attribute, in JLib.jar

Open in new window

how to correct the message prompted in above?
If you dont have a manifest in your jar invoking java -jar will not work.

Use this command if you dont have a manifest:

java -cp foo.jar full.package.name.ClassName

look at this conversations:

http://stackoverflow.com/questions/9689793/cant-execute-jar-file-no-main-manifest-attribute
http://stackoverflow.com/questions/1238145/how-to-run-a-jar-file
C:\Eclipse\JLib>java -jar JLib.jar

Open in new window


means it's a stand-alone app. Is it?
Thanks all.

CEHI,
yes
Then you haven't named the main class correctly in the manifest (done in the IDE if using one). Use the fully-qualified package name
Thanks. can I have the details to create manifest, to the project, using Eclipse?
I also get it from Help of Eclipse. Can you show me in details to do this? thanks
as per your question you can also use plugin........see below link

http://www.acnenomor.com/6064241p2/eclipse-create-runnable-jar-with-manifest-possible
Can I work with manifest, without the plug-in?
in Eclipse you can but.............but it is not runnable
If you're using Eclipse, you export as a jar to accomplish your goal:

http://help.eclipse.org/luna/topic/org.eclipse.jdt.doc.user/reference/ref-export-jar.htm

Make sure the application's entry point is set in the wizard. Then it will be runnable
Thanks a lot.
How to to resolve this

Description	Resource	Path	Location	Type
CalCl cannot be resolved to a type	CalCl3.java	/JLib3/src/CalCl3	line 3	Java Problem

Open in new window

using these codes?
package CalCl3;

public class CalCl3 implements CalCl {

}

Open in new window

While CalCl does exists within the another Java project, that is
https://dl.dropboxusercontent.com/u/40211031/JLib2.zip
I get the same problem, even if I adjust the codes to
package CalCl3;
import JLib2.Calcl;

public class CalCl3 implements CalCl {

}

Open in new window

I'm not really much of an Eclipse user, but does it run properly in the IDE?
I'm to compile it and then have got the issue. thanks
Can you try to open it, if available? thanks.
There's no main method in your last source - so it will never 'run' as such, but it will compile
Sorry, I am not able to compile these
package CalCl3;
import JLib2.Calcl;

public class CalCl3 implements CalCl {

}

Open in new window


why?
It's probably something to do with the way you have the projects linked. That import statement is also probably wrong
You didn't actually include Calc3 in the source you linked to
What to adjust to the codes above?
You need to name the packages correctly (I don't know what the names should be) and make sure the projects are linked thru the IDE
what to adjust to make it work?
what do you mean by "linked thru the IDE"?
I mean that IDEs give you the facility of sharing code amongst projects but they have to be told to do that. In your case, it sounds as if it could be better to create a library that's reusable rather than have it in a shared project.
But I did attach jar file to JLib3. Can you please tell me what is wrong inside it below?
https://dl.dropboxusercontent.com/u/40211031/JLib3.zip
That doesn't contain source for interface CalCl
No, JLib2.jar is under Referenced Libraries of JLib3 project.
See the attached
t965.png
You misunderstand - i'm saying it's not in that download - nor is there any jar IN it
Do you see the attached screenshot?
Well that looks good as far as the IDE is concerned, but of course doesn't help with that download. Find that referenced jar and run the following command on it, having changed to the directory which contains it. Then post the output please

jar tf  JLib2.jar

Open in new window

Here are what I get
C:\Eclipse\JLib2>jar tf JLib2.jar
'jar' is not recognized as an internal or external command,
operable program or batch file.

C:\Eclipse\JLib2>java
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
....

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial