Solved

Way to create the library

Posted on 2015-02-03
41
78 Views
Last Modified: 2015-02-12
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
Comment
Question by:HuaMinChen
  • 22
  • 12
  • 7
41 Comments
 
LVL 8

Expert Comment

by:Naitik Gamit
ID: 40588041
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40588054
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40588076
I create one project
https://dl.dropboxusercontent.com/u/40211031/JLib.zip

using Eclipse. How to find out jar file from it?
0
 
LVL 8

Expert Comment

by:Naitik Gamit
ID: 40588087
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40588112
How to get the Jar file to the recent project? Thanks
0
 
LVL 8

Expert Comment

by:Naitik Gamit
ID: 40588119
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40588124
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
 
LVL 8

Expert Comment

by:Naitik Gamit
ID: 40588134
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 40588137
C:\Eclipse\JLib>java -jar JLib.jar

Open in new window


means it's a stand-alone app. Is it?
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40588144
Thanks all.

CEHI,
yes
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40588155
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40588163
Thanks. can I have the details to create manifest, to the project, using Eclipse?
0
 
LVL 8

Expert Comment

by:Naitik Gamit
ID: 40588200
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40588283
I also get it from Help of Eclipse. Can you show me in details to do this? thanks
0
 
LVL 8

Expert Comment

by:Naitik Gamit
ID: 40588302
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40588311
Can I work with manifest, without the plug-in?
0
 
LVL 8

Expert Comment

by:Naitik Gamit
ID: 40588322
in Eclipse you can but.............but it is not runnable
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40588486
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40590241
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40590244
While CalCl does exists within the another Java project, that is
https://dl.dropboxusercontent.com/u/40211031/JLib2.zip
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 10

Author Comment

by:HuaMinChen
ID: 40590272
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 40590649
I'm not really much of an Eclipse user, but does it run properly in the IDE?
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40590654
I'm to compile it and then have got the issue. thanks
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40590655
Can you try to open it, if available? thanks.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40590714
There's no main method in your last source - so it will never 'run' as such, but it will compile
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40590719
Sorry, I am not able to compile these
package CalCl3;
import JLib2.Calcl;

public class CalCl3 implements CalCl {

}

Open in new window


why?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40590767
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40591266
What to adjust to the codes above?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40591357
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40592512
what to adjust to make it work?
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40592845
what do you mean by "linked thru the IDE"?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40593166
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40593169
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 40593237
That doesn't contain source for interface CalCl
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40593269
No, JLib2.jar is under Referenced Libraries of JLib3 project.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40593273
See the attached
t965.png
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40593275
You misunderstand - i'm saying it's not in that download - nor is there any jar IN it
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40593281
Do you see the attached screenshot?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40593295
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 40595018
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
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 40595501
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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now