Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 105
  • Last Modified:

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?
0
HuaMinChen
Asked:
HuaMinChen
  • 22
  • 12
  • 7
1 Solution
 
Naitik GamitSoftware DeveloperCommented:
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.
0
 
HuaMinChenBusiness AnalystAuthor Commented:
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?
0
 
HuaMinChenBusiness AnalystAuthor Commented:
I create one project
https://dl.dropboxusercontent.com/u/40211031/JLib.zip

using Eclipse. How to find out jar file from it?
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
HuaMinChenBusiness AnalystAuthor Commented:
How to get the Jar file to the recent project? Thanks
0
 
Naitik GamitSoftware DeveloperCommented:
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.
0
 
HuaMinChenBusiness AnalystAuthor Commented:
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?
0
 
Naitik GamitSoftware DeveloperCommented:
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
0
 
CEHJCommented:
C:\Eclipse\JLib>java -jar JLib.jar

Open in new window


means it's a stand-alone app. Is it?
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Thanks all.

CEHI,
yes
0
 
CEHJCommented:
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
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Thanks. can I have the details to create manifest, to the project, using Eclipse?
0
 
Naitik GamitSoftware DeveloperCommented:
0
 
HuaMinChenBusiness AnalystAuthor Commented:
I also get it from Help of Eclipse. Can you show me in details to do this? thanks
0
 
Naitik GamitSoftware DeveloperCommented:
as per your question you can also use plugin........see below link

http://www.acnenomor.com/6064241p2/eclipse-create-runnable-jar-with-manifest-possible
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Can I work with manifest, without the plug-in?
0
 
Naitik GamitSoftware DeveloperCommented:
in Eclipse you can but.............but it is not runnable
0
 
CEHJCommented:
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
0
 
HuaMinChenBusiness AnalystAuthor Commented:
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

0
 
HuaMinChenBusiness AnalystAuthor Commented:
While CalCl does exists within the another Java project, that is
https://dl.dropboxusercontent.com/u/40211031/JLib2.zip
0
 
HuaMinChenBusiness AnalystAuthor Commented:
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

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

public class CalCl3 implements CalCl {

}

Open in new window


why?
0
 
CEHJCommented:
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
0
 
HuaMinChenBusiness AnalystAuthor Commented:
What to adjust to the codes above?
0
 
CEHJCommented:
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
0
 
HuaMinChenBusiness AnalystAuthor Commented:
what to adjust to make it work?
0
 
HuaMinChenBusiness AnalystAuthor Commented:
what do you mean by "linked thru the IDE"?
0
 
CEHJCommented:
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.
0
 
HuaMinChenBusiness AnalystAuthor Commented:
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
0
 
CEHJCommented:
That doesn't contain source for interface CalCl
0
 
HuaMinChenBusiness AnalystAuthor Commented:
No, JLib2.jar is under Referenced Libraries of JLib3 project.
0
 
HuaMinChenBusiness AnalystAuthor Commented:
See the attached
t965.png
0
 
CEHJCommented:
You misunderstand - i'm saying it's not in that download - nor is there any jar IN it
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Do you see the attached screenshot?
0
 
CEHJCommented:
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

0
 
HuaMinChenBusiness AnalystAuthor Commented:
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

0
 
CEHJCommented:
As a Java developer you need to set up your tools properly. jar.exe is a part of the JDK and the JDK bin directory should be in your PATH. And of course you should have a JDK installed, though Eclipse only requires a JRE.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 22
  • 12
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now