Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Easy import and organisation of 3rd-party open source libraries
Easy import and organisation of 3rd-party open source libraries [message #254844] Tue, 29 April 2008 13:43 Go to next message
Rob Davis is currently offline Rob DavisFriend
Messages: 3
Registered: July 2009
Junior Member
Can Eclipse properly import the hierarchical collection of folders of a
3rd party library (e.g. from apache or sourceforge) so that they will be
correctly recognised and compiled, avoiding the "The declared package does
not match the expected package"?

At the moment I have to manually browse to each folder to get to the
correct level for Eclipse to recognise the files as code and compile them.
For example, considet the 3rd-party library, apache log4j downloaded
source:

In the folder apache-log4j-1.2.15\src

there are several folders containing .java source code
25/08/2007 00:09 <DIR> assembly
25/08/2007 00:09 <DIR> changes
25/08/2007 00:09 <DIR> main
25/08/2007 00:09 <DIR> ntdll
25/08/2007 00:09 <DIR> performance
25/08/2007 00:09 <DIR> site

If I point the standard Eclipse importer at this src folder, expecting it
to recognise the code in these subfolders, it won't do so correctly, it
will import them with the incorrect package name e.g.
main.java.org.apache.log4j.Appender rather than org.apache.log4j.Appender
It incorrectly uses too much of the folder hierarchy when working out what
the package names should be, and as a result I get the "The declared
package does not match the expected package".

The only solution I know of is very manual: When doing an import, I have
to point the import at the java folder level for a 3rd party library. I
have to repeat this for each folder within the 3rd party library source.
Very tedious.

What would be better is if Eclipse could recursively search the 3rd party
library source as a tree - and find the leaves - the .java files
themselves - then within each .java file, find the package statement to
determine what package the .java file belongs to, create this if not
already created and import the file so that it correctly compiles with the
rest of the source in a project.

Also what would be better is if Eclipse could retain the hierarchy of the
3rd-party library, or at the very least, mark the packages as belonging to
a certain 3rd party library. This would make updating such libraries with
newer versions easier and also make the code more portable outside of
Eclipse - because it would be easier to understand what libraries need
building.
Re: Easy import and organisation of 3rd-party open source libraries [message #254895 is a reply to message #254844] Tue, 29 April 2008 17:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: codeslave.ca.ibm.com

log4j 1.2.13 is available as a plugin (osgi bundle) from Orbit. Here's
the latest stable build:

http://download.eclipse.org/tools/orbit/downloads/drops/S200 80427194908/

You might have better success using the plugin than the sources, though
admittedly that's not as new as the version you're using.

In terms of requesting features, try opening an enhancement bug and
asking for comments from the dev teams. Bear in mind that any new
feature work will have to wait until at least mid-summer (if not next
year), as the current release is already winding down.

If you do plugin dev, use

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=PDE

If you do just java dev, use:

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=JDT

Good luck!

Nick

Rob Davis wrote:
> Can Eclipse properly import the hierarchical collection of folders of a
> 3rd party library (e.g. from apache or sourceforge) so that they will be
> correctly recognised and compiled, avoiding the "The declared package
> does not match the expected package"?
>
> At the moment I have to manually browse to each folder to get to the
> correct level for Eclipse to recognise the files as code and compile
> them. For example, considet the 3rd-party library, apache log4j
> downloaded source:
>
> In the folder apache-log4j-1.2.15\src
>
> there are several folders containing .java source code
> 25/08/2007 00:09 <DIR> assembly
> 25/08/2007 00:09 <DIR> changes
> 25/08/2007 00:09 <DIR> main
> 25/08/2007 00:09 <DIR> ntdll
> 25/08/2007 00:09 <DIR> performance
> 25/08/2007 00:09 <DIR> site
>
> If I point the standard Eclipse importer at this src folder, expecting
> it to recognise the code in these subfolders, it won't do so correctly,
> it will import them with the incorrect package name e.g.
> main.java.org.apache.log4j.Appender rather than org.apache.log4j.Appender
> It incorrectly uses too much of the folder hierarchy when working out
> what the package names should be, and as a result I get the "The
> declared package does not match the expected package".
>
> The only solution I know of is very manual: When doing an import, I have
> to point the import at the java folder level for a 3rd party library. I
> have to repeat this for each folder within the 3rd party library source.
> Very tedious.
>
> What would be better is if Eclipse could recursively search the 3rd
> party library source as a tree - and find the leaves - the .java files
> themselves - then within each .java file, find the package statement to
> determine what package the .java file belongs to, create this if not
> already created and import the file so that it correctly compiles with
> the rest of the source in a project.
>
> Also what would be better is if Eclipse could retain the hierarchy of
> the 3rd-party library, or at the very least, mark the packages as
> belonging to a certain 3rd party library. This would make updating such
> libraries with newer versions easier and also make the code more
> portable outside of Eclipse - because it would be easier to understand
> what libraries need building.
>
>
>
Re: Easy import and organisation of 3rd-party open source libraries [message #254916 is a reply to message #254844] Tue, 29 April 2008 20:38 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: wegener.cboenospam.com

"Rob Davis" <tech@robertjdavis.co.uk> wrote in message
news:f8c08e54c70d84ea83addd7afde5ae71$1@www.eclipse.org...
> Can Eclipse properly import the hierarchical collection of folders of a
> 3rd party library (e.g. from apache or sourceforge) so that they will be
> correctly recognised and compiled, avoiding the "The declared package does
> not match the expected package"?
>
> At the moment I have to manually browse to each folder to get to the
> correct level for Eclipse to recognise the files as code and compile them.
> For example, considet the 3rd-party library, apache log4j downloaded
> source:
>
> In the folder apache-log4j-1.2.15\src
>
> there are several folders containing .java source code
> 25/08/2007 00:09 <DIR> assembly
> 25/08/2007 00:09 <DIR> changes
> 25/08/2007 00:09 <DIR> main
> 25/08/2007 00:09 <DIR> ntdll
> 25/08/2007 00:09 <DIR> performance
> 25/08/2007 00:09 <DIR> site
>
> If I point the standard Eclipse importer at this src folder, expecting it
> to recognise the code in these subfolders, it won't do so correctly, it
> will import them with the incorrect package name e.g.
> main.java.org.apache.log4j.Appender rather than org.apache.log4j.Appender
> It incorrectly uses too much of the folder hierarchy when working out what
> the package names should be, and as a result I get the "The declared
> package does not match the expected package".
>
> The only solution I know of is very manual: When doing an import, I have
> to point the import at the java folder level for a 3rd party library. I
> have to repeat this for each folder within the 3rd party library source.
> Very tedious.
>

You don't specify if you are trying to import the source into a larger
project or if you are creating a project specifically for each 3rd party
library. I would suggest separate projects for each 3rd party library.

Eclipse projects support source folders. Source folders are locations in
your project hierarchy where java packages start. The source folders allow
you more flexibility in the way you organize your projects.

My suggestion. Create a project called Log4J. On the Project Creation
dialog, select Create separate folders for source and class files. Use
File->Import->Archive File or File system depending on whether the source is
zipped or not. Select the folders that you want imported into your project.
Use the Package Explorer to navigate to the folder that is the base of the
package structure. Right Click and select Build Path->Use as Source Folder
from the context menu. For example if main has a Java folder that contains
the com.apache.... package roots, you would select main/java as the source
folder.

You do have to declare each source folder individually, but you only have to
perform one import.
> What would be better is if Eclipse could recursively search the 3rd party
> library source as a tree - and find the leaves - the .java files
> themselves - then within each .java file, find the package statement to
> determine what package the .java file belongs to, create this if not
> already created and import the file so that it correctly compiles with the
> rest of the source in a project.
>
> Also what would be better is if Eclipse could retain the hierarchy of the
> 3rd-party library, or at the very least, mark the packages as belonging to
> a certain 3rd party library. This would make updating such libraries with
> newer versions easier and also make the code more portable outside of
> Eclipse - because it would be easier to understand what libraries need
> building.
>
>
>
Re: Easy import and organisation of 3rd-party open source libraries [message #254922 is a reply to message #254916] Tue, 29 April 2008 21:10 Go to previous message
Eclipse UserFriend
Originally posted by: eclipse-news.rizzoweb.com

Dave Wegener wrote:
> "Rob Davis" <tech@robertjdavis.co.uk> wrote in message
> news:f8c08e54c70d84ea83addd7afde5ae71$1@www.eclipse.org...
>> Can Eclipse properly import the hierarchical collection of folders of a
>> 3rd party library (e.g. from apache or sourceforge) so that they will be
>> correctly recognised and compiled, avoiding the "The declared package does
>> not match the expected package"?
>>
>> At the moment I have to manually browse to each folder to get to the
>> correct level for Eclipse to recognise the files as code and compile them.
>> For example, considet the 3rd-party library, apache log4j downloaded
>> source:
>>
>> In the folder apache-log4j-1.2.15\src
>>
>> there are several folders containing .java source code
>> 25/08/2007 00:09 <DIR> assembly
>> 25/08/2007 00:09 <DIR> changes
>> 25/08/2007 00:09 <DIR> main
>> 25/08/2007 00:09 <DIR> ntdll
>> 25/08/2007 00:09 <DIR> performance
>> 25/08/2007 00:09 <DIR> site
>>
>> If I point the standard Eclipse importer at this src folder, expecting it
>> to recognise the code in these subfolders, it won't do so correctly, it
>> will import them with the incorrect package name e.g.
>> main.java.org.apache.log4j.Appender rather than org.apache.log4j.Appender
>> It incorrectly uses too much of the folder hierarchy when working out what
>> the package names should be, and as a result I get the "The declared
>> package does not match the expected package".
>>
>> The only solution I know of is very manual: When doing an import, I have
>> to point the import at the java folder level for a 3rd party library. I
>> have to repeat this for each folder within the 3rd party library source.
>> Very tedious.
>>
>
> You don't specify if you are trying to import the source into a larger
> project or if you are creating a project specifically for each 3rd party
> library. I would suggest separate projects for each 3rd party library.
>
> Eclipse projects support source folders. Source folders are locations in
> your project hierarchy where java packages start. The source folders allow
> you more flexibility in the way you organize your projects.
>
> My suggestion. Create a project called Log4J.... <etc>

In the interest of "teach a man to fish," I'll suggest you open the Help
Contents and find the tutorials under the Java Development User Guide >
Getting Started section. There is a tutorial specifically about project
organization that will help you understand how to set up projects in
Eclipse. The hour or two you spend there will save you many more hours
down the road as you use Eclipse.

Eric
Previous Topic:Error trying to install new features from Mac version
Next Topic:Qt plugins for eclipse
Goto Forum:
  


Current Time: Thu Apr 25 00:43:34 GMT 2024

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

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

Back to the top