星期四, 5月 31, 2012

[Java] Cannot create JDBC driver of class '' for connect URL 'null'

想要透過local的專案直接連mysql所遇到的
Cannot create JDBC driver of class '' for connect URL 'null'錯誤訊息的方法,
Google到的資訊實在太多做法了,把試成功的經驗記錄一下。

step1:在專案內的WEB-INF/加入context.xml檔

<xml version="1.0" encoding="UTF-8"?>
<Context >
<Resource
                name="jdbc/資料表連接名稱"
                auth="Container"
                type="javax.sql.DataSource"
        maxActive="100"
                maxIdle="30"
                maxWait="10000"
        username="root"
                password="密碼"
                driverClassName="com.mysql.jdbc.Driver"
        autoReconnect="true"
                removeAbandoned="true"
                removeAbandonedTimeout="300"
                logAbandoned="false"
        url="jdbc:mysql://遠端IP:3306/資料庫名稱"/>
        
Context>


Tip:DBCP已經設全域設定了,所以這個不用加
step2:在專案的web.xml加入

<resource-ref>
      <description>DB Connectiondescription>
      <res-ref-name>jdbc/資料表連接名稱res-ref-name>
      <res-type>javax.sql.DataSourceres-type>
resource-ref>

非常重要!!記得要重新開Tomcat!!

星期三, 5月 30, 2012

Mac lion Eclipse 設定 JDK7

在lion安裝完JDK7後,它的路徑已經先之前安裝的路徑不一樣了。
目前預設的安裝目錄是在
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home

之後打開Eclipse後,透過偏好設定的JAVA中的Installed JREs,指定新的JDK就可以了。


找到的參考資料
If you are a Java developer who wants to do Java development on Mac OS X 10.7, here are a few not-so-tricky steps to follow to get going:
  1. Go to http://connect.apple.com and sign in with your Apple ID (developer account may be required – it’s free).
  2. From the list titled “Downloads for Apple Developers”, select the item labeled “Java for Mac OS X 10.7 Update 1 Developer Package” (release date Nov 8, 2011) then download and install the package.
  3. The JDK will be installed into a different location then previous. This will result in IDEs (such as Eclipse) being unable to locate source code and java docs.
  4. At the time of writing the JDK ended up here:
    /Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home
  5. Open up Eclipse preferences and go to Java > Installed JREs page
  6. Rather than use the “JVM Contents (MacOS X Default) we will need to use the JDK location
  7. At the time of writing Search is not aware of the new JDK location; we we will need to click on the Add button
  8. From the Add JRE wizard choose “MacOS X VM” for the JRE Type
  9. For the JRE Definition Page we need to fill in the following:
    JRE Home: /Library/Java/JavaVirtualMachines/1.6.0_26-b03-383.jdk/Contents/Home
  10. The other fields will now auto fill, with the default JRE name being “Home”. You can quickly correct this to something more meaningful such as:
    JRE name: System JDK
  11. Finish the wizard and return to the Installed JREs page
  12. Choose “System JDK” from the list
  13. You can now develop normally with:

[Java] Filter 變更 jsp輸出內容

今天為了讓jsp上面的js檔案能使用SVN的版號做版本控制,
又為了讓同事能不用變更之前放在jsp裡面的script path,
所以想到了可以透過filter來將jsp輸出前把script path加上SVN的版號,
這樣就可以模擬出使用者每次都能讀到最新變更的Javascript

以下是簡單置換內容的Filter Sample

星期二, 5月 29, 2012

星期一, 5月 28, 2012

[Alfresco] Alfresco Namespace

Note: This list will expand / change between now and the next release.
NamespaceCommon PrefixDescription
http://www.alfresco.orgalfGeneral Alfresco Namespace
http://www.alfresco.org/model/dictionary/1.0dData Dictionary model
http://www.alfresco.org/model/system/1.0sysRepository system model
http://www.alfresco.org/model/content/1.0cmContent Domain model
http://www.alfresco.org/model/application/1.0appApplication model
http://www.alfresco.org/model/bpm/1.0bpmBusiness Process Model
http://www.alfresco.org/model/site/1.0stSite Model
http://www.alfresco.org/model/forum/1.0fmForum Model
http://www.alfresco.org/model/user/1.0usrUser model (in repository.jar)
http://www.alfresco.org/view/repository/1.0viewAlfresco Import / Export View
http://www.alfresco.org/model/action/1.0actAction service model
http://www.alfresco.org/model/rule/1.0ruleRule service model
http://www.alfresco.org/ws/service/authentication/1.0authAuthentication Web Service
http://www.alfresco.org/ws/service/repository/1.0repRepository Web Service
http://www.alfresco.org/ws/service/content/1.0contentContent Web Service
http://www.alfresco.org/ws/service/authoring/1.0authorAuthoring Web Service
http://www.alfresco.org/ws/service/classification/1.0clsClassification Web Service
http://www.alfresco.org/ws/cml/1.0cmlContent Manipulation Language
http://www.alfresco.org/ws/model/content/1.0cmWeb Service Content Domain Model
http://www.alfresco.org/ws/headers/1.0hdrSOAP Headers
http://www.alfresco.org/model/workflow/1.0wfWorkflow Model(link is to Alfresco simple workflow model, not generally extended)

[Eclipse] 設定JRE與Tomcat runtime

簡單記錄一下Eclipse設定JRE與Server Runtime擷圖XD

JRE Runtime
Step1: Windows-> Preference
Step2: Java-> Installed JREs


Server Runtime

Step1: Windows-> Preference
Step2: Server-> Runtime Environments
Step3: Add, 新增一個runtime server

Step4: 選擇新的runtime enviornment,範例為tomcat 7.0

Step5: 設定Tomcat安裝目錄
C:\Program Files\Apache Software Foundation\Tomcat 7.0



Step6: 完成,接下來編譯時選擇你要的執行環境即可


phpmyadmin 重新命名資料表

XD找好久
1.點選要修改的資料表
2.之後到瀏覽介面後,按上面的管理
3.資料表選項內,直接將資料表改名為的框框修改就好了

星期二, 5月 22, 2012

[Heroku] Java on Heroku

試玩了一下Heroku,發現自已從本地端的eclipse建Maven專案push上去Heroku後,
app都run不起來。
不過目前Heroku支援了四種template來幫助開發者在上面開發web app。
請參考這個網站:http://java.heroku.com/

•Web app with Spring and Tomcat
•Containerless web app with Embedded jetty
•Web app with Play! Framework
•RESTful API with JAX-RX

[Java] Maven + Eclipse 備忘錄

Maven是什麼?

Maven提供你的是建構環境,或說是建構環境的框架(Framework)。

Maven的主要精神有:


  • 慣例先於設定(Convention over configuration)


舉例來說,在Maven中認為,專案開發遵循應某些慣例,這些慣例像是固定目錄的名稱與架構、固定變數的名稱、固定的建構生命周期(Build lifecycle)等。Maven認為你不應花費時間在這些慣例的設定上,而要將精神放在更重要的工作上。


  • 集中管理相依性(Dependency management)


正如在 簡介 Apache Ivy 中提到的,程式庫的相依性管理是個頭痛的問題,Maven使用集中式管理,提供集中式的貯藏室(Central repository),你要在設定檔案宣告相依的程式庫等資訊,Maven會為你下載相關的檔案。

plugin 為基礎的架構

Maven 提供固定的建構生命周期,像是Default、Clean、Site等。在每個生命周期中,又會分作一些階段(Phase), 像是Default生命周期中,會有Validate、Compile、Test、Package、Integration test、Verify、Install、Deploy等階段,每個階段會有一些相繫結的plugin,Maven本身會有一些預設的plugin,你也 可以在設定檔中依需求宣告想使用的plugin,Maven會自動取得plugin。

專案物件模型(Project Object Model)


在Ant中使用build.xml來定義建構過程中的所有資訊,在Maven中與之對應的是pom.xml,不過pom.xml主要的目的是提供專案資訊,像是專案名稱、組織名稱、相依資訊等。


星期日, 5月 20, 2012

[RoR] 如何連接資料庫

Rails內建的資料庫是採用SQLite,資料庫的設定檔在此目錄下:config/database.yml


# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

建立一個Model
$>rails g model users account:string password:string

      invoke  active_record
      create    db/migrate/20120520124738_create_users.rb
      create    app/models/users.rb
      invoke    test_unit
      create      test/unit/users_test.rb
      create      test/fixtures/users.yml

使用migrate建立資料表

$> bundle exec rake db:migrate

==  CreateUsers: migrating ====================================================
-- create_table(:users)
   -> 0.0014s
==  CreateUsers: migrated (0.0015s) ===========================================

新增一個descript欄位到users表格

rails g migration add_descript_to_users
      invoke  active_record
      create    db/migrate/20120520125033_add_descript_to_users.rb


執行migrate將剛新增的欄位加入

$>bundle exec rake db:migrate
==  AddDescriptToUsers: migrating =============================================
==  AddDescriptToUsers: migrated (0.0000s) ====================================


TIP:Rails會知道哪些已經執行過migration,所以只會執行一次


Rake指令集
rake db:create # to create database
rake db:migrate # to create tables based on your migration







星期六, 5月 19, 2012

[RoR] 第一個RoR應用程式: HelloWorld

來個所有程式的第一步吧,HelloWorld

測試環境:
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.3.0]
Rails 3.2.3
作業1:HelloWorld 起步

星期三, 5月 09, 2012

[Javascript] Prototype 繼承

記錄一些關於Prototype的讀後感:)


Prototype的好處?
Javascript可使用Prototype來擴充類別的方法,
可以增加其效能,可將全部已instances的物件,
全部加上新的方法。

為什麼要用jQuery.fn?
jQuery中的jQuery.fn ($.fn) 其實就是等於 jQuery.prototype,
意即:

$.fn = $.prototype

所以寫外掛的時候就能輕鬆擴充jQuery的函式庫了。

為什麼不直接用$.prototype?


主要在於早期的jQuery.fn裡的每個內容並不使用prototype來實作,
而是採繞行整個物件的方式,
因為物件內的屬性跟方法可能很多,導致速度很慢,
後續版本改用prototype來提升效能,
為避免已存在的外掛程式被破壞。
所以才有會$.fn = $.prototype的別名存在。

Reference:
用javascript的prototype來玩繼承

[jQuery API] Deferred Object

Deferred Object 最大的特色在於處理非同步的狀況時,所執行的 Callback function 可以指定多個,讓程式增加可讀性,舉一個簡單的例子來說明:


Deferred Object 的狀態可分成三種
1. Pending: Operation 處理中
2. Resolve: Operation 處理成功
3. Reject: Operation 處理失敗


Reference:
http://ithelp.ithome.com.tw/question/10090605

星期二, 5月 08, 2012

[jQuery plugin] 使用tinyscrollbar外掛做出iphone/ipad捲軸視窗效果

如果使用iPhone/iPad常常會看到視窗過長的捲軸效果,
現在Facebook也都有一樣的捲軸視窗,
使用tinyscrollbar可以簡單的完成這個效果。




[jQuery Plugin] imagesLoaded偵測圖檔已被讀取

需要偵測圖檔已被讀取完畢的話,可以使用imagesLoaded這個外掛:)

[jQuery API] 偵測元素大小被改變 Detect element resize

先前寫了一個FlickrLinkr小服務,在div添加tinyscrollbar的外掛, 但因為div裡面需要讀取圖檔,當未讀取完的時候,會導致tinyscrollbar的高度不正常(後面被讀取出來的圖檔被div擋住) 可以透過這個可以偵測元素resize的外掛來解決目前的問題:)

[RoR] Ruby on Rails 完整架構圖

RoR完整架構圖,讓你簡單了解RoR MVC架構




Reference:

星期四, 5月 03, 2012

[IIS7] URL rewrite for php

前幾天試著透過Fast CGI想在上面跑phpMyAdmin的專案結果不是很順利(可參考 這篇)
今天換個變通的想法,
利用IIS 7的rewrite的模組來進行轉址~
開始動手設定吧XD

星期三, 5月 02, 2012

UML 又來了 lol

免費的UML圖表工具
http://astah.net/

活動圖:

  • 活動圖是表示流程的大方向面
  • 不要落入描述活動的細節裡面,有細節可再細分第二張活動圖
  • 活動圖應保持易讀性與單純化

http://microbuddy.blogspot.com/2009/03/uml_25.html

循序圖:
http://codingjames.blogspot.com/2009/08/uml-sequence-diagram.html

其他你感興趣的文章

Related Posts with Thumbnails