Search code examples
javaeclipseclassbuildencapsulation

Can I build multiple classes into one .class file in Java?


I am opening a .class file using COMSOL multi-physics, and it works fine for one .class file, but I can't open several .class files at a time. My problem is that I want to be able to build more complicated objects inside the class that I open but, when I import these classes and build the project, I end up with multiple .class files. When I open the main .class file in COMSOL, a "error running java class", which I assume is because I've only opened one class.

I am not very familiar with programming in Java, but I started trying to put my classes inside one file, but when I build there still 3 output .class files. Also, in case it matters, I am running on a windows 7 machine and using Eclipse... I would greatly appreciate any suggestions.


Solution

  • You need a .class for each class. The usual solution is to combine them into a .jar. The .jar file can be downloaded and moved around as a single file, regardless of how many classes it represents. You can mark it to identify the main class, so it can be run much as a single class file.

    Creating a .jar is one of the options in Eclipse for File-Export