Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Tools / November 2005

Tip: Looking for answers? Try searching our database.

Netbeans / preprocessor / headache

Thread view: 
fj39fj0dle3u - 15 Nov 2005 17:42 GMT
Netbeans / preprocessor / headache
I have a project where I need to use a different "include" file
depending on the version of product I am building.  There are also
various functions within the code that have different argument calls
depending on the version.  Being from the VC++ environment I am very
use to using preprocessor directives, and something like that would
work very well in this case, but I am at a loss for how to set it up
within NetBeans.  A couple things:
1) I am trying to avoid using the C++ preprocessor (trying to keep
everything contained within NetBeans).
2) I see there is a "Mobility" add-on that allows for preprocessor
directives, but I can not figure out how to make this take affect
within an existing project (appears one must create a new project with
Mobility turned on).  I have loaded the latest NetBeans and Mobility
Pack (5.0).
3) I am trying to keep all my code in one source... not a bunch of
different files depending on the version.  Ultimately, I would like to
change one preprocessor directive line in the code (e.g. VERSION) and
compile the source for that version.

I will be the first to admit I am a newbie to Java and NetBeans, but I
have searched for a couple of hours in the help docs and online
searches to no avail.  One would think the NetBeans developers would
allow for the preprocess feature in any project and not JUST Mobility
projects, but I may be wrong.  I am just trying to figure out how to
make it happen for my current project.

Thank you in advance for your assistance.
Rogue - 16 Nov 2005 08:42 GMT
Hi there,

I am not sure what is it that you are trying to achieve. Do you want to
compile selected files alone? or do you want to modify your files based
on some command switches?

Java as such does not have a concept of a pre-processor and all, but
there are tools which can help you do so, but if you use those tools,
then unless they provide an integration with Netbeans, you may still be
at a loss, as some of the directives would not be understood by Java.

There is another option, but i am afraid that it is rather complicated.
You could define your own annotations and annotation processing tool,
and use it for a pre-compilation to get the desired effect.

I may not be the ultimate authority in this subject, but then this is
what comes to my mind immediately.

thanks,
Rogue
Robert Klemme - 16 Nov 2005 10:51 GMT
> Hi there,
>
[quoted text clipped - 12 lines]
> processing tool, and use it for a pre-compilation to get the desired
> effect.

A simple properties file with class names to load might be sufficient.
Then the build process just needs to generate (or copy) the appropriate
properties file.  It can even be bundled with the classes inside a jar and
then a factory class can create instances of the appropriate type.  You'll
likely then have a number of interfaces or (abstract) base classes that
contain different behavior etc.

Kind regards

   robert
fj39fj0dle3u - 18 Nov 2005 19:50 GMT
Hello,
Thank you guys for the responses.
Rogue, I was afraid this was the only easy answer available.  I am sure
there is a good reason why they did not put a preprocessor into the IDE
/ compiler (it would not be difficult), but I can not figure one out.

Robert, I will look more into this, but it may be outside my available
time (and capabilities).  I was really hoping for a single class / file
that generated the appropriate jar files based on a single flag.  There
have been other options presented, but unfortunately they do not appear
to apply to "include" (e.g. non class) statements.

The fact that the Mobility add on to NetBeans (5.0) has the
preprocessor directives makes me wonder why it was not included in non
Mobility type projects.

Thanks again for your replies.
Robert Klemme - 21 Nov 2005 09:23 GMT
> Hello,
> Thank you guys for the responses.
> Rogue, I was afraid this was the only easy answer available.  I am
> sure there is a good reason why they did not put a preprocessor into
> the IDE / compiler (it would not be difficult), but I can not figure
> one out.

Probably because the preprocessor is considered bad for good reasons.  I
think even Stroustrup has regarded keeping the preprocessor in C++ one of
his bigger mistakes.

> Robert, I will look more into this, but it may be outside my available
> time (and capabilities).  I was really hoping for a single class /
> file that generated the appropriate jar files based on a single flag.
> There have been other options presented, but unfortunately they do
> not appear to apply to "include" (e.g. non class) statements.

You can't expect to move to a new language and platform and keep doing
business as you are used to.  You'll have to invest some time to get to
know the new environment.

Regarding your problem: ant (the XML configured Java build tool) might
help also, as it is quite flexible.

> The fact that the Mobility add on to NetBeans (5.0) has the
> preprocessor directives makes me wonder why it was not included in non
> Mobility type projects.

I don't know that feature but probably it's a hack included for platforms
where every single byte (even in class files) counts.

Regards

   robert
Roedy Green - 21 Nov 2005 11:29 GMT
>Probably because the preprocessor is considered bad for good reasons.  I
>think even Stroustrup has regarded keeping the preprocessor in C++ one of
>his bigger mistakes.

One place I would like something like a preprocessor in Java is when
you have two alternate implementations of a class in different
packages, and want to flip back and forth.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.