Does the Struts2 tutorial have misnamed files? HelloWorldAction in HelloWorld.java

StackOverflow https://stackoverflow.com/questions/22115697

  •  18-10-2022
  •  | 
  •  

Pregunta

I am going through the Struts2 tutorial at http://struts.apache.org/release/2.2.x/docs/hello-world-using-struts-2.html

They have a file HelloWorld.java that defines a class HelloWorldAction and the compiler (as run from ant) complains:

[javac] HelloWorld.java:6: class HelloWorldAction is public, should be declared in a file named HelloWorldAction.java

Obviously I can fix this, but is the tutorial really this wrong, or is there some configuration setting that I am missing? I already fixed this once with the tutorial having class MessageStore defined in Message.java and I'm wondering if I'm missing something.

¿Fue útil?

Solución

The caption says

Step 2 - Create The Action Class HelloWorldAction.java

So just rename the file that's probably the typo. There are no such config. Java always wants you to name files accordingly.

Otros consejos

Yes, it is wrong. You need to name it HelloWorldAction.java

enter image description here

public class Foo

must always be named Foo.java no matter what framework you are using or javac will complain.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top