# How can I load packages automatically after reopening Mathematica [duplicate]

Possible Duplicate:

I have made two packages "Package1" and "Package2". Package2 calls Package1. it works fine.But everytime I am reopening Mathematica,I have to run both packages and then load them by Needs. I dont want to load packages again and again.

-

## marked as duplicate by Szabolcs, Yves Klett, Mr.Wizard♦Jul 24 '12 at 9:53

If Package2 relies on Package1, I'd suggest loading it using the second argument of BeginPackage in Package2. This ensures that you only need to load Package2 manually before using it (and not Package1 as well). –  Szabolcs Jul 24 '12 at 9:52
@Szabolcs What you described is a public import which is only recommended in cases when the functionality of the second package (Package1) needs to be available for the users of Package2. In all other cases, a private import through calling Needs["Package1"] in the Private section of Package2 is the better method, for the sake of encapsulation and information hiding. –  Leonid Shifrin Jul 24 '12 at 11:42
@LeonidShifrin It does not in fact need to be in the Private section for the import to be private, as it is the EndPackage of Package2 that removed the Package1 context from the context path. –  Szabolcs Jul 24 '12 at 11:53
@Szabolcs What I described is a standard practice (see R.Maeder's PIM for example). Your suggestion will work technically, but is a rather non-standard way of importing. If the package Package1 you are importing does not have BeginPackage-EndPackage and Begin-End itself (which is a case sometimes), then you will create all its symbols in the public part of Package2 with such an import, and therefore, leak its details to the user. It is not a frequent case, but from the "black box" point of view importing into a Private subsection adds extra protection. –  Leonid Shifrin Jul 24 '12 at 12:11
It was not a suggestion, of course, just a clarification. It's easy to misunderstand your comment and assume that it's the Begin["Private"] that makes the imported package private. –  Szabolcs Jul 24 '12 at 17:37

I would suggest changing the init.m file found in \$UserBaseDirectory/Kernel.

-
I have seen this <mathematica.stackexchange.com/questions/8221/…; but unable to get how it can be useful. I am able to get that .bak file in Mathematica kernel folder. –  Jennifer Jul 24 '12 at 12:02