Windows開発環境設定、インストール・サンプル

更新:

Windows 開発環境設定、インストールのサンプル。

J2SDK
・http://java.sun.com/
・Windows版のexeファイルをダウンロードしてインストール。
・j2*****\jdk\binにパスを設定。
・ソースサンプル
	import java.io.*;

	public class sample extends Object {
		public static void main(String[] argv){
			System.out.println("Hello, world");
		}
	}
・コンパイル
	javac sample.java
・実行
	java sample

■tomcat (4.1.30の例。tomcatのバージョンにより方法が多少異なる。)
・http://jakarta.apache.org/tomcat/
・アーカイブをダウンロードして解凍する。
・SET JAVA_HOME=***、とSET TOMCAT_HOME=***を設定。
・起動
	tomcat\bin\startup.bat
・終了
	tomcat\bin\shutdown.bat
・表示
	http://localhost:8080/
・コンテンツ追加
	tomcat\webapps\以下にディレクトリを追加する
	
	web.xmlがないと動かない場合がある。
	tomcat\webapps\test\sample.jsp
	tomcat\webapps\tset\WEB-INF\web.xml
	tomcat\webapps\test\WEB-INF\classes\Sample.class
	
	server.xmlの最終行を編集
	
			</Service>
			
			<Context Path="/test"
				docBase="test"
				debug="0"
				reloadable="true"
				crossContext="true">
			</Context>

		</Server>
	reloadable="true"の場合、tomcatを再起動しなくても、定期的に更新されたサーブレットを読み込みます。
	debugはログレベルで、数字が大きいほどログが詳細に出ます。
	他にもディレクトリを作る場合は、必要な数だけContext Pathを追加します。
・sample.jsp
	<%@ page
		language="java"
		contentType="text/html; charset=Shift_JIS"
	%>

	<HTML><BODY>Hello, world</BODY></HTML>

	tomcatを起動し、http://localhost:8080/test/sample.jspで表示される。
・サーブレット
	サーブレットの場合は、http://localhost:8080/test/servlet/Sampleで表示される。
	test\WEB-INF\classes\com\test\Sample.classに置いた場合、
	http://localhost:8080/test/servlet/com.test.Sampleで表示される。
・web.xml
	<?xml version="1.0" encoding="ISO-8859-1"?>
	<!DOCTYPE web-app
		PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
		"http://java.sun.com/dtd/web-app_2_3.dtd">

	<web-app>
	</web-app>
	
	http://localhost:8080/test/servlet/com.test.Sampleを
	http://localhost:8080/test/servlet/Sampleで表示させるには、以下のように設定する。

	<?xml version="1.0" encoding="ISO-8859-1"?>
	<!DOCTYPE web-app
		PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
		"http://java.sun.com/dtd/web-app_2_3.dtd">

	<web-app>

		<servlet>
			<servlet-name>Sample</servlet-name>
			<servlet-class>com.test.Sample</servlet-class>
		</servlet>

		<servlet-mapping>
			<servlet-name>invoker</servlet-name>
			<url-pattern>/servlet/*</url-pattern>
		</servlet-mapping>

	</web-app>

	tomcat4.1からは、<servlet-mapping>の設定をしないと
	http://localhost:8080/test/servlet/Sampleでサーブレットが表示できない。

■AN HTTP
・http://www.st.rim.or.jp/~nakata/
・Apacheより簡単にWEBサーバができる。
・ダウンロード後、適当なディレクトリに置く。
 httpd.exeをダブルクリックして起動。
 タスクトレイにアイコンが表示され、アイコンを選択するとウィンドウが表示される。
 メニュー→オプション→一般→一般を選択して書く設定を行う。
・設定例
	ドキュメントルート:C:\sitebuild
	デフォルトインデックス:index.html
	設定後、http://127.0.0.1/でC:\sitebuild\index.htmlが表示される。

■Active Perl
・http://www.activestate.com/
・Windows版アーカイブをダウンロードし、適当な場所に解凍。
・Perl\binにパスを設定。
・サンプル
	sample.cgi
		#!/usr/bin/perl

		print "Hello, world";
	DOSプロンプトから実行
		perl sample.cgi
	sample.cgi
		#!/usr/bin/perl

		print "Content-type: text/html\n\n";
		print "<HTML><BODY>Hello, world</BODY></HTML>";
	AN HTTPなどのWEBサーバの設定をして、ブラウザで表示できる。

■MySQL
・http://www.mysql.com/
・Windows版をダウンロードして、インストール。
・mysql\binにパスを設定。
・起動
	mysql\bin\winmysqladmin.exe
・DOSプロンプト
	mysql起動
		mysql
	ヘルプ
		\h
	終了
		\q

■Cygwin
・http://cygwin.com/
・フリーのCコンパイラなど。
・cygwin\binにパスを設定。
・sample.c
	#include <stdio.h>
	main()
	{
		printf("Hello, world\n");
	}
・コンパイル
	CygwinかDOSプロンプトからsample.cのあるディレクトリで
		gcc sample.c -o sample.exe
・実行
	CygwinかDOSプロンプトから
		sample
	で実行。

このエントリーをはてなブックマークに追加