• Post Reply Bookmark Topic Watch Topic
  • New Topic

Kathy and Bert book: Strange web app structure - Class files inside WEB-INF folder  RSS feed

 
Ali Gordon
Ranch Hand
Posts: 182
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A week ago, I start learning JSP and Servlets from Head first JSP and Servlets from Kathy sierra and bert bates book. I like it a very much !

The book tells me to create the following structure outside of an IDE like eclipse -



But I want to do everything inside an IDE. So, when I created the above package under classes folder, the package ends up in the src folder. Why does this happen ? I want it to be created in the classes
folder as mentioned in my book. I also read a few of pages ahead. Only the classes go into the com.example folder. But, when I copy paste my class into the classes folder, it ends up in Libraries folder of
Eclipse instead. Why ?

Thanks.
Chenqui.

This post have been duplicate at stackoverflow as well. I ask here because this is where authors have hang out -
strange-web-app-structure-class-files-inside-web-inf-folder

 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, that folder is not named "com.example", that's two folders, "\com\example".

Second, and I can't emphasize this enough, do not, I mean, DO NOT start using any IDE at this point. Do everything at the command line the way it's described in the book. Learn to compile and run your programs from the command line or the IDE will just become a crutch and you'll end up not really understanding what you are doing.

I know it's powerfully tempting to dive into an IDE with all the bells and whistles, but do yourself a huge favor and just use a text editor like Notepad++ or EditPad and forget about IDE's for now.
 
Ali Gordon
Ranch Hand
Posts: 182
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. Kevin Robbins wrote:First, that folder is not named "com.example", that's two folders, "\com\example".

Second, and I can't emphasize this enough, do not, I mean, DO NOT start using any IDE at this point. Do everything at the command line the way it's described in the book. Learn to compile and run your programs from the command line or the IDE will just become a crutch and you'll end up not really understanding what you are doing.

I know it's powerfully tempting to dive into an IDE with all the bells and whistles, but do yourself a huge favor and just use a text editor like Notepad++ or EditPad and forget about IDE's for now.


I respectfully disagree. So far, I understood everything. I completed their first "mini project" successfully in Eclipse with little effort. I guess that I will be using an IDE at a job, which is where I see myself after I am done learning.
I still wonder why they would want to have some of the classes inside the WEB_INF folder.
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not some of the classes, all of them. They are supposed to be in the WEB-INF folder because anything in there is not accessible to the outside world, only to the web application itself. It's a security thing.

As for the IDE, if you're using one which is designed to work with web applications then somewhere there will be a process which makes a web application -- probably a WAR file -- from your project. (There might even be a tutorial about how to use it.) And remember, it isn't your source code which is supposed to go into the web application. It's the compiled classes. So don't be concerned about where your source code is.
 
Ali Gordon
Ranch Hand
Posts: 182
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Not some of the classes, all of them. They are supposed to be in the WEB-INF folder because anything in there is not accessible to the outside world, only to the web application itself. It's a security thing.

As for the IDE, if you're using one which is designed to work with web applications then somewhere there will be a process which makes a web application -- probably a WAR file -- from your project. (There might even be a tutorial about how to use it.) And remember, it isn't your source code which is supposed to go into the web application. It's the compiled classes. So don't be concerned about where your source code is.


In that case, it seems that Eclipse is designed incorrectly. Why would the creators force us to put the classes outside web-inf (eg. java resources > src), even when we try to create them inside web-inf in eclipse ? I wonder if developers avoid using Eclipse on the job to create web apps because of such reasons.

In the older projects, my book does not put anything inside the web-inf folder, except the web.xml file.

I am confused now. But, I managed to put all the stuff in src and make it work.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's WEB-INF. Not WEB_INF, not web-inf.

And take the advice you have been give to heart. Dump the IDE until you know how to do everything without it.
 
Paul Clapham
Sheriff
Posts: 22509
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ali Gordon wrote:In that case, it seems that Eclipse is designed incorrectly. Why would the creators force us to put the classes outside web-inf (eg. java resources > src), even when we try to create them inside web-inf in eclipse ? I wonder if developers avoid using Eclipse on the job to create web apps because of such reasons.


Well, put it this way: at work I used Eclipse to create web applications. I just put the code in the src directory and the web-app-creation process created the WEB-INF directory and put the classes in it and put it in the jar and all that sort of thing. It's much more convenient that way, which is sort of the point of using Eclipse. But if you wanted to deal with the WEB-INF directory yourself, I'm sure it would be possible to persuade Eclipse to go along with that as well. But I'm not going to look into how to do that because it's a diversion from your goal, which is to learn about web apps. Which is what several other people have been trying to tell you in this thread: bringing in the IDE diverts you from learning what you're supposed to be learning and forces you to learn the IDE first.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ali Gordon wrote:
J. Kevin Robbins wrote:First, that folder is not named "com.example", that's two folders, "\com\example".

Second, and I can't emphasize this enough, do not, I mean, DO NOT start using any IDE at this point. Do everything at the command line the way it's described in the book. Learn to compile and run your programs from the command line or the IDE will just become a crutch and you'll end up not really understanding what you are doing.

I know it's powerfully tempting to dive into an IDE with all the bells and whistles, but do yourself a huge favor and just use a text editor like Notepad++ or EditPad and forget about IDE's for now.


I respectfully disagree. So far, I understood everything.


Not really. When you create a class that resides in a package called com.example.something.somethingelse it will end up being compiled in the folder \WEB-INF\classes\com\example\something\somethingelse\. Use an archive tool like 7zip to look inside any jar file and you'll see what I mean. In the meantime, do yourself a favor and realize that decades of experience are telling you to dump the IDE at this stage of your learning. Months from now you'll be glad you listened.
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 4097
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ali Gordon wrote:

In that case, it seems that Eclipse is designed incorrectly.

That thought should actually ring a bell in your head that you are not yet ready for IDEs :)
 
Ali Gordon
Ranch Hand
Posts: 182
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Anilprem wrote:
Ali Gordon wrote:

In that case, it seems that Eclipse is designed incorrectly.

That thought should actually ring a bell in your head that you are not yet ready for IDEs :)


Then, how do I become ready for such complicated IDEs ?
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ali Gordon wrote:Then, how do I become ready for such complicated IDEs ?


First, get a decent text editor. I like Notepad++. Other popular ones are EditPad and EMACS<egads>. Whatever you are familiar with is fine. You can even use the Notepad that comes with Windows although it lacks a lot of very basic features. Some hard core geeks even use VIM. A decent editor will provide features like bracket highlighting and auto-indent. Do NOT use a word processor as they insert weird control characters that will prevent your code from compiling.

Second, learn the directory structure of a web app like the book is trying to explain to you so you understand where the class files and jar files will reside, where your jsps will reside, and where the deployment descriptor lives.

Third, learn to deploy apps to Tomcat and how to start and stop Tomcat.

Finally, learn how to use the javac compiler from the command line including using the -cp switch to pick up the supporting libraries and how to create a jar file. Do not set the CLASSPATH environment variable as it will just have you tearing your hair out.

These are the things that the IDE is hiding from you. If you start with an IDE you'll never really have a clear understanding of how these things work. Once you are comfortable with all the above, then and only then are ready to graduate to an IDE and it will come much easier because you will understand what the IDE is doing.

In the end you will be a much better programmer for gaining this knowledge. It's not easy, but it's worth it. Good luck and don't hesitate to come back with more questions.
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 4097
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. Kevin Robbins wrote:

Finally, learn how to use the javac compiler from the command line including using the -cp switch to pick up the supporting libraries and how to create a jar file. Do not set the CLASSPATH environment variable as it will just have you tearing your hair out.

Add -d option to that. I would also move it to the top of the list. This should be the first thing a java programmer should focus on, after may be HelloWorld :)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!