views:

619

answers:

4

Hi,

Is it possible to include files in java source files somehow?

Thanks.

+3  A: 

You could of course use a preprocessor to create your source files from templates but that in general is not advisable and will create more problems than it solves.

Apart from that: no, Eclipse does not offer a way to do that. Including files in the source code is not The Java Way™. :)

Bombe
A: 

You could use an aspect to weave in intertype declarations and/or use pointcuts to weave advice to method declarations. This is not equivalent to #include, but the effects can be similar.

See this AspectJ tutorial for a starting point and the quick reference sheet for more details.

Rich Seller
It looks interesting.
Aftershock
+3  A: 

Not really, java doesn't work that way. If you need code from another class, you use

import package_name.classname

which will search for the class in your class path (that includes the currect directory). If you have jar-files that contains the classes you will have to add them to your class path with an argument to the java inteprentor

java -cp jarfile.jar:. your-class-file

In unix : is used to separate paths, in windows i think it is ;.

Torandi
A: 
  • List item
  • emphasized text

    emphasized text

Blockquote

enter code here
  • List item
  • List item



typed wrongly ..sorry