Skip to main content



      Home
Home » Newcomers » Newcomers » Ant build fails to find referenced libraries - buildpath problem?
Ant build fails to find referenced libraries - buildpath problem? [message #549446] Mon, 26 July 2010 12:14 Go to next message
Eclipse UserFriend
Hi all

This is my first post in this forum so forgive me if I have this in the wrong area.

I am trying to build a project with an Ant buildfile and it keeps telling me it can't find the libraries I'm using.

It is just an OSGi tutorial that I'm messing around with trying to learn this thing and it recommended Eclipse.

I have the libraries in the buildpath (the needed class files occur under the library directory thing in the directory tree in the left panel: "Referenced Libraries --> framework.jar --> org.osgi.framework"

One class imports org.osgi.framework.BundleActivator and org.osgi.framework.BundleContext.

Eclipse doesn't seem to have a problem with it and finds them just fine (no errors in the left margin of the editor panel or anything). However the minute I try to use my Ant buildfile to build the project I get a javac error telling me the package "org.osgi.framework" doesn't exist.

The buildfile is in the highest level of the file hierarchy (right below the Java project itself)

Why is it that Eclipse can see the libraries but that Ant buildfile can't?

I'm sure it must be something I'm doing wrong.

[Updated on: Mon, 26 July 2010 12:17] by Moderator

Re: Ant build fails to find referenced libraries - buildpath problem? [message #549453 is a reply to message #549446] Mon, 26 July 2010 12:51 Go to previous messageGo to next message
Eclipse UserFriend
On 7/26/2010 10:14 AM, porchrat wrote:
> Hi all
>
> This is my first post in this forum so forgive me if I have this in the
> wrong area.
>
> I am trying to build a project with an Ant buildfile and it keeps
> telling me it can't find the libraries I'm using.
>
> It is just an OSGi tutorial that I'm messing around with trying to learn
> this thing and it recommended Eclipse.
>
> I have the libraries in the buildpath (they occur under a library thing
> in the directory tree in the left panel under "Referenced Libraries -->
> framework.jar --> org.osgi.framework"
>
> One class imports org.osgi.framework.BundleActivator and
> org.osgi.framework.BundleContext.
>
> Eclipse doesn't seem to have a problem with it and finds them just fine
> (no errors in the left margin of the editor panel or anything). However
> the minute I try to use my Ant buildfile to build the project I get a
> javac error telling me the package "org.osgi.framework" doesn't exist.
>
> The buildfile is in the highest level of the file hierarchy (right below
> the Java project itself)
>
> Why is it that Eclipse can see the libraries but that Ant buildfile can't?
>
> I'm sure it must be something I'm doing wrong.

Note that ant is enabled by Eclipse in that it provides a way for you to
write, maintain and use ant scripts. However, Eclipse does pretty much
nothing else for you that way.

When you write an ant script and run it, from the script's point of
view, Eclipse doesn't exist. So, if you're assuming Eclipse is telling
any anything about where source code and libraries are, you're going to
be disappointed.

If you are used to writing ant scripts devoid of Eclipse, this won't be
a problem as it's business as usual. If, as I did, you start writing ant
from an Eclipse point of view, the learning curve is steeper and rockier.
Re: Ant build fails to find referenced libraries - buildpath problem? [message #549456 is a reply to message #549446] Mon, 26 July 2010 12:52 Go to previous messageGo to next message
Eclipse UserFriend
On 7/26/2010 10:14 AM, porchrat wrote:
> Hi all
>
> This is my first post in this forum so forgive me if I have this in the
> wrong area.
>
> I am trying to build a project with an Ant buildfile and it keeps
> telling me it can't find the libraries I'm using.
>
> It is just an OSGi tutorial that I'm messing around with trying to learn
> this thing and it recommended Eclipse.
>
> I have the libraries in the buildpath (they occur under a library thing
> in the directory tree in the left panel under "Referenced Libraries -->
> framework.jar --> org.osgi.framework"
>
> One class imports org.osgi.framework.BundleActivator and
> org.osgi.framework.BundleContext.
>
> Eclipse doesn't seem to have a problem with it and finds them just fine
> (no errors in the left margin of the editor panel or anything). However
> the minute I try to use my Ant buildfile to build the project I get a
> javac error telling me the package "org.osgi.framework" doesn't exist.
>
> The buildfile is in the highest level of the file hierarchy (right below
> the Java project itself)
>
> Why is it that Eclipse can see the libraries but that Ant buildfile can't?
>
> I'm sure it must be something I'm doing wrong.

Note that ant is enabled by Eclipse in that it provides a way for you to
write, maintain and use ant scripts. However, Eclipse does pretty much
nothing else for you that way.

When you write an ant script and run it, from the script's point of
view, Eclipse doesn't exist. So, if you're assuming Eclipse is telling
ant anything about where source code and libraries are, you're going to
be disappointed.

If you are used to writing ant scripts devoid of Eclipse, this won't be
a problem as it's business as usual. If, as I did, you start writing ant
from an Eclipse point of view, the learning curve is steeper and rockier.
Re: Ant build fails to find referenced libraries - buildpath problem? [message #549597 is a reply to message #549453] Tue, 27 July 2010 06:35 Go to previous messageGo to next message
Eclipse UserFriend
You may be right. I am pretty new to Ant scripting.

I find it really helpful though and I have been really keen to learn it.

I think you have found my answer.

My referenced libraries are not in the same directory as the Ant script (they're sitting in another area of my home directory).

I will try and move those libraries into the same directory and see what happens.

Thanks for the advice Smile
Re: Ant build fails to find referenced libraries - buildpath problem? [message #549666 is a reply to message #549446] Tue, 27 July 2010 09:48 Go to previous messageGo to next message
Eclipse UserFriend
On 7/26/10 12:14 PM, porchrat wrote:
> Hi all
>
> This is my first post in this forum so forgive me if I have this in the
> wrong area.
>
> I am trying to build a project with an Ant buildfile and it keeps
> telling me it can't find the libraries I'm using.
>
> It is just an OSGi tutorial that I'm messing around with trying to learn
> this thing and it recommended Eclipse.
>
> I have the libraries in the buildpath (they occur under a library thing
> in the directory tree in the left panel under "Referenced Libraries -->
> framework.jar --> org.osgi.framework"
>
> One class imports org.osgi.framework.BundleActivator and
> org.osgi.framework.BundleContext.
>
> Eclipse doesn't seem to have a problem with it and finds them just fine
> (no errors in the left margin of the editor panel or anything). However
> the minute I try to use my Ant buildfile to build the project I get a
> javac error telling me the package "org.osgi.framework" doesn't exist.
>
> The buildfile is in the highest level of the file hierarchy (right below
> the Java project itself)
>
> Why is it that Eclipse can see the libraries but that Ant buildfile can't?
>
> I'm sure it must be something I'm doing wrong.

Eclipse doesn't automatically inject it's build path into any Ant build
script; you have to write the Ant script to know where to find the OSGi
JARs.

There is an option to export an Ant build file from an Eclipse project;
have you tried that?

Eric
Re: Ant build fails to find referenced libraries - buildpath problem? [message #549682 is a reply to message #549666] Tue, 27 July 2010 10:31 Go to previous messageGo to next message
Eclipse UserFriend
Eric Rizzo wrote on Tue, 27 July 2010 09:48

Eclipse doesn't automatically inject it's build path into any Ant build
script; you have to write the Ant script to know where to find the OSGi
JARs.

There is an option to export an Ant build file from an Eclipse project;
have you tried that?

Eric


That makes sense and I think that you are right.

I am totally new to Ant scripting (first time I have ever written any of it, though I am relatively familiar with XML itself in particular XMI).

I suppose I will need to look up an Ant tutorial to get me started on how to tell the buildfile where my libraries are as you can see below the build.xml file doesn't contain any reference to the location of that external JAR:

<?xml version="1.0"?>

<project name="simplebundle" default="all">
	<target name="all" depends="init, compile, jar"/>
	
	<target name="init">
		<mkdir dir="./classes"/>
		<mkdir dir="./build"/>
	</target>
	
	<target name="compile">
		<javac destdir="./classes" debug="on" srcdir="./src">
		</javac>
	</target>
	
	<target name="jar">
		<jar basedir="./classes" jarfile="./build/simplebundle.jar" compress="true" includes="**/*" manifest="./META-INF/manifest.mf"/>
	</target>
	
	<target name="clean">
		<delete dir="./classes"/>
		<delete dir="./build"/>
	</target>
		
</project>


This is pretty much how the tutorial told me to create this Ant script and I had assumed it would just work. I had wondered about it not mentioning the libraries but just assumed that Eclipse would hand it's buildpath information over to the buildfile if and when required. I realise now that would be stupid because it would mean that Ant script would be totally reliant on Eclipse and that would be pointless.

Either that or that the manifest would be used by javac when called by the buildfile to find the library.

One good thing will come from this. I find I learn things a lot better when something goes wrong.
Re: Ant build fails to find referenced libraries - buildpath problem? [message #549699 is a reply to message #549682] Tue, 27 July 2010 11:18 Go to previous message
Eclipse UserFriend
OK as an update I went out and found an Ant tutorial and it looks like I have figured out what was wrong with my script posted in the above post (so awesome when you figure it out for yourself) Smile

I didn't define a classpath so the bloody thing had no idea where to search for the libraries needed by javac to compile.

This is exactly what both responses to this thread told me and I'm so thankful for the insight. Thanks dudes!

Anyway here is the now slightly modified build.xml:

<?xml version="1.0"?>

<project name="simplebundle" default="all">
	
<!-- defining properties for ease of use (edit added by me) -->
	<property name="project.libs" value="/home/porchrat/software/OSGi/knopflerfish/knopflerfish_osgi_sdk_3.0.0/osgi" />
	
<!-- pre-defining classpath for ease of use later (edit added by me) -->
	<path id="lib.path">
		<fileset dir="${project.libs}">
			<include name="**/*.jar" />
		</fileset>
	</path>
	
	<target name="all" depends="init, compile, jar" />
	
	<target name="init">
		<mkdir dir="./classes" />
		<mkdir dir="./build" />
	</target>
	
	<target name="compile">
		<javac destdir="./classes" debug="on" srcdir="./src">
<!-- adding classpath (edit added by me) -->
			<classpath>
				<path refid="lib.path" />
			</classpath>
		</javac>
	</target>
	
	<target name="jar">
		<jar basedir="./classes" jarfile="./build/simplebundle.jar" compress="true" includes="**/*" manifest="./META-INF/manifest.mf" />
	</target>
	
	<target name="clean">
		<delete dir="./classes" />
		<delete dir="./build" />
	</target>
		
</project>


If any of you spot any errors or a breaking of convention in that code please let me know. I am not exactly an Ant guru and any advice from those more experienced than myself is greatly appreciated.
Previous Topic:Display multiple consoles or log files
Next Topic:Sharing Eclipse between Windows and Ubuntu
Goto Forum:
  


Current Time: Wed Sep 17 18:20:24 EDT 2025

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

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

Back to the top