文章

顯示包含「java」標籤的文章

IntelliJ 設定存檔自動 formatter

Below is Neil's answer updated. IntelliJ 13 Steps: 透過巨集錄制完成後並設定成快速鍵。 Code -> Reformat Code Edit -> Macros -> Start Macro Recording Code -> Reformat Code File -> Save all Edit -> Macros -> Stop Macro Recording Name the macro (something like "formatted save") File -> Settings -> Keymap Right click on the macro. Add Keyboard Shortcut. Set the keyboard shortcut to Control + S IntelliJ will inform you of a hotkey conflict. Select "remove" to remove other assignments.

Solr 匯率使用方法

查詢的使用方式 https://wiki.apache.org/solr/CurrencyField 設定匯率 https://cwiki.apache.org/confluence/display/solr/Working+with+Currencies+and+Exchange+Rates OpenCurrency ,每個月有1000次的Query https://openexchangerates.org/api/latest.json?app_id=c6b8570ac6de45cbbd8209292b2aa7f9

簡單記錄一下 Boolean compare 的結果

簡單記錄一下 Boolean compare 的結果 Boolean a1 = true; Boolean a2 = false; System.out.println("true compareTo false : " + a1.compareTo(a2)); System.out.println("false compareTo true : " + a2.compareTo(a1)); a2 = true; System.out.println("true compareTo true : " + a2.compareTo(a1)); a1=false; a2=false; System.out.println("true compareTo true : " + a2.compareTo(a1)); 輸出結果: true compareTo false : 1 false compareTo true : -1 true compareTo true : 0 true compareTo true : 0

Java 匯入keystore

keytool -importkeystore -srckeystore jksfile -keystore $JAVA_HOME/jre/lib/security/cacerts 預設的密碼: changeit

eclipse 轉換到 intellij-Editing Resource Bundle

圖片
Internationalization (I18N Support) Editing Resource Bundle 若有遇到中文無法正常顯示時,到設偏好設定中的File Encodings 中調整,勾選:Transparent native-to-ascii conversion 目錄的顯示 左下方有:Text , Resource Bundle 可以切換編輯方式

Resolve paste text to PgAdmin from Eclipse.

For my problem, I had to go to Window > Preferences > Java > Editor > Typing, and uncheck "Update imports" Reference : http://stackoverflow.com/questions/1189002/eclipse-3-5-copy-paste-problem

Integrating pentaho bi server

其實在安裝好的環境內有 integrating_biserver.pdf 的說明文件,文件中有提供一個範例pentaho_integration_examples.war,依步驟安裝後就會可以看到他的串接說明,不過文件中特別到到一個,你必須要先登入,不然會轉址到登入頁,這問題其實還挺困擾,繼續找尋解法,最後找到網友提供的方式,在URL後面加上登入資訊的參數,如: userid=joe&password=password ,這樣就可以免登入直接看報表了,有了這個神器讓我能整報到至內部系統來使用,真是太方便了。

Google 短網址API http://goo.gl/fbsS

Google 提供的短網址 short url 首先要去: https://code.google.com/apis/console/b/0/#project:865057694379  啟用您的服務並申請api key. 這裡有一個官方提供的sample code :  http://code.google.com/p/google-api-javascript-client/wiki/Samples#URL_Shortener_API 接下來要注意幾個東西,若您是要產生短網址,記得修改幾個地方 原始內容是反查短網址         var request = gapi . client . urlshortener . url . get ({           'shortUrl' : 'http://goo.gl/fbsS'         }); 下面的是產短網址         var request = gapi . client . urlshortener . url . insert ({           'resource': { 'longUrl' : 'http://goo.gl/fbsS' }         }); 原始回傳結果抓取方式 appendResults ( response . longUrl ); 改用抓取ida即可 appendResults ( response . id ); 若未使用: 'resource': { 'longUrl' : 'http://goo.gl/fbsS' } 會回傳下列的錯誤訊息: {  "error": {   "errors": [    {     "domain": "global",     "reason": "...

struts2 jquery plugin

最近工作上的需要一個autocomplate的功能,雖然很多套件都有此功能,總得找個容易上手的套件,第一個找到的套件是: struts2-dojo-pluging ,看完文章後想說既然有dojo,那有沒有jquery plugin 呢?谷哥一下後找到: http://code.google.com/p/struts2-jquery/ ,試用後就決定是他了。 簡單的使用方式: 在Action中 private List queryList; // 需要再加上 set / get 的method public String edit() {   queryList = new ArrayList();   queryList.add("TW");   queryList.add("US");   queryList.add("JP");   queryList.add("IT");   queryList.add("FR");   return SUCCESS; } 在jsp中的使用方式: < sj:autocompleter id = "lanauages" name = "lanauagesName" list = "%{queryList}" / > 另外需要加上:   < sj:head jqueryui = "true" />   這個 head就是載入jquery js的相關作業,若您需要使用新版本的jquery,可以自行在原來jar file 中template\jquery\下,複制:head.ftl到自己專案中,再修改需要變動的內容。

Jboss 7 第一步~

未來可能會用到,先自己練習一下吧 1:將war更新於 : /jboss-as-7.1.1.Final/standalone/deployments/ 2:datasource設定 : 修改/jboss-as-7.1.1.Final/standalone/configuration/standalone.xml 安裝jdbc driver Install jdbc driver have two ways.either as a deployment or as a core module. copy jar to : jboss-7.0.0.<release>/modules/com/mysql/main create module.xml file <?xml version="1.0" encoding="UTF-8"?> <!--   ~ JBoss, Home of Professional Open Source.   ~ Copyright 2010, Red Hat, Inc., and individual contributors   ~ as indicated by the @author tags. See the copyright.txt file in the   ~ distribution for a full listing of individual contributors.   ~   ~ This is free software; you can redistribute it and/or modify it   ~ under the terms of the GNU Lesser General Public License as   ~ published by the Free Software Foundation; either version 2.1 of   ~ the License, or (at your option) any later version.   ~   ...

Jboss 7 開啟mod_jk功能

加上下列紅字那行,另外scheme不可以用:ajp,就是說明沒看清楚又浪費了我一些時間!xd <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false">             <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>             <connector name="ajp" protocol="AJP/1.3" scheme="http" socket-binding="ajp"/>             <virtual-server name="default-host" enable-welcome-root="true">                 <alias name="localhost"/>                 <alias name="example.com"/>             </virtual-server>         </subsystem>         <subsystem xmlns="urn:jboss:domain:webservices:1.1">             <modify-wsdl-address>true</mod...

Jboss 7 Datasource 出現:service jboss.jdbc-driver.mysql (missing)

設定後啟動出現下列錯誤, service jboss.jdbc-driver.mysql (missing) 原來是使用:mysql-connector-java-5.0.8-bin.jar 改用:mysql-connector-java-5.1.19-bin.jar 就正常可以使用了。

用Maven来創建一个非常簡單的Helloworld項目

用Maven来創建一个非常簡單的Helloworld項目 mvn archetype:create -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=net.jinwei.test -DartifactId=helloworld

jboss AS 7.X 安裝啟動

圖片
首先從jboss官網下載,網址: http://www.jboss.org/jbossas/downloads 解開壓縮後目錄結構如下: 若沒什麼特別,直接在command模式一下,在bin目錄下,執行:standalone.sh(若是window系統,請執行:standalone.bat)即可, 啟動完成後,可以透過http://localhost:8080/,看到下列結果: 您可以點選 administrator console,此時會請您先建立使用者,再使用一個command模式,在bin目錄下,執行:add-user.sh(若是window系統,請執行:add-user.bat) 執行後會出現: What type of user do you wish to add?  a) Management User (mgmt-users.properties)  b) Application User (application-users.properties) 選擇 a, Enter the details of the new user to add. Realm (ManagementRealm) : (enter) Username : (輸入帳號) Password : (輸入密碼) Re-enter Password :(再輸入密碼) About to add user 'xxxxxx' for realm 'ManagementRealm' Is this correct yes/no? yes(輸入yes) 建立完成,即可進入管理界面了。 若您在啟動時,希望載入自定的設定檔,指令如下: ./standalone.sh --server-config=standalone-ha.xml

Ajaxify

圖片
自從開始使用 ajax後,網頁返回上頁後,往往會出乎你的意料,但發現Facebook / Google為何能避開這個問題,我留意到了,他們網址真的會被replace,但頁面郤不會有刷新的感覺,這真的可以被browser抓住上一頁的,仔細研究了Facebook,發現到一個特別的東西:ajaxify ,我想這就是我要的東西,果真真的是我要的

Eclipse 免費的UML & ER-Diagram 工具

ER-Diagram工貝 AmaterasERD: http://amateras.sourceforge.jp/cgi-bin/fswiki_en/wiki.cgi?page=AmaterasERD UML工具 AmaterasUML: http://amateras.sourceforge.jp/cgi-bin/fswiki_en/wiki.cgi?page=AmaterasUML 雖然只支援:Activity Diagram / Class Diagram / Sequence Diagram / Usecase Diagram,算是不錯了, 因為很多免費的不支援 Class Diagram export to java or import from java,這應該是對他有很大的加分! 2012-0229 update,若你開啟編輯時,若是物件都不見了 white screen,請更新jre為 1.6版,這問題在jre 7時會有此問題(please use  jre 1.6 or remove jre 1.7)。

載入tiles 前的插入,以達成動態產生tiltle

Tiles 的模塊真的很好用,但如何達到動態產生tilte,並使用Spring來抓取資料,這段之前很頭痛,終於找到解法 首頁修改Tiles,加入preparer < definition name ="member.index" extends ="basic"  preparer ="PlatFormViewPreparer" >     < put-attribute name = " title " value = "首頁" />     < put-attribute name ="content"  value ="/WEB-INF/jsp/demo/index.jsp" /> </ definition >   自行寫一個PlatFormViewPreparer.java,若有Package name也要加上去 PlatFormViewPreparer.java 他必須繼承:ViewPreparerSupport publicclass PlatFormViewPreparer extends ViewPreparerSupport  覆寫 execute的方法,可以透過ServletUtil取得ServletContext,再透過Servletcontext和WebApplicationContext來取得Spring 物件,就可以自由操作Spring的功能,另外回再透過,AttributeContext 的 arg1,來將資料傳出去,而這個title需要與jsp樣內要換的名稱相同。 @Override publicvoid execute(TilesRequestContext arg0, AttributeContext arg1) throws PreparerException {       ServletUtil.getServletContext(arg0.getApplicationContext());      WebApplicationContext springContext ...

試試在Mac 中使用 jdk 7.0

下載位置:http://jdk7.java.net/macportpreview/ 裝完後請在command模式中,做下列指令 cd /System/Library/Frameworks/JavaVM.framework/Versions sudo ln -s /Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents 1.7.0 在Eclipse 中可在偏好設定中 -> Java  -> Installed JREs 中加入新的設定  新功能介紹:http://blog.cyberjos.idv.tw/space/2011-08-03/1

Eclipse 幾個常用的plugin

Properties Editor 可以直接編輯Properties好處是可以直接幫我們轉換字的encode 下載位置: http://propedit.sourceforge.jp/eclipse/updates/ 官網: http://propedit.sourceforge.jp/index_en.html Velocity UI 下載位置: http://veloedit.sourceforge.net/updates/ 官網: http://veloedit.sourceforge.net/ Subclipse 下載位置: http://subclipse.tigris.org/update_1.6.x 官網: http://subclipse.tigris.org/ Maven Integration(m2e) 下載位置: http://m2eclipse.sonatype.org/sites/m2e 官網: http://eclipse.org/m2e/ Spring IDE,Springsource tool suite 下載位置: http://dist.springsource.com/release/TOOLS/update/e3.7 官網: http://www.springsource.org/downloads/sts

ubuntu 下安裝 sun java

增加 partnet 來源 sudo add-apt-repository "deb http://archive.canonical.com/ubuntu maverick partner" 系統提示沒有add-apt-repository命令,則需要另外安裝 python-software-properties,指令:sudo apt-get install python-software-properties 若安裝後還是無法使用,可以手動自行添加來源,添加方式:sudo vi /etc/apt/sources.list,加入:dev http://archive.canonical.com/ubuntu maverick partner 更新來源   sudo apt-get update   安裝 jre   sudo apt-get install sun-java6-jre sun-java6-plugin   安裝 jdk   sudo apt-get install sun-java6-jdk sun-java6-plugin   變更系統預設的Java   sudo update-alternatives --config java   選擇就可以了 參考來源: http://wiki.ubuntu.org.cn/Sun-java6