출처
http://whiteship.tistory.com/1516
http://blog.naver.com/an5asis/60019595888
Job - 이 인터페이스를 상속 받아서 execute 메소드를 구현해야 됩니다. (실행 수행되는 내용)
JobDetail -
Trigger - 작업을 언제 실행할 지 정의합니다.
SimpleTrigger - start time, end time, interval time, repeat times 등을 설정할 수 있습니다.
CronTrigger - Linux의 cron 하고 비슷하게, 특정 시간이 되면 발동하게 해줍니다.
SchedulerFactory
StdSchedulerFactory - 클래스패스에 quartz.properties 파일을 먹고 삽니다.
Scheduler - 스케쥴 팩토리에서 얻어 옵니다. JobDetail과 Trigger를 가지고 스케쥴을 정할 수 있습니다.
package QuartzApp;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class HelloJob implements Job {
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
System.out.println("HelloJob !!!");
}
}
package QuartzApp;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleTrigger;
public class HelloJobTest1Main {
public static void main(String[] args) {
try {
SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
Scheduler sched = schedFact.getScheduler();
sched.start();
JobDetail jobDetail = new JobDetail("HelloJob", HelloJob.class);
SimpleTrigger trigger = new SimpleTrigger("HelloJob");
trigger.setRepeatInterval(1l);
trigger.setRepeatCount(100); // 100번 반복
sched.scheduleJob(jobDetail, trigger);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Programming
- Quartz - SimpleTrigger 사용하기 2010.09.09
- Tomcat 7 - Spring MVC 설치 2010.09.03
- Maven / Jetty 설치 2010.09.02
- Delphi - What is the Send API for accessing menu commands from outside application 2010.08.25
- Delphi Tip - 숫자 여부 확인 2010.05.18
- Delphi Tip - 디렉토리 문자열 분리 2010.04.04
- Delphi - 열거형 타입 ( Delphi enum type ) 2010.03.04
- Delphi Tip 로케일(Locale) 확인 하기 2010.01.20
Quartz - SimpleTrigger 사용하기
Tomcat 7 - Spring MVC 설치
출처 : http://pelican7.egloos.com/2584679
Tomcat 7
Spring Framework 3.0.3.RELEASE
Eclipse 3.6
간단하게 브라우저에서 hello.htm을 호출하면 내부에서 hello.jsp를 호출하는 예제입니다.
1. Project 생성
2. jar 복사
경로 : SpringMVC\WebContent\WEB-INF\lib
commons-logging-1.1.1.jar
org.springframework.asm-3.0.4.RELEASE.jar
org.springframework.beans-3.0.4.RELEASE.jar
org.springframework.context-3.0.4.RELEASE.jar
org.springframework.core-3.0.4.RELEASE.jar
org.springframework.expression-3.0.4.RELEASE.jar
org.springframework.web-3.0.4.RELEASE.jar
org.springframework.web.servlet-3.0.4.RELEASE.jar
3. web.xml 파일 작성
경로 : SpringMVC\WebContent\WEB-INF
---------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
---------------------------------------
4. springapp-servlet.xml 파일 작성
경로 : SpringMVC\WebContent\WEB-INF
---------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- the application context definition for the springapp DispatcherServlet -->
<bean name="/hello.htm" class="springapp.web.HelloController"/>
</beans>
---------------------------------------
5. HelloController.java 작성 / 컴파일
---------------------------------------
package springapp.web;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
public class HelloController implements Controller {
protected final Log logger = LogFactory.getLog(getClass());
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
logger.info("Returning hello view");
return new ModelAndView("hello.jsp");
}
}
---------------------------------------
6. hello.jsp 파일 작성
경로 : SpringMVC\WebContent
---------------------------------------
<html>
<head><title>Hello :: Spring Application</title></head>
<body>
<h1>Hello - Spring Application</h1>
<p>Greetings.</p>
</body>
</html>
---------------------------------------
7. Test
http://localhost:8080/SpringMVC/hello.htm
Maven / Jetty 설치
출처 : http://zzyzzy.textcube.com/14
Maven 설치
1. 다운로드
경로 : http://maven.apache.org/
apache-maven-2.2.1-bin.zip 파일 다운로드
2. OS 환경변수 추가
M2_HOME=C:\source.java\apache-maven-2.2.1
PATH에 추가 ;%M2_HOME%\bin
3. Maven 환경 파일 수정 (settings.xml)
경로 : C:\source.java\apache-maven-2.2.1\conf
- localRepository 내용추가
<localRepository>C:/source.java/apache-maven-2.2.1/repo</localRepository>
4. 설치 확인
C:\Users\bluesanta>mvn -vsersion
Apache Maven 2.2.1 (r801777; 2009-08-07 04:16:01+0900)
Java version: 1.6.0_13
Java home: C:\source.java\jdk1.6.0_13\jre
Default locale: ko_KR, platform encoding: MS949
OS name: "windows vista" version: "6.1" arch: "x86" Family: "windows"
C:\Users\bluesanta>
5. Maven 초기화
C:\Users\bluesanta>mvn install
Jetty 설치
1. 다운로드
경로 : http://dist.codehaus.org/jetty/
jetty-6.1.25.zip
2. 실행배치 파일 만들기 ( start.bat )
경로 : C:\source.java\jetty-6.1.25
start.bat 내용
----------------------------------
@echo off
%JAVA_HOME%\bin\java -jar start.jar etc/jetty.xml
----------------------------------
3. 설치 확인
브라우저에서 http://localhost:8080/ 주소 입력
m2eclipse 설치
1. 이클립스 실행 -> [Help] > [Install New Software...] -> [Add]
- ajdt 설치
http://download.eclipse.org/tools/ajdt/35/dev/update
- m2eclipse 설치
Delphi - What is the Send API for accessing menu commands from outside application
http://swissdelphicenter.com/torry/showcode.php?id=1104
http://www.delphisources.ru/pages/faq/base/get_res_names.html
http://www.swissdelphicenter.ch/torry/showcode.php?id=1710
// Grab sub menu for a Window (by handle), given by (0 based) indices in menu hierarchy
function GetASubmenu(const hW: HWND; const MenuInts: array of Integer): HMENU;
var
hSubMenu: HMENU;
I: Integer;
begin
Result := 0;
if Length(MenuInts) = 0 then
Exit;
hSubMenu := GetMenu(hW);
if not IsMenu(hSubMenu) then
Exit;
for I in MenuInts do
begin
Assert(I < GetMenuItemCount(hSubMenu), format('GetASubmenu: tried %d out of %d items',[I, GetMenuItemCount(hSubMenu)]));
hSubMenu := GetSubMenu(hSubMenu, I);
if not IsMenu(hSubMenu) then
Exit;
end;
Result := hSubMenu;
end;
// Get the caption for MenuItem ID
function GetMenuItemCaption(const hSubMenu: HMENU; const Id: Integer): string;
var
MenuItemInfo: TMenuItemInfo;
begin
MenuItemInfo.cbSize := 44; // Required for Windows 95. not sizeof(AMenuInfo)
MenuItemInfo.fMask := MIIM_STRING;
// to get the menu caption, 1023 first chars should be enough
SetLength(Result, 1023 + 1);
MenuItemInfo.dwTypeData := PChar(Result);
MenuItemInfo.cch := Length(Result)-1;
if not GetMenuItemInfo(hSubMenu, Id, False, MenuItemInfo) then
RaiseLastOSError;
// real caption's size. Should call GetMenuItemInfo again if was too short
SetLength(Result, MenuItemInfo.cch);
{$WARN SYMBOL_PLATFORM OFF}
if DebugHook > 0 then
OutputDebugString(MenuItemInfo.dwTypeData);
end;
procedure Test;
var
hwnd, hSubMenu: Cardinal;
id : Integer;
begin
// hwnd := FindWindow('Afx:00400000:8:00010013:00000000:03F61829', nil); // UltraEdit
// hSubMenu := GetASubmenu(hwnd, [5,0]);
hwnd := FindWindow('Notepad', nil); // get the 1st instance of Notepad...
hSubMenu := GetASubmenu(hwnd, [3]); // 4th submenu Menu aka &View
if hSubMenu > 0 then
begin
id := GetMenuItemID(hSubMenu, 0); // 1st Item in that sub menu (must not be a submenu itself)
if id > -1 then
begin
PostMessage(hwnd, WM_COMMAND, id, 0);
ShowMessage('Done: ' + GetMenuItemCaption(hSubMenu, id));
end
else
RaiseLastOSError;
end
else
RaiseLastOSError;
end;
// 리소스 파일에 존재하는 메뉴 조회
procedure GetMenuInfo2(MainMenu: hMenu; MenuType : TMenuType);
var
id : integer;
i, nItems: Integer;
hwnd, hSubMenu: hMenu;
menuTitle : String;
begin
nItems := GetMenuItemCount(MainMenu);
for i := 0 to nItems - 1 do begin
id := GetMenuItemID(MainMenu, i);
if id > -1 then begin
menuTitle := GetSubMenuItemCaption(MainMenu, id);
if Length(menuTitle)>0 then begin
//ShowMessage(menuTitle);
MenuType.Menus.Add(menuTitle);
end;
end else begin
hSubMenu := GetSubMenu(MainMenu, i );
GetMenuInfo2(hSubMenu, MenuType);
end;
end;
end;
Delphi Tip - 숫자 여부 확인
Tip을 올립니다.
SysUtil.pas의 StrToInt 내부를 보면,
Var 함수를 사용하고 있는데, 3번째 인자의 값이 0이 아니면 Exception을 발생하도록 되어 있습니다.
function StrToInt(const S: string): Integer;
var
E: Integer;
begin
Val(S, Result, E);
if E <> 0 then ConvertErrorFmt(@SInvalidInteger, [S]);
end;
사용예)
아래의 예를 보시면 Result 값을 0으로 초기화 하고
Var의 3번째 인자의 값이 0이면 Result에 값에 담아서 반환하도록 했습니다.
function StrToInt2(const S: string): Integer;
var
intTemp, E : Integer;
begin
Result := 0;
// 숫자 여부 확인
Val(S, intTemp , E);
if E=0 then
Result := intTemp ;
end
Delphi Tip - 디렉토리 문자열 분리
uses
StrUtils;
procedure TForm1.Button1Click(Sender: TObject);
var
tmpDirStr : String;
offset : integer;
function GetFindStr(SubFindStr : String; var offset : integer):string;
var
offsetOld, offset2 : integer;
begin
Result := '';
offset2 := 0;
if SubFindStr[offset] = '/' then
inc(offset2);
offsetOld := offset;
offset := PosEx('/', SubFindStr, offset + offset2);
if offset>0 then begin
Result := MidStr(SubFindStr, offsetOld + offset2, offset-offsetOld-offset2);
end;
end;
begin
tmpDirStr := Edit1.Text;
if (tmpDirStr[Length(tmpDirStr)]<>'/') then
tmpDirStr := tmpDirStr + '/';
offset := 1;
while (offset > 0) do begin
Memo1.Lines.Add(GetFindStr(tmpDirStr, offset));
end;
end;
Delphi - 열거형 타입 ( Delphi enum type )
type
TDatabaseType
= (dbtMSSQL, dbtOracle, dbtCUBRID, dbtSybase, dbtNone);
TDatabaseSet = set of TDatabaseType;
const
StrDatabaseNames : array[TDatabaseType] of String
= ('MSSQL', 'Oracle', 'CUBRID', 'Sybase', 'None');
함수 | 내용 |
Typeinfo | 열거형의 형정보(TypeInfo)에 대한 포인터 반환 |
GetEnumName | 열거형의 각 멤버를 문자열로 반환 |
GetEnumValue | |
Ord | |
Pred | |
Succ | |
Dec | |
Inc | |
Low |
procedure TForm1.Button1Click(Sender: TObject);
var
DatabaseType : TDatabaseType;
begin
// GetEnumValue : String to Enum
DatabaseType := TDatabaseType(GetEnumValue(TypeInfo(TDatabaseType), 'dbtOracle'));
// GetEnumName : Enum to String
ShowMessage(GetEnumName(TypeInfo(TDatabaseType), Ord(DatabaseType))); // dbtOracle
// Ord
ShowMessage(IntToStr(Ord(dbtOracle))); // 1
// Dec
Dec(DatabaseType);
ShowMessage(GetEnumName(TypeInfo(TDatabaseType), Ord(DatabaseType))); // dbtMSSQL
// Inc
Inc(DatabaseType);
ShowMessage(GetEnumName(TypeInfo(TDatabaseType), Ord(DatabaseType))); // dbtOracle
// Low, High / Loop
for DatabaseType := Low(TDatabaseType) to High(TDatabaseType) do
ShowMessage(GetEnumName(TypeInfo(TDatabaseType), Ord(DatabaseType)));
end;
Delphi Set배열
uses TypInfo; procedure TForm1.Button1Click(Sender: TObject); var i : TDBObjectType; begin for i in UniSQLObjectSet[DBVer_CUBRID] do begin Memo1.Lines.Add('i=' + GetEnumName ( TypeInfo ( TDBObjectType ), Ord(i) ) ); end; end;
- end -
Delphi Tip 로케일(Locale) 확인 하기
원본 사이트 : http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_10231553.html
procedure TForm1.Button1Click(Sender: TObject);
function GetLocale(ALcid: Integer): string;
var s: string;
begin
Result := '[Unknown]';
SetLength(s, 128);
if GetLocaleInfo(ALcid, LOCALE_SENGLANGUAGE, PChar(s), 128) > 0 then
begin
Result := StrPas(PChar(s));
if GetLocaleInfo(ALcid, LOCALE_SENGCOUNTRY, PChar(s), 128) > 0 then
begin
Result := Format('%s (%s)', [Result, StrPas(PChar(s))]);
end;
end;
end;
begin
showmessage(GetLocale(GetUserDefaultLangID));
end;