• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

import jar in eclipse //

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dear all,

I want to ask about the import in eclipse ...

The teacher sent a jar file to use it as a component when we do our assignment ...

i try to import the jar and use it in the java project, but it doesn't work ..

when i import the jar file, i do the following: import >> archieve file ...>> it is the right way to import jar file ?

can someone tell me how to import the jar and use it in the java project ?

[NK: Removed font color]
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Please don't write all in red; it is difficult to read.
This would sit better on the IDEs forum. Nitesh will probably move it.

R-click the name of the project on the left pane-> properties->Java Build Path->libraries tab->add external jars->find the jar->OK->OK->OK.
 
nor alain
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the red color ...

mm ok.. i do this step ..
but how can i use the jar on the code ?

for example, when we want to import a libaray in java, we write " import java.awt.* " as example. ..
 
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

obviously you put in a libs folder in the project for your ant support..

Now once that is done right click your project folder in eclipse

The menu item you want to click on is called buld path
and the sub selection you want is libraries

than choose user libraries and set one up for that jar you just imported




nor alain wrote:Sorry for the red color ...

mm ok.. i do this step ..
but how can i use the jar on the code ?

for example, when we want to import a libaray in java, we write " import java.awt.* " as example. ..

 
nor alain
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the import is successful now ..

import SWEB401_HW1.NumericOperation;




but i can't use the methods in the class ( which is in the jar) ..

For example, the class NumericOperation has a method which is add ;
when i tried to create object for the class to call the method, the program give me error because the constructor of the class is not visible ..

what can i do ?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that add method is static which means you should not create of the class i order to call its method.
Try doing this:
ClassName.methodName();

like in your case do:
NumericOperation.add();

Thanks
 
nor alain
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ready do this step, but it give me a syntax error ..

it give me this message ;;

"Syntax error on token "add", Identifier expected after this token";

 
nor alain
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried several things to use the methods which are in the class ( in the jar ) ...

first, i tried to create an instance, but it doesn't work because the constructor is not visible ...
second, i tried to use the class as abstract class and extend it on the new class .. but also it give me the same error ( constructor is not visible ) ..

I don't know what can i do to use the class's methods !!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic