2012-09-28

How to fix log4j.dtd XML problem in eclipse

Problem
The file cannot be validated as the XML definition \path\to\workspace\java.shop\src\test\resources\log4j.dtd (The system cannot find the file specified)" that is specified as describing the syntax of the file cannot be located.

Reason
Eclipse cannot find the log4j.dtd for validation.

Solution
Open Preference (Window > Preferences) and Select XML>XML Catalog
Click [Add...] and insert the following
Location: jar:file:C:\USR\eclipse\plugins\org.apache.log4j_1.2.15.v201012070815.jar!/org/apache/log4j/xml/log4j.dtd
Key Type: Public ID
Key: -//APACHE//DTD LOG4J 1.2//EN


2012-09-23

Share Windows desktop with Linux

  1. Download and Install VirtualBox - https://www.virtualbox.org/wiki/Downloads
  2. Install Linux in VirtualBox and GuestEdition on Linux
  3. Go to Seamless mode View > Switch to Seamless mode
  4. Combined desktop - Windows 8 and Linux

2012-09-22

How to setup IssueTracker GIT PHP JSP for PHPEclipse


Download
xampp-win32-1.8.0-VC9-installer.exe :: http://www.apachefriends.org/en/xampp-windows.html
ruby-1.9.3-p125-i386-mingw32.7z :: http://rubyinstaller.org/downloads/ <== Do not use p194 because of bug
DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe :: http://rubyinstaller.org/downloads/
mysql-connector-c-noinstall-6.0.2-win32.zip :: http://dev.mysql.com/downloads/connector/c/
redmine-2.1.0.zip :: http://rubyforge.org/frs/?group_id=1850
PortableGit-1.7.11-preview20120710.7z :: http://code.google.com/p/msysgit/

# Do not download the belows if you have a 32bit Windows box
apache-tomcat-7.0.30-windows-x64.zip :: http://tomcat.apache.org/
mysql-5.5.27-winx64.zip :: http://www.mysql.com/downloads/mysql/

Install XAMPP into C:\usr
Extract others into C:\usr
C:\usr\apache-tomcat-7.0.30\
C:\usr\mysql-5.5.27-winx64\
C:\usr\ruby-1.9.3-p194-i386-mingw32
C:\usr\DevKit-tdm-32-4.5.2-20111229-1559-sfx
C:\usr\mysql-connector-c-noinstall-6.0.2-win32
C:\usr\redmine-2.1.0
C:\usr\Git-1.7.11
Make symbolic link as Administrator
CMD> cd C:\usr
CMD> mklink /D ruby C:\usr\ruby-1.9.3-p194-i386-mingw32
CMD> mklink /D devkit C:\usr\DevKit-tdm-32-4.5.2-20111229-1559-sfx
CMD> mklink /D mysql-connector c:\usr\mysql-connector-c-noinstall-6.0.2-win32
CMD> mklink /D redmine C:\usr\redmine-2.1.0
CMD> mklink /D git C:\usr\Git-1.7.11
CMD> cd C:\usr\ruby\bin
CMD> mklink libmysql.dll C:\usr\mysql-connector\lib\libmysql.dll
## Skip if you have a 32bit Windows box
CMD> cd C:\usr
CMD> ren(or remove) tomcat tomcat7-32bit
CMD> ren(or remove) mysql mysql-5.5.25-winx86
CMD> mklink /D tomcat apache-tomcat-7.0.30
CMD> mklink /D mysql mysql-5.5.27-winx64
CMD> copy mysql-5.5.25-winx86\mysql_installservice.bat mysql
CMD> copy mysql-5.5.25-winx86\mysql_uninstallservice.bat mysql
CMD> copy mysql-5.5.25-winx86\mysql_resetroot.bat mysql
## Move mysql data directory to D drive : you can skip this
CMD> cd C:\usr\mysql-5.5.25-winx86
CMD> mkdir "D:\MySQL Data"
CMD> xcopy /S data "D:\MySQL Data"
CMD> cd C:\usr\mysql   <== make sure 64bit mysql(mysql-5.5.25-winx86)
CMD> ren(or remove) data data.org
CMD> mklink /D data "D:\MySQL Data"
Setup DevKit
Add C:\usr\ruby\bin into PATH
CMD> cd C:\usr\devkit
CMD> ruby dk.rb init
CMD> ruby dk.rb review <== Add "- C:/usr/ruby" into config.yml manually when init failed
CMD> ruby dk.rb install
Create database
CMD> cd C:\usr\mysql\bin
CMD> msyql -u root -p
mysql> create database redmine character set utf8;
mysql> grant all privileges on redmine.* to 'redmine'@'localhost' identified by 'PASSWORD';
Edit C:\usr\redmine\config\database.yml
production:
  adapter: mysql2
  database: redmine
  host: 127.0.0.1 <== In my case, localhost didn't work.
  username: redmine
  password: PASSWORD
Install redmine
Extract redmine into c:\usr\redmine-2.1.0
Add a line into C:\usr\redmine\Gemfile
gem "thin"
Install redmine
CMD> cd C:\usr\redmine
CMD> gem install bundler
CMD> bundle install --without development test rmagick  postgresql sqlite
CMD> set RAILS_ENV=production
CMD> rake generate_secret_token
CMD> rake db:migrate
CMD> rake redmine:load_default_data
Add to end of C:\usr\redmine\config\environment.rb
Redmine::Utils::relative_url_root = "/redmine"
Test
CMD> cd C:\usr\redmine
CMD> thin start -e production
Go to http://localhost:3000/redmine with your web browser, and login admin/admin

Configuration Redmine
Edit C:\usr\redmine\config\configuration.yml
set email in section default
set attachments_storage_path: C:/usr/redmine/files
set scm_git_command: C:\usr\git\cmd\git.exe
Run as a windows service
CMD> gem install win32-service
Save as C:\usr\redmine\service_install.rb
require 'rubygems'
require 'win32/service'

include Win32

SERVICE_NAME = 'Redmine'

# Create a new service
Service.create({
  :service_name       => SERVICE_NAME,
  :service_type       => Service::WIN32_OWN_PROCESS,
  :description        => 'Redmine on Thin as Windows Service',
  :start_type         => Service::AUTO_START,
  :error_control      => Service::ERROR_NORMAL,
  :binary_path_name   => 'c:\usr\Ruby\bin\ruby.exe -C C:\usr\redmine service.rb',
  :load_order_group   => 'Network',
  :dependencies       => ['W32Time','Schedule'],
  :display_name       => SERVICE_NAME
})
Save as C:\usr\redmine\servce.rb
REDMINE_DIR = 'C:\usr\redmine'
LOG_FILE = "#{REDMINE_DIR}\\log\\service.log"

begin
  require 'win32/daemon'
  include Win32

  class RedmineService < Daemon

    def service_init
      File.open(LOG_FILE, 'a'){ |f| f.puts "Initializing service #{Time.now}" }

      @server_pid = Process.spawn 'C:\usr\ruby\bin\ruby C:\usr\ruby\bin\thin start -p 3001 -e production --prefix /redmine', :chdir => REDMINE_DIR, :err => [LOG_FILE, 'a']
    end

    def service_main
      File.open(LOG_FILE, 'a'){ |f| f.puts "Service is running #{Time.now} with pid #{@server_pid}" }
      while running?
        sleep 10
      end
    end

    def service_stop
      File.open(LOG_FILE, 'a'){ |f| f.puts "Stopping server thread #{Time.now}" }
      system "taskkill /PID #{@server_pid} /T /F"
      Process.waitall
      File.open(LOG_FILE, 'a'){ |f| f.puts "Service stopped #{Time.now}" }
      exit!
    end
  end

  RedmineService.mainloop

rescue Exception => e
  File.open(LOG_FILE,'a+'){ |f| f.puts " ***Daemon failure #{Time.now} exception=#{e.inspect}\n#{e.backtrace.join($/)}" }
  raise
end
Install service and run it as Administrator
CMD> cd C:\usr\redmine
CMD> ruby service_install.rb
CMD> net start Redmine
# Check if Redmine runs and see logs at C:\usr\redmine\log\service.log
# See http://localhost:3001/redmine/
Attach to Apache
Add to end of C:\usr\apache\conf\httpd.conf
Include "conf/extra/httpd-proxy-redmine.conf"
Save as C:\usr\apache\conf\extra\httpd-proxy-redmine.conf
<IfModule !mod_proxy.c>
    LoadModule proxy_module modules/mod_proxy.so
</IfModule>
<IfModule !mod_proxy_http.c>
    LoadModule proxy_http_module modules/mod_proxy_http.so
</IfModule>

<IfModule proxy_module>
  <IfModule proxy_http_module>

  ProxyRequests Off
  ProxyPreserveHost On

  <Proxy *>
      Order deny,allow
      Allow from all
  </Proxy>

  ProxyPass /redmine http://127.0.0.1:3001/redmine/
  ProxyPassReverse /redmine http://127.0.0.1:3001/redmine/
  </IfModule>
</IfModule>
See http://localhost/redmine/

2012-09-20

How to run IIS and Apache on the same server

IIS binds all IPs on the server using http.sys.

Sample configuration
IIS on 192.168.0.10:80
Apache on 192.168.0.20:80
  1. For IIS
    • Run netsh on Windows 2008 server,
    • C:\>netsh
      netsh> http add iplisten ipaddress=192.168.0.10
      
      IP address successfully added
      
      netsh> http show iplisten
      
      IP addresses present in the IP listen list:
      -------------------------------------------
      192.168.0.10
      
      netsh> exit
      
    • Download and Run httpcfg on Windows 2003 server,
    • http://www.microsoft.com/en-us/download/details.aspx?displaylang=en&id=15326
      C:\> httpcfg.exe set iplisten -i 192.168.0.10
      C:\> net stop http
      C:\> net start http
      

  2. For Apache Modify httpd.conf
  3. Listen 192.168.0.20:80
    
  4. Result
    • You can see the Welcome screen by IIS with http://192.168.0.10/
    • Also, you have the response from Apache with http://192.168.0.20/