Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » [JAVA] Importing Jars(Getting java.lang.NoClassDefFoundError)
[JAVA] Importing Jars [message #836573] Wed, 04 April 2012 12:44 Go to next message
Eugenio Bargiacchi is currently offline Eugenio Bargiacchi
Messages: 3
Registered: April 2012
Junior Member
Good morning everybody, I'm having a little bit of trouble using java libraries in Eclipse.

More specifically, every time I include a jar in my project, I can import it just fine in the code, and everything will compile just fine, but as soon as I test what I did I get a java.lang.NoClassDefFoundError.

As I understand, this exception is caused by some classpath issues. However, it appears to me ( but as I am new I'm surely making some mistake ) that everything is correct.

To add a .jar to a project I right-click on my project, Build Path->Configure Build Path..->Libraries Tab, and then I click on Add External Jars.

This adds the jars into the Libraries folder ( is it a folder? it has a different icon, like books ).

Are there some steps I am missing to make the whole thing work?

Thanks in advance.
Re: [JAVA] Importing Jars [message #836582 is a reply to message #836573] Wed, 04 April 2012 12:55 Go to previous messageGo to next message
David Wegener is currently offline David Wegener
Messages: 1297
Registered: July 2009
Senior Member
That will allow you to build against the jar. You need to make sure that your launch configuration also includes the jar on its runtime classpath. Open up the launch config for the program and look at the Classpath tab. The default entry should pick up your build path. If you've customized the runtime Classpath, you will need to add the jars you add manually.
Re: [JAVA] Importing Jars [message #836606 is a reply to message #836582] Wed, 04 April 2012 13:41 Go to previous messageGo to next message
Eugenio Bargiacchi is currently offline Eugenio Bargiacchi
Messages: 3
Registered: April 2012
Junior Member
I understand, thanks! I've finally managed to make it work.

Another thing though. I've noticed that when I go to Run Configurations, there's only one configuration ( the one that my server is using ). Is there a way to make more and assign them to each different project?

I can't seem to find an option to assign a configuration to a specific project.
Re: [JAVA] Importing Jars [message #836858 is a reply to message #836606] Wed, 04 April 2012 21:12 Go to previous messageGo to next message
David Wegener is currently offline David Wegener
Messages: 1297
Registered: July 2009
Senior Member
On 04/04/2012 12:41 PM, Eugenio Bargiacchi wrote:
> I understand, thanks! I've finally managed to make it work.
>
> Another thing though. I've noticed that when I go to Run Configurations,
> there's only one configuration ( the one that my server is using ). Is
> there a way to make more and assign them to each different project?
>
> I can't seem to find an option to assign a configuration to a specific
> project.
You can create as many launch configs as you want. They just have to
have different names. You can create a new one by clicking the new icon
or selecting an existing config and using the duplicate existing icon on
the upper left portion on the Run Configurations dialog.

If you want to save the launch in a project, use the Common tab to pick
a project location to save the launch in.
Re: [JAVA] Importing Jars [message #837314 is a reply to message #836573] Thu, 05 April 2012 10:02 Go to previous messageGo to next message
Russell Bateman is currently offline Russell Bateman
Messages: 3052
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 4/4/2012 10:44 AM, Eugenio Bargiacchi wrote:
> Good morning everybody, I'm having a little bit of trouble using java
> libraries in Eclipse.
>
> More specifically, every time I include a jar in my project, I can
> import it just fine in the code, and everything will compile just fine,
> but as soon as I test what I did I get a java.lang.NoClassDefFoundError.
>
> As I understand, this exception is caused by some classpath issues.
> However, it appears to me ( but as I am new I'm surely making some
> mistake ) that everything is correct.
>
> To add a .jar to a project I right-click on my project, Build
> Path->Configure Build Path..->Libraries Tab, and then I click on Add
> External Jars.
>
> This adds the jars into the Libraries folder ( is it a folder? it has a
> different icon, like books ).
>
> Are there some steps I am missing to make the whole thing work?
>
> Thanks in advance.

Is this a Dynamic Web Project? In addition to adding the JAR via Build
Path, you'll need to add it to the Deployment Assembly. While you're in
Build Path, look over at the left column just above Build Path.
Re: [JAVA] Importing Jars [message #837971 is a reply to message #837314] Fri, 06 April 2012 07:19 Go to previous messageGo to next message
Eugenio Bargiacchi is currently offline Eugenio Bargiacchi
Messages: 3
Registered: April 2012
Junior Member
@David Wegener
Thanks, I've managed to create a new configuration but I can't seem to find a way to assign it to a specific project. Instead it appears directly in my Run menu.

What I'd like ( if it is possible ) is to assign a configuration to a project so that when I run it, the server automatically gets configured as the configuration assigned to the project. Is this possible or do I have to create different servers?

@Russel Bateman
It is a Vaadin Project. Adding the jars to the Build Path of the project ( via Configure Build Path -> Libraries -> Add External JARs ) and to the configuration of the server ( via Run Configurations.. -> Classpath -> User entries ) seems to work now. What is the Deployment Assembly? I've seen the menu and it shows me two entries ( /src | WEB-INF/classes and /WebContent | / ), but I'm not sure I know what they mean.

Sorry for being a newbie =)
Re: [JAVA] Importing Jars [message #838042 is a reply to message #837971] Fri, 06 April 2012 09:29 Go to previous message
Russell Bateman is currently offline Russell Bateman
Messages: 3052
Registered: July 2009
Location: Provo, Utah, USA
Senior Member

On 4/6/2012 5:19 AM, Eugenio Bargiacchi wrote:
> @David Wegener
> Thanks, I've managed to create a new configuration but I can't seem to
> find a way to assign it to a specific project. Instead it appears
> directly in my Run menu.
>
> What I'd like ( if it is possible ) is to assign a configuration to a
> project so that when I run it, the server automatically gets configured
> as the configuration assigned to the project. Is this possible or do I
> have to create different servers?
>
> @Russel Bateman
> It is a Vaadin Project. Adding the jars to the Build Path of the project
> ( via Configure Build Path -> Libraries -> Add External JARs ) and to
> the configuration of the server ( via Run Configurations.. -> Classpath
> -> User entries ) seems to work now. What is the Deployment Assembly?
> I've seen the menu and it shows me two entries ( /src | WEB-INF/classes
> and /WebContent | / ), but I'm not sure I know what they mean.
>
> Sorry for being a newbie =)

I can't say. I know nothing of Vaadin (a web application framework). So,
if it works, then don't sweat it. What you're doing is a web
application; normally you'd ask questions in the Eclipse web tools
forum. I don't know if you'll fare better there, but you might try.
Otherwise, you really should find help in the Vaadin community. In fact,
that's probably the place to start.
Previous Topic:Run As Configurations -> Java Application -> Display my_project_name (2)
Next Topic:about j2ee project.
Goto Forum:
  


Current Time: Wed Apr 16 00:41:01 EDT 2014

Powered by FUDForum. Page generated in 0.02397 seconds