Aftershock
Aftershock

Reputation: 5351

How to include files in java ? Is it possible in Eclipse IDE?

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

Thanks.

Upvotes: 0

Views: 3480

Answers (3)

Torandi
Torandi

Reputation: 1625

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 ;.

Upvotes: 3

Rich Seller
Rich Seller

Reputation: 84038

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.

Upvotes: 0

Bombe
Bombe

Reputation: 83850

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™. :)

Upvotes: 3

Related Questions