Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- case "$1" in
- */)
- directory=$1
- ;;
- *)
- directory="${1}/"
- ;;
- esac
- name=$2
- classpath=$3
- project_root="$directory$name"
- config_folder="$project_root/WEB-INF/"
- source_folder="$project_root/src/"
- class_folder="${config_folder}classes/"
- echo $directory
- echo $name
- echo $project_root
- echo $config_folder
- echo $source_folder
- echo $class_folder
- mkdir -p $project_root
- mkdir -p $config_folder
- mkdir -p $class_folder
- # Creates a basic web.xml file that describes a hello-world servlet
- echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > "$config_folder/web.xml"
- echo "<web-app version=\"2.4\" xmlns=\"http://java.sun.com/xml/ns/j2ee\" " >> "$config_folder/web.xml"
- echo " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " >> "$config_folder/web.xml"
- echo " xsi:schemaLocation=\"http://java.sun.com/xml/ns/j2ee " >> "$config_folder/web.xml"
- echo " http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd\">" >> "$config_folder/web.xml"
- echo "" >> "$config_folder/web.xml"
- echo " <servlet>" >> "$config_folder/web.xml"
- echo " <servlet-name>Hello-World</servlet-name>" >> "$config_folder/web.xml"
- echo " <servlet-class>HelloWorld</servlet-class>" >> "$config_folder/web.xml"
- echo " </servlet>" >> "$config_folder/web.xml"
- echo "" >> "$config_folder/web.xml"
- echo " <servlet-mapping>" >> "$config_folder/web.xml"
- echo " <servlet-name>Hello-World</servlet-name>" >> "$config_folder/web.xml"
- echo " <url-pattern>/hello</url-pattern>" >> "$config_folder/web.xml"
- echo " </servlet-mapping>" >> "$config_folder/web.xml"
- echo "</web-app>" >> "$config_folder/web.xml"
- # Creates the directory the Java® source file lives in.
- mkdir -p $source_folder
- # Creates the source-file
- echo "" > "${source_folder}HelloWorld.java"
- echo "" >> "${source_folder}HelloWorld.java"
- echo "import java.io.IOException;" >> "${source_folder}HelloWorld.java"
- echo "import java.io.PrintWriter;" >> "${source_folder}HelloWorld.java"
- echo "import javax.servlet.http.HttpServlet;" >> "${source_folder}HelloWorld.java"
- echo "import javax.servlet.http.HttpServletRequest;" >> "${source_folder}HelloWorld.java"
- echo "import javax.servlet.http.HttpServletResponse;" >> "${source_folder}HelloWorld.java"
- echo " /**" >> "${source_folder}HelloWorld.java"
- echo " * A simple hello-world servlet, responding to HTTP GET" >> "${source_folder}HelloWorld.java"
- echo " */" >> "${source_folder}HelloWorld.java"
- echo "public class HelloWorld extends HttpServlet {" >> "${source_folder}HelloWorld.java"
- echo " @Override" >> "${source_folder}HelloWorld.java"
- echo " public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{" >> "${source_folder}HelloWorld.java"
- echo " PrintWriter out = response.getWriter();" >> "${source_folder}HelloWorld.java"
- echo " out.println(\"<!DOCTYPE html>\");" >> "${source_folder}HelloWorld.java"
- echo " out.println(\"<html lang=\\\"en\\\">\");" >> "${source_folder}HelloWorld.java"
- echo " out.println(\" <head>\");" >> "${source_folder}HelloWorld.java"
- echo " out.println(\" <meta charset=\\\"utf-8\\\">\");" >> "${source_folder}HelloWorld.java"
- echo " out.println(\" <title>Hello World</title>\");" >> "${source_folder}HelloWorld.java"
- echo " out.println(\" </head>\");" >> "${source_folder}HelloWorld.java"
- echo " out.println(\" <body>\");" >> "${source_folder}HelloWorld.java"
- echo " out.println(\" <h1>Hello World</h1>\");" >> "${source_folder}HelloWorld.java"
- echo " out.println(\" </body>\");" >> "${source_folder}HelloWorld.java"
- echo " out.println(\"</html>\");" >> "${source_folder}HelloWorld.java"
- echo " }" >> "${source_folder}HelloWorld.java"
- echo "}" >> "${source_folder}HelloWorld.java"
- # Moves us to the project root. This is not really necessary, but gives us a convenient place to put error logs.
- # No, I don't log errors. Why do you ask? :p
- pushd $project_root
- # Compiles the files. This will give an error if the classpath is wrong.
- javac src/HelloWorld.java -classpath ${classpath} -d ${class_folder}
- # Goes back to where we came from.
- popd
- # TODO:
- # Log errors.
- # Make an ant-build script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement