Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » How to import JAR file for use in exisiting projects
How to import JAR file for use in exisiting projects [message #270374] Fri, 17 April 2009 06:19 Go to next message
Harry Brundage is currently offline Harry BrundageFriend
Messages: 2
Registered: July 2009
Junior Member
Hi Eclipse Community. I'm brand new to this editor and I come from a web
design background, meaning I'm not very familiar with how the java
classpath works and how Eclipse searches for includes or the equivalent
thereof.

I've spent some time making a pretty simple application using several
different classes in a simple Eclipse project. However, to finish it, I'd
like to use the JGAP framework: http://jgap.sourceforge.net/. Looks pretty
neat. The guide on their site only shows how to use it from the command
line, which I find inefficient for debugging and whatnot. So I would like
to import the relevant files from that framework into my Eclipse project,
or somehow reference them, so I can import them in my Java files.

I think that the main important thing in the framwork is jgap.jar. I tried
importing that by right clicking on my project in the project explorer,
hitting import, and then selecting that JAR file, and many things showed
up in the src folder of the project and elsewhere, however they were all
compiled classfiles (that makes sense). So I tried importing org.jgap in
one of my classes, and the reference couldn't be resolved. I tried
importing the entire JGAP folder into my project by dragging and dropping
and using the import wizard, but I can't get that import to resolve. Any
suggestions?

Also, when I import an example that uses the framework, it's import of
org.jgap resolves fine. As far as I can tell there is no difference in the
location of the files, they are both in my project right? I tried to run
one of them from Eclipse and got a "editor does not contain a main type"
error. There is definitely a main method. Any suggestions?

Thanks very much!
Re: How to import JAR file for use in exisiting projects [message #270379 is a reply to message #270374] Fri, 17 April 2009 16:26 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

"Harry Brundage" <harry.brundage@gmail.com> wrote in message
news:234f171ceb04448d11f5c333026a4fd7$1@www.eclipse.org...
> Hi Eclipse Community. I'm brand new to this editor and I come from a web
> design background, meaning I'm not very familiar with how the java
> classpath works and how Eclipse searches for includes or the equivalent
> thereof.
>
> I've spent some time making a pretty simple application using several
> different classes in a simple Eclipse project. However, to finish it, I'd
> like to use the JGAP framework: http://jgap.sourceforge.net/. Looks pretty
> neat. The guide on their site only shows how to use it from the command
> line, which I find inefficient for debugging and whatnot. So I would like
> to import the relevant files from that framework into my Eclipse project,
> or somehow reference them, so I can import them in my Java files.
>
> I think that the main important thing in the framwork is jgap.jar. I tried
> importing that by right clicking on my project in the project explorer,
> hitting import, and then selecting that JAR file, and many things showed
> up in the src folder of the project and elsewhere, however they were all
> compiled classfiles (that makes sense). So I tried importing org.jgap in
> one of my classes, and the reference couldn't be resolved. I tried
> importing the entire JGAP folder into my project by dragging and dropping
> and using the import wizard, but I can't get that import to resolve. Any
> suggestions?
>
> Also, when I import an example that uses the framework, it's import of
> org.jgap resolves fine. As far as I can tell there is no difference in the
> location of the files, they are both in my project right? I tried to run
> one of them from Eclipse and got a "editor does not contain a main type"
> error. There is definitely a main method. Any suggestions?
>
> Thanks very much!
>
You are on the right track in talking about the classpath. Java uses jar
files like library files for linked executables. You need to get the jar
file on the classpath. One thing to keep in mind with a classpath is that
the build path may be different from the run path. Because of this Eclipse
uses the concept of a Build Path for resolving references on compiles so you
need to add the jar file to the projects build path.

The most straight forward way to do this is to first import the jar file
into your project. Create a new folder in your project called lib. Use the
Import wizard to import the jar file into the lib folder. Import the jar
file intact. Don't expand it into individual class files. Now, you need to
add the jar file to the Build Path. Right click on the project and select
Properties. In the Properties dialog, select Java Build Path. Go to the
Libraries tab and click on Add. Browse to the lib folder and select the jar
file. Click on OK until you have closed all dialogs.

The jar file should now be on your Build Path and you should be able to
resolve reference to classes.
Re: How to import JAR file for use in exisiting projects [message #270381 is a reply to message #270379] Fri, 17 April 2009 17:46 Go to previous messageGo to next message
Harry Brundage is currently offline Harry BrundageFriend
Messages: 2
Registered: July 2009
Junior Member
Worked flawlessly, I was completely unaware that you could set build paths
on a project basis. Neat.

This man is a hero, he should be treated like one. Thanks so very much.
Re: How to import JAR file for use in exisiting projects [message #270387 is a reply to message #270381] Fri, 17 April 2009 19:23 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

On 4/17/2009 1:46 PM, Harry Brundage wrote:
> Worked flawlessly, I was completely unaware that you could set build
> paths on a project basis. Neat.
> This man is a hero, he should be treated like one. Thanks so very much.
>

Dave W. is indeed an excellent helper around here. But I'll point out
that the information you learned from him can also be learned (and a lot
more) from the Eclipse Help documentation. Specifically, the Getting
Started section of the "Java Development User Guide."
Help > "Help Contents" will get you there.

Hope this helps,
Eric
Previous Topic:Building Javadoc for just one directory
Next Topic:"publish after servers".
Goto Forum:
  


Current Time: Thu Sep 19 02:38:27 GMT 2024

Powered by FUDForum. Page generated in 0.08537 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top