This project is a working "stub" application for learners to use to get started.
-
Fork this project on github.com, so you have your own copy. Look for the Fork button in the upper right of the web page.
-
In mid-page, or the lower right, find the "SSH" or "HTTP" button next to a URL, with a "Copy to Clipboard" button next to it.
-
Push "Copy to Clipboard"
-
In a terminal window (mac) or git-bash (windows),
cd
to change directory to the folder where you want your project to appear. -
Then run git clone (paste) (Notice your username in that address - not mine!) :
git clone git@github.com:yourusername/codergirl-project-stub.git
You've already done a fork and clone. You have a copy of the code. But the project name isn't to your liking, and you'd like to separate from my git naming entirely. How do you do it?
- Exit Eclipse. You don't want this open while you fix things.
- Navigate to the folder
codergirl-project-stub
using the folder explorer (windows) or finder (mac). - Delete the .git directory - this will make it "forget" the history of the project and disconnect it from github.
- Rename the codergirl-project-stub directory to your project name.
- Use a text editor (sublime, wordpad, whatever) to modify the
.project
file and thepom.xml
file, to change the name inside there. The names appear multiple times in each file; any place you seecodergirl-project-stub
you should replace that with your project name. Save your changes. - Open the
.settings/org.eclipse.wst.common.component
file and change the name in there. Save your changes. - Get a command prompt (terminal on mac, git-bash on windows) and change directory into your project dir.
- Type:
mvn package
and make sure it succeeds at compiling. If you getmvn: Command not found
then skip this step; you'll check it later in Eclipse instead.
-
Open Eclipse.
-
File menu > Import > From existing workspace > Browse to your project folder and click Open. It should recognize the project and have a checkbox next to it in the white dialog box in the middle of the wizard.
-
Tell it ok, and your project should be listed on the left in Eclipse; after a minute, any compile errors should go away.
-
Spin open the project in the left window of Eclipse (click the triangle). Find the pom.xml file. Click it just one to select it. Then right-click it, go to Run As, Maven Build, and in the "Goal" box type the word
package
and then hit okay. You should see a bunch of stuff scroll past, ending with:[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.855 s [INFO] Finished at: 2016-07-17T16:34:22-05:00 [INFO] Final Memory: 19M/191M [INFO] ------------------------------------------------------------------------
That means all the code is currently compiling properly.
- In terminal or git-bash, change directory into your project dir (you might already be there).
- Type and run:
git init
- Type and run:
git add --all .
- Type and run:
git commit -m "Changed project name"
- Go to your web browser, and go to github.com
- Go to Repositories for your user
- Create New Repository
- Give it a name to match your project name
- DO NOT add a readme or a license file. Click ok.
- Look at the info on the web browser. It will have a section like "…or create a new repository on the command line".
This contains some commands for you to run (but you've already done some of them). Look for the one with
git remote add origin
and copy-paste that into git bash to run it. It's already customized with your project name. - Type and run:
git push -u origin master
- Type and run:
git push --set-upstream origin master
- Refresh the page in your web browser and you should be able to see your code.
- Go back to Eclipse and right-click the project, choose Refresh, and the icons should change to indicate git success.
You're done! You now have an empty project with your preferred name.
You will create servlets in src/main/java/your.package.name/
and jsps in src/main/webapps/*.jsp
(or
optionally in folders within that).
You will start jetty running,
test/main/java/org.codergirl/Start.java (right click, Run as Java Application)
and then go to:
http://localhost:8080/
in a web browser of your choosing. As you modify servlets and jsps, jetty will automatically pick up most changes, if you just reload the web page. If it fails to pick up a change, you can stop and restart jetty to see your change. (Do make sure your code is compiling first; if it's not recompiled, then jetty won't pick up the change.)
As you add new servlet urls, you may need to edit web.xml
to match pretty urls with the
servlet classes that support them.
You may also wish to add Java classes that aren't servlets, but which instead help with
database access, or represent data entities, or whatever. You can create any packages
and classes you want within src/main/java/
and they will be included in the web app.
You may also want to write unit tests; those go in test/main/java/
instead. Anything
in test/
is not available from jetty (except Start.java that runs jetty itself). The
test folder is meant for unit tests that are only needed by the developer, not in a
running web app.
Periodically, as you finish a feature, you will want to save your progress:
git add --all .
git status
git commit -m "Added feature blah blah blah"
git push
src/main/java
- contains the Java code
src/main/resources
- contains properties files when needed
test/main/java
- contains the jetty Start application for local testing, and may contain unit tests.
src/main/webapp/
- contains html content and jsps, plus the WEB-INF/web.xml
file
target/
- contains compiled code (excluded from git)
pom.xml
- maven configuration file that controls what library dependencies are included
This project is modeled from https://github.com/jennybrown8/edu-java-jsp and uses the same project layout and configuration. Read its README for more details.