views:

89

answers:

4

I have an existing code base that is not packaged at all.

The code base is all minor Java programs designed to extend/enhance the functionality of a third party program. The current process is one jar per class, one class per file, no package.

I'd like to break out the code-base so each jar file is also a package; this eases my jar process in Eclipse.

Are there any risks associated with this I need to be aware of?

+4  A: 

The only risks are around explicit (or more likely, implicit) package definitions being out of date.

For example, all of your Java files, since they're in the same package, will not need to import each other. After the migration, they'll either need to use the fully-qualified name of classes in other packages, or import them.

In a similar vein, anywhere a class name appears (e.g. in Spring config files, perhaps properties files that name classes) it will almost certainly need to be updated to the fully qualified name (e.g. "com.company.package.MyClass" instead of just "MyClass").

It's the latter one that's likely to be the most troublesome; as long as you have a good build process and ensure you're building from scratch, any Java errors should be caught at the compilation stage (unless you're using something weird like Class.forName("MyClass") in your source). The config file problems, though, will manifest at runtime if not sorted out - and then, typically when they're about to be used. If a seldom-used feature has a Spring config referencing one of your classes and you forget to change it, you won't find out about it until it fails.

On the plus side - decent IDEs will have a "rename" or "change package" refactoring, which should be able to find occurences of your class name in text files too.

Andrzej Doyle
A: 

I'm not sure that I fully understand what you are trying to do, but if you are looking to create package(s) for your classes where none exist today then just be aware that some methods may no longer be visible if they are package protected.

cagreen
A: 

Put all the classes into a package (including any properties files, etc) and create a jar from the that package and then you can always include that jar file in your eclipse projects by going do the projects build option and including it as an external jar file then just import the particular class/classes you need into the project and you're done.

As long as you include all the resources that those classes need into the resulting package/jar they will work the same way as they did before but they will be much much easier to use in other projects.

ChadNC
A: 

When you move the class to a different package or rename the package using Eclipse, Eclipse is smart enough to find and change all references as well. All at once. Give it a try.

BalusC