0

It gives an error "Could not find the main class: filename.java" How do I set the filename to be independent of the class names?

eldarerathis
  • 35,455
  • 10
  • 90
  • 93
nnn
  • 977
  • 2
  • 10
  • 13
  • 8
    Use a language other than Java? – Sergey Kalinichenko Feb 03 '12 at 18:48
  • 2
    Why would you like to do that? If you elaborate more about the concrete problem for which you thought that ignoring the filename would be the solution, we may be able to propose the *right* solutions for that (there may not necessarily be any solution if the problem is just caused by developer's own ignorance or laziness, though). – BalusC Feb 03 '12 at 18:48
  • 1
    Oh, please don't. That would mess with anybody ever looking at your code. – Dave Newton Feb 03 '12 at 18:49
  • 3
    I would help if you elaborated a bit. What is "it"? What command do you execute? – JB Nizet Feb 03 '12 at 18:49
  • I keep version numbers in the filename. – nnn Feb 03 '12 at 18:52
  • Please don't edit new questions into your previous one. If you have additional unrelated questions, ask them separately. – eldarerathis Feb 03 '12 at 19:13

5 Answers5

12

You can't ... In Java the file name has to match the name of the public class in the file

See Why are filenames in Java the same as the class name? for an explanation

Community
  • 1
  • 1
klaustopher
  • 6,702
  • 1
  • 22
  • 25
4

Short Answer: You can't. One class per file is the java way. Accept that or find another language.

Longer Answer: You can but you probably don't want to.

If you have one public class and x number of non-public classes, you can put the all in the same file by nesting the non-public classes inside the public class. For example (in BlowFish.java):

public class BlowFish
{
  class Hooty
  {
  }

  class Sushi
  {
  }
}
DwB
  • 37,124
  • 11
  • 56
  • 82
3

you can't. a java class must be in a .java file with the same name.

yurib
  • 8,043
  • 3
  • 30
  • 55
0

maybe is into the manifesto file where you are defining this class as your main class

elopez
  • 109
  • 9
0

Sure you can. Just put version numbers in your classnames, as well.

Or keep the newest as the classname.java, with older versions getting version numbers.

Or drop the version numbers and use source code control.

CPerkins
  • 8,968
  • 3
  • 34
  • 47