<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    云自無心水自閑

    天平山上白云泉,云自無心水自閑。何必奔沖山下去,更添波浪向人間!
    posts - 288, comments - 524, trackbacks - 0, articles - 6
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    2015年2月9日

    1. java zip 多個文件時,如果先添加了一個excel文件,然后再想添加其他的文件時會出現 steam is closed的錯誤。這是因為work.write(outputSteam)后,出調用outputSteam.close(),關閉輸出流。
    解決方法:
    將原來的程序:
                ZipEntry entry = new ZipEntry( "file3.txt" );
                zos.putNextEntry( entry );
                workbook.write( zos );
                zos.closeEntry();
    改為:
                ZipEntry entry = new ZipEntry( "file3.txt" );
                zos.putNextEntry( entry );
                workbook.write( new NonCloseableOutputStream( zos ) );
                zos.closeEntry();

    其中 NonCloseableOutputStream 定義如下:
    public class NonCloseableOutputStream extends java.io.FilterOutputStream {
        public NonCloseableOutputStream(OutputStream out) {
            super(out);
        }
        @Override public void close() throws IOException {
            flush();
        }
    }



    2. 使用binary使得mysql區分大小寫
    select * from table1 where binary field1 = 'abc';

    posted @ 2017-08-09 19:52 云自無心水自閑 閱讀(428) | 評論 (0)編輯 收藏

    https://notepad-plus-plus.org/community/topic/13661/plugin-manager-x64-available-submit-your-plugins

    posted @ 2017-06-26 09:33 云自無心水自閑 閱讀(396) | 評論 (0)編輯 收藏

    move Git Server to a new IP/URL:

    you can just edit 
    .git/config and change the URLs there

    也可以在git視圖中,右鍵點擊項目,選擇屬性,然后修改url中的地址

    posted @ 2017-06-15 08:40 云自無心水自閑 閱讀(320) | 評論 (0)編輯 收藏

    autohotkey
    listary
    cmder可以split screen,在一個窗口中同時運行數個cmd

    posted @ 2017-05-24 07:13 云自無心水自閑 閱讀(17853) | 評論 (0)編輯 收藏

    官網地址:autohotkey.com

    ; fill password
    ^Numpad2::
    Send, root{tab}root{enter}
    Return
    ^Numpad3::
    IfWinExist, ahk_exe OUTLOOK.EXE
    {
        WinActivate ahk_exe OUTLOOK.EXE ; Automatically uses the window found above.
        ; WinMaximize  ; same
        ;Send, Some text.{Enter}
    msgbox Outlook is running.
    }
    Return

    posted @ 2017-03-08 13:06 云自無心水自閑 閱讀(368) | 評論 (0)編輯 收藏

    <html>
    <head>
        <script src="https://unpkg.com/vue/dist/vue.js"></script>
        <script>
            window.onload = function () {
                var app = new Vue({
                    el: '#app',
                    data: {
                        message: 'Hello Vue!'
                    }
                });
            }    
        </script>
    </head>

    <body>
        <div id="app">
          {{ message }}
        </div>
    </body>
    </html>

    posted @ 2017-02-09 07:41 云自無心水自閑 閱讀(402) | 評論 (0)編輯 收藏


    String[] splits=someString.split("a,b,c,d", ",");
    logger.debug( "array: {}", (Object) splits );

    這里要注意的就是要把數組的數據類型強制轉換為Object 

    posted @ 2016-12-29 11:51 云自無心水自閑 閱讀(1619) | 評論 (0)編輯 收藏

    在windows環境中,可以用如下方法重置root密碼

    1、先停止mysql數據庫

    2、保存密碼重置sql文件
         5.7.6(包括)以后的版本:ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
         5.7.5(包括)以前的版本:SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
    假設保存到文件: c:\reset.txt

    3、以管理員身份打開命令行窗口,運行
    C:\> cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
    C:\> mysqld --init-file=C:\reset.txt

    4、啟動后,還不能馬上用新密碼連接數據庫,需要重啟mysql數據庫

    posted @ 2016-12-21 07:12 云自無心水自閑 閱讀(370) | 評論 (0)編輯 收藏

    This is a general step that happens when m2e/m2eclipse (Maven integration for Eclipse) is installed, whether projects are actively using it or not.
    這是因為m2eclipse(maven插件)要在啟動時需要進行的一個步驟。

    This step can be disabled through the Eclipse preferences: Window / Preferences / Maven / "Download repository index updates on startup". This option is on the main "Maven" preference page (not a child page). Just uncheck the box to prevent this from happening.
    我們可以停止這個動作。方法:Windows -> Preferences -> Maven 取消勾選 Download repository index updates on startup

    posted @ 2016-11-29 08:38 云自無心水自閑 閱讀(1310) | 評論 (0)編輯 收藏

    有好幾個java library都可以實現這個功能,但是從pdf提取文本的一個問題是,提取出來的文本沒有固定的順序,不容易比較好的還原其格式。

    我的做法是使用pdfclown來進行這項工作。官方網站是:https://pdfclown.org/ 先下載其最新版本。
    參考其示例代碼:https://pdfclown.org/2010/01/02/upcoming-0-0-8-whats-going-to-be-new/#more-30

    使用這段代碼,我們不僅可以得到文本的字符串,還能得到文本的頁數和相對坐標。
    我的思路是先把所有文本的字符串和坐標提取出來。然后排序,排序的順序是縱坐標,然后橫坐標。
    這樣排序完畢后,就能比較好的解決文本格式問題。

    posted @ 2016-11-28 11:03 云自無心水自閑 閱讀(385) | 評論 (0)編輯 收藏


    1, 先定義一個input, 做為datepicker的容器。
    <input type='text' class="form-control" id="dateTo" name="dateTo" required/>

    2, 在后面加上glyphicon, 注意關鍵是label 中的for的id需要是前面定義的容器的id, 這樣點擊glyphicon的時候就會觸發彈出日期選擇框。
    <label for="dateTo" class="input-group-addon"><span class="glyphicon glyphicon-time"></span></label>

    posted @ 2016-10-10 19:57 云自無心水自閑 閱讀(219) | 評論 (0)編輯 收藏

    在日志文件中看到這個錯誤信息
    Cause: java.sql.SQLException: #HY000

    后來才知道這是因為數據庫中有個別字段要求不能為空, 但是insert語句中沒有提供數據,造成了這個錯誤。

    關鍵是錯誤信息不明確直觀,不容易知道是這個原因


    posted @ 2016-09-28 13:13 云自無心水自閑 閱讀(1067) | 評論 (0)編輯 收藏

        public void afterJFinalStart(){
            Configuration config = FreeMarkerRender.getConfiguration();
            config.setTemplateUpdateDelayMilliseconds( 2 );
            config.setAPIBuiltinEnabled( true );
        }

    posted @ 2016-09-21 14:02 云自無心水自閑 閱讀(239) | 評論 (0)編輯 收藏


    中文版地址  https://angular.cn/

    posted @ 2016-09-16 13:13 云自無心水自閑 閱讀(2108) | 評論 (0)編輯 收藏

    1, call ##002# to cancel "call diversion"

    2, call 121600, choose option "2" to cancel "Active call catcher"

    posted @ 2016-08-25 12:58 云自無心水自閑 閱讀(154) | 評論 (0)編輯 收藏

    1. 格式化XML的插件
    可以安裝“XML Tools", 安裝完畢后,選擇 插件->XML Tools->Pretty Print(XML Only - with line breaks)

    2. 格式化JSON的插件
    可以安裝”JSON Viewer", 安裝完畢后,選擇 插件->JSON Viewer->Format JSON

    3. 格式化SQL的插件
    可以安裝“Poor man's T-Sql Formatter", 選擇 插件->Poor man's T-Sql Formatter->Format T-Sql Code

    posted @ 2016-08-12 15:14 云自無心水自閑 閱讀(1052) | 評論 (0)編輯 收藏

     
    使用的工具

    1. Apache HttpClient
    2. Firefox + FireBug
    3. Burp Suite ( https://portswigger.net/burp ) + Firefox FoxyProxy

    Firefox + FireBug 主要用于查看渲染出的頁面中的信息(比如:表單項的名稱,節點ID等等)
    Burp Suite 主要用于動態攔截頁面的交互,查看Ajax的調用。
    HttpClient 用于最后程序的編制。搞清楚了網頁交互的過程,就可以自主決定程序需要包含的內容。
    在實際網頁中,可能需要點開數級菜單,才能最后看到需要的內容。
    但是在程序中,可以直接跳到最后一步。

    posted @ 2016-06-05 19:00 云自無心水自閑 閱讀(198) | 評論 (0)編輯 收藏

    1. 表格文字右對齊 
     <table>
    <tr>
        <td><p style="text-align:right;margin:0;padding:0">文字右對齊</p></td>
        <td>文字左對齊</td>
    </tr>
    </table>

    2. 表格邊緣的margin 需要在表格外再套一個div
    <div style="margin:10px">
        <table>
        ......
        </table>
    </div>

    3. btn-toolbar class can put a margin between 2 "pull-right" buttons
            <div class="row">
                <div class="col-md-2"></div>
                <div class="col-md-8 btn-toolbar">
                    <input type="submit" class="btn btn-warning pull-right" value="Submit">
                    <input type="button" id="profilePassBackBtn" class="btn btn-info pull-right" value="Back">
                </div>
                <div class="col-md-2">
                </div>
            </div>

    posted @ 2016-05-31 11:39 云自無心水自閑 閱讀(378) | 評論 (0)編輯 收藏

     AngularJS 2.0 已經發布了Beta版本,相信正式版不久以后就會發布了。

    下面是官網上的新功能介紹:

    1. 更快更高效。AngularJS 2 將會比 AnuglarJS 1 快很多。因為它會支持:從遠程胳快速加載、離線編譯以便于更快啟動、以及超快的變動檢測和為使滾動更平滑的視圖緩存等等。

    2. 更加簡單清晰。語法將會顯得更加自然,易于編寫

    3. 跨越平臺。無論是臺式機、手機瀏覽器、安卓、IOS平臺,AngularJS都能提供相應的支持。

    4. 無縫從 AngularJS 1 升級到 2

    5. 簡便的開發。支持各種開發語言,ES5, TypeScript, Dart

    6. 全面完備的路由。 方便地映射URL到應用組件,并提供多種高級功能,比如:嵌套和鄰接路由,支持卡片棧導航、動畫過渡、手機用戶延遲加載等等

    7. 依賴注入。

    8. 舊瀏覽器的良好支持

    9. 動畫效果 (仍在開發中)

    10. 國際化支持(仍在開發中)

    posted @ 2016-04-18 20:09 云自無心水自閑 閱讀(265) | 評論 (0)編輯 收藏

    1. Go to web project properties.
    2. Deployment Assembly (Left).
    3. Add > Select project > Select your lib project > Check "Assemble projects into the WEB-INF/lib folder of the web application" if not checked > Finish.

    posted @ 2016-04-13 10:35 云自無心水自閑 閱讀(171) | 評論 (0)編輯 收藏

     使用酷狗就可以轉換。
    右鍵點擊歌曲 ,工具,格式轉換。
    唯一要注意的是要先登錄。

    posted @ 2016-03-17 20:20 云自無心水自閑 閱讀(1595) | 評論 (0)編輯 收藏

    今天把commons dbcp 和 pool都升級到2.x, 結果發現不能正常的工作,卡在new BasicDataSource()上了.
    后來才發現原因是因為沒有加入commons-logging的jar文件

    幾個注意點:
    1. commons dbcp2.x 和 commons pool需要同時升到2.x
    2. dbcp 2.x要運行在java 7以上 
    3. mysql connector要5.1.11以上
    4. 需要有commons-logging的包,我使用的是slf4j, 就需要加一個jcl-over-slf4j

    posted @ 2016-02-09 11:44 云自無心水自閑 閱讀(615) | 評論 (0)編輯 收藏

    Error
    com.jcraft.jsch.JSchException: The cipher 'aes256-cbc' is required, but it is not available.
    or
    Caused by: java.security.InvalidKeyException: Illegal key size


    posted @ 2016-02-05 13:51 云自無心水自閑 閱讀(270) | 評論 (0)編輯 收藏


    我在網上搜索了一下如何使用Selenium下載文件,其中確實有幾篇文件介紹了實現的方法。
    但是其主要思想都是使用httpClient或者URL獲得InputStream, 然后保存到文件中。
    但是,其中的問題是用戶登錄的Session不能維持。

    我發現了一個簡單的方法。
    直接使用WebDriver.get, 示例如下:

    webDriver.get("https://website.com/login");
    WebElement element = driver.findElement( By.id( "userID" ) );
    element.sendKeys( "user01" );

    element = driver.findElement( By.id( "passwd" ) );
    element.sendKeys( "password" );

    element = driver.findElement( By.name( "Login" ) );
    element.submit();

    webDriver.get("https://website.cm/download.do?start=xx&end=yy");
    String source = webDriver.getPageSource();

    這個source就是我們想保存的要下載的內容。
    只要把這個String寫到一個文件中,就實現了文件下載的目的

    posted @ 2016-01-28 18:06 云自無心水自閑 閱讀(470) | 評論 (0)編輯 收藏

         摘要: 在我的上一篇文章中介紹了如何進行GPG加密解密。
    加密解密的基本操作流程是,用戶使用公鑰對明文進行加密,解密方使用私鑰對密文進行解密。

    在實際應用中,除了加密保證文本內容不泄露外,同時還要考慮能夠驗證密文發送方的身份,比較普遍使用的方法就是簽名。
    本文主要對具體的方法進行介紹并附上源代碼。  閱讀全文

    posted @ 2015-12-11 21:40 云自無心水自閑 閱讀(1268) | 評論 (0)編輯 收藏

    Java程序中訪問擁有全部讀寫權限的目錄相對比較簡單,和普通的目錄沒有什么差別。
    但是要訪問一個需要用戶和密碼驗證的目錄就需要一點點小技巧了。
    這里介紹一個開源的庫能夠比較容易的實現這一需求。
    1。 下載庫文件:
     https://jcifs.samba.org/
    下載的zip文件中, 不僅包含了jar文件,還有文檔和示例。

    2。拷貝jcif-1.3.18.jar到類路徑中。

    3。代碼示例:
     1     String user = "your_user_name";
     2     String pass ="your_pass_word";
     3 
     4     String sharedFolder="shared";
     5     String path="smb://ip_address/"+sharedFolder+"/test.txt";
     6     NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",user, pass);
     7     SmbFile smbFile = new SmbFile(path,auth);
     8     SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
     9     smbfos.write("testing.and writing to a file".getBytes());
    10     System.out.println("completed nice !");
    說明: 如果有一個共享目錄,比如: \\192.168.1.2\testdir\
    那么smb的路徑就是:smb://192.168.1.2/testdir/
    NtlmPasswordAuthentication需要三個參數, 第一個是名,沒有的話,填null, 第二個是用戶名,第三個是密碼

    得到SmbFile之后,操作就和java.io.File基本一樣了。
    另外還有一些功能比如:
    SmbFile.copyTo
    SmbFile.renameTo
    等等

    posted @ 2015-11-20 14:03 云自無心水自閑 閱讀(12984) | 評論 (0)編輯 收藏

    先將my.default.ini改名為my.ini放到bin目錄
    命令行執行: mysqld --initialize --user=mysql --console
    先執行以上命令, 生成庫. 注意有個臨時密碼, 要記下來.

    安裝服務:mysqld.exe --install MySql5.7 --defaults-file=c:\mysql\mysql5.7\my.ini

    然后啟動服務. 
    然后再命令行:
    mysql -uroot -p
    輸入密碼,
    再輸入: 
    set password = password('root')
    改密碼成功, 然后就可以操作了.

    posted @ 2015-11-09 15:25 云自無心水自閑 閱讀(736) | 評論 (0)編輯 收藏

    如果只是在beforeSubmit()中 調用$('#fieldname').val(2)是不能成功修改表單的值的。
    因為此時ajaxForm已經把表單中所有的內容存儲在arr之中了。

        $('#form1').ajaxForm({
            beforeSubmit: function(arr){
                for ( var i = 0; i < arr.length; i ++ ) {
                    if ( arr[i].name == "fieldName1" ) {
                        arr[i].value = '新的值';
                    }
                }
            }
        });
    需要使用這種方式進行修改。

    posted @ 2015-11-02 19:13 云自無心水自閑 閱讀(1218) | 評論 (0)編輯 收藏

    今天在運行myeclipse的時候,突然報nullPointerException.

    具體的錯誤信息如下:

    Message: Errors running builder ‘DeploymentBuilder’ on project XXX’.
    Exception Stack Trace
    java.lang.NullPointerException

    解決方法:

    1. Shut down the workspace.

    2. Delete the file com.genuitec.eclipse.ast.deploy.core.prefs which is located at <workspace dir>/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.genuitec.eclipse.ast.deploy.core.prefs

    3. Start the IDE.

    posted @ 2015-10-21 09:21 云自無心水自閑 閱讀(364) | 評論 (0)編輯 收藏

     
    ipconfig /flushdns
    ipconfig /registerdns
    netsh winsock reset

    重新啟動電腦。

    posted @ 2015-10-13 16:31 云自無心水自閑 閱讀(1787) | 評論 (0)編輯 收藏

    今天下載了Apache James 3.0 Beta 5, 文件名:james-server-app-3.0.0-beta5-20150627.102412-1076-app.zip
    解壓,運行run.bat

    然后,注冊domain
    james-cli --host localhost adddomain example.com
    添加用戶
    james-cli.bat --host localhost adduser test@example.com password

    然后測試發送郵件,客戶端顯示發送成功,但是james服務器報錯,找不到MimeConfig的無參數構造函數。
    解決方法:
    使用舊的mime4j的jar包替換james 3.0 beta5中自帶的最新包。
    beta5中自帶的是0.8.0版,apache網站中可以下載到0.7.2
    下載apache-mime4j-0.7.2-bin.zip, 將其中的apache-mime4j-core-0.7.2.jar, apache-mime4j-dom-0.7.2.jar復制到james\lib目錄,
    并將其更名覆蓋原有的
    apache-mime4j-core-0.8.0-20150617.024907-738.jar
    apache-mime4j-dom-0.8.0-20150617.024927-735.jar
    重新啟動james, 發送郵件, 成功。

    posted @ 2015-10-08 08:45 云自無心水自閑 閱讀(3277) | 評論 (0)編輯 收藏

         摘要: 解壓/生成有密碼保護的壓縮文件, 研發過程中,作者研究了壓縮文件格式文檔: http://www.pkware.com/documents/casestudies/APPNOTE.TXT,并且參考了7-zip的實現。
      閱讀全文

    posted @ 2015-08-19 10:16 云自無心水自閑 閱讀(9954) | 評論 (0)編輯 收藏

         摘要: 花了兩天時間終于把windows10安裝好了,以下是我的一些個人的體會
      閱讀全文

    posted @ 2015-08-03 18:56 云自無心水自閑 閱讀(6251) | 評論 (0)編輯 收藏

    在JfinalConfig的繼承類中,
    configConstant() 需要設置me.setDevMode(true);

    1. 只有在DevMode下,才能禁止freeMarker的緩存。
    Configuration config = FreeMarkerRender.getConfiguration();
    config.setTemplateUpdateDelayMilliseconds(0);
    才會生效


    2. 這時才會有JFinal Action Report日志輸出

    posted @ 2015-07-24 19:58 云自無心水自閑 閱讀(416) | 評論 (0)編輯 收藏

    本文將簡單介紹如何使用PowerMock和Mockito來mock
    1. 構造函數
    2. 靜態函數
    3. 枚舉實現的單例
    4. 選擇參數值做為函數的返回值
    5. 在調用mock出來的方法中,改變方法參數的值

    一點簡要說明:Mockito其實已經可以滿足大部分的需求,但是它的實現機制是使用cglib來動態創建接口的類的實例。但是這種實現方式不能用于構造函數和靜態函數,因為那需要使用類的字節碼(比如使用javassist). 所以我們才需要結合使用PowerMock.

    1. mock構造函數, 如果有代碼沒有使用DI注入依賴實例,在單元測試中可以使用PowerMock來模擬創建對象。
    注意的開始兩行的2個注解 @RunWith 和 @PrepareForTest
    @RunWith比較簡單,后面始終是PowerMockRunner.class
    @PrepareForText后面需要加的是調用構造函數的類名,而不是有構造函數的類本身。
    在下面的例子中,我們要測試的類是:Helper, 在Helper類中調用了Somthing類的構造函數來創建實例。
    @RunWith(PowerMockRunner.class)
    @PrepareForTest(Helper.
    class)
    public class HelperTest {
      @Mock
      
    private Something mockSomething;
          
      @InjectMocks
      
    private Helper helper;
          
      @Test
      
    public void doSomething() throws Exception {
          String argument 
    = "arg";
              
          PowerMockito.whenNew(Something.
    class).withArguments(argument).thenReturn(mockSomething);
             
          // 調用需要測試方法
          helper.doSomething(argument);
             
          // 進行驗證
          verify(mockSomething).doIt();
      }
    }


    public class Helper {
      public void doSomething(String arg) {
          Something something = new Something(arg);
          something.doit();
      }
    }


    2,mock 靜態函數, 單例模式就是一個典型的會調用靜態函數的例子。 注意要點與mock構造函數相同。
    class ClassWithStatics {
      
    public static String getString() {
        
    return "String";
      }

      
    public static int getInt() {
        
    return 1;
      }
    }

    @RunWith(PowerMockRunner.
    class)
    @PrepareForTest(ClassWithStatics.
    class)
    public class StubJustOneStatic {
      @Test
      
    public void test() {
        PowerMockito.mockStatic(ClassWithStatics.
    class);

        when(ClassWithStatics.getString()).thenReturn(
    "Hello!");

        System.out.println(
    "String: " + ClassWithStatics.getString());
        System.out.println(
    "Int: " + ClassWithStatics.getInt());
      }
    }

    3。mock枚舉實現的單例
    SingletonObject.java
    public enum SingletonObject { 
        INSTANCE
    ;
        private
    int num;
        protected
    void setNum(int num) {
            this.num = num;
        }
        public int getNum() {
            return
    num;
        }

    }
    SingletonConsumer.java

    public class SingletonConsumer {
        public String consumeSingletonObject() { 
            return
    String.valueOf(SingletonObject.INSTANCE.getNum());
        }
    }
    SingletonConsumerTest.java
    @RunWith(PowerMockRunner.class) 
    @PrepareForTest({SingletonObject.class})
    public class SingletonConsumerTest {
        @Test public void testConsumeSingletonObject() throws Exception {
            SingletonObject
    mockInstance = mock(SingletonObject.class);
            Whitebox
    .setInternalState(SingletonObject.class, "INSTANCE", mockInstance);
            when
    (mockInstance.getNum()).thenReturn(42);
            assertEquals
    ("42", new SingletonConsumer().consumeSingletonObject());
        }
    }
    4。返回參數值做為函數返回值。
    mockito 1.9.5之后,提供一個方便的方法來實現這個需要,在這之前可以使用一個匿名函數來返回一個answer來實現。
    when(myMock.myFunction(anyString())).then(returnsFirstArg());
    其中returnsFirstArg()是org.mockito.AdditionalAnswers中的一個靜態方法。
    在這個類中還有其他的一些類似方法
    returnsSecondArg()
    returnsLastArg()
    ReturnsArgumentAt(int position)

    5. 在調用mock出來的方法中,改變方法參數的值
    when( myMock.someMethod( any( List.class ) ) ).thenAnswer( ( new Answer<Void>() {
        @Override
        
    public Void answer( InvocationOnMock invocation )
                
    throws Throwable {
            Object[] args 
    = invocation.getArguments();
            List arg1 
    = (List)args[0];
            arg1.add(
    "12345");
            
    return null;
        }
    } ) );



    Verifying with generic parameters
    verify(someService).process(Matchers.<Collection<Person>>any());
    verify(adunoMasterBaseProcessor).processBinFiles( anyListOf(File.class) );

    posted @ 2015-06-16 21:27 云自無心水自閑 閱讀(18458) | 評論 (0)編輯 收藏

    Oracle提供的JDK其實已經自帶一定程度的熱加載功能,但是如果你修改了類名,方法名,或者添加了新類,新方法的話。
    Tomcat都需要重新啟動來使得剛才的更改生效。
    而JRebel和springloaded都能有效地解決這個問題。其中springloaded是開源軟件,可以免費使用,尤其難得。
    其主頁:https://github.com/spring-projects/spring-loaded
    在官方頁面的簡單介紹中,作者只講述了如何在java程序中應用springloaded,而沒有說明如何在tomcat中進行配置。
    本文將簡要進行介紹。

    1,下載springloaded到本地目錄,比如:c:\temp\springloaded-1.2.3.RELEASE.jar

    2. 修改tomcat的應用,禁止tomcat自己的熱加載,方法是在META-INF目錄下創建context.xml文件,里面包含如下語句,關鍵便是其中設置reloadable為false
    <?xml version="1.0" encoding="UTF-8"?>
    <Context antiResourceLocking="false" privileged="true" useHttpOnly="true" reloadable="false" />

    3.在運行環境中添加springloaded的jar文件,在eclipse中右鍵點擊項目,run as->run configuration
    在彈出的窗口中,選擇Arguments標簽,在vm arguments的末尾添加:
    -javaagent:C:\temp\springloaded-1.2.3.RELEASE.jar -noverify
    點擊應用按鈕。

    以上便完成了所有的配置,步驟并不復雜。

    posted @ 2015-06-11 21:59 云自無心水自閑 閱讀(7714) | 評論 (0)編輯 收藏

    java wrapper是一個可以用于將java應用程序包裝成windows服務的工具。
    并且可以通過簡單的配置來允許使用visualVM進行監控。

    配置方法:
    在wrapper.conf中添加如下3行

    wrapper.java.additional.1=-Dcom.sun.management.jmxremote.port=9898 #這里的端口號可以自行選擇。
    wrapper.java.additional.2=-Dcom.sun.management.jmxremote.ssl=false
    wrapper.java.additional.3=-Dcom.sun.management.jmxremote.authenticate=false

    修改完畢保存后重新啟動服務。

    打開visualVM, 在菜單中選擇 file->Add JMX Connection。
    在彈出窗口中,connection一項中輸入: localhost:9898 即可。

    此配置對于jconsole也同樣有效。

    posted @ 2015-06-11 14:09 云自無心水自閑 閱讀(4817) | 評論 (0)編輯 收藏

    在一些歷史遺留代碼中,會用到java.util.logging. 如果在新的項目中引用了這些代碼,而又不希望去一個一個的修改原來的代碼。
    可以使用slf4j提供的類來轉接這部分的日志輸出。

    方法:
    1、類路徑中添加
        slf4j-api-1.7.10.jar
        jul-to-slf4j.1.7.10.jar ( 用于將java.util.logging的日志橋接到slf4j中)
        logback-core.1.1.2.jar
        logback-classic-1.1.2.jar

    2、在代碼中添加:
             // Optionally remove existing handlers attached to j.u.l root logger
             SLF4JBridgeHandler.removeHandlersForRootLogger();  // (since SLF4J 1.6.5)

             // add SLF4JBridgeHandler to j.u.l's root logger, should be done once during
             // the initialization phase of your application
             SLF4JBridgeHandler.install();

    注意事項:
    1、這個橋接可以會造成性能問題。
    和其他的橋接實現(比如:log4j, commons logging)不同,這個模塊并不真正的完全替代java.util.logging類,因為這個java.util.logging是java自帶的。
    所以只是把原來的日志對象進行了轉換,簡單的說,這個轉換過程是有開銷的。
    關鍵在于,不管日志語句有沒有根據日志級別被關閉,這個轉換無法避免。

    2、不能在類路徑中放入
    slf4j-jkd14.jar
    jul-toslf4j.jar

    posted @ 2015-04-27 15:31 云自無心水自閑 閱讀(1551) | 評論 (0)編輯 收藏

     1. Text Editor: Notepad++/Syncplify.me Notepad!
     2. Browser: Chrome/Firefox
     3. 文件管理: XYplorer Lite/Explorer++/Q-Dir
     4. Mind map: XMind Free
     5. Video player: PotPlayer
     6. Music player: Kugou
     7. Mysql client: HeidiSql
     8. PDF reader: Foxit Reader
     9. File/Folder synchronize : FreeFileSync
    10. MP3 tools: Audacity/MP3 Gain
    11. Zip: 7-zip
    12. Partition Management: EaseUS Partition Master Free / MiniTool Free Partition Manager 
    13. Data Recovery: EaseUS Data Recovery Wizard Free / MiniTool Free Data Recovery
    14. PDF Printer: PDF reDirect v2
    15. 個人信息管理: EssentialPIM Free Edition
    16. 遠程登錄: Terminals
    17. 文本比較合并: winmerge
    18. (s)FTP client: WinSCP
    19. 圖像處理: GIMP

    posted @ 2015-04-14 21:21 云自無心水自閑 閱讀(726) | 評論 (0)編輯 收藏

    Ember 是一個旨在創建大型web應用的JavaScript框架,它消除了樣板(boilerplate)并提供了標準的應用程序架構。

    Manning: Ember.js in action 第一章
    Manning: Ember.js in action 第五章

    posted @ 2015-03-23 12:37 云自無心水自閑 閱讀(3707) | 評論 (1)編輯 收藏

    先給一個例子:
    $http. get('/remote/item' ). then(function(response) {
    console.log('成功。');
    }, function(errResponse) {
    console. error('出錯.' );
    });

    一。介紹Promise
    在這個例子中,$http.get()函數返回了一個Promise對象, 有了這個對象,我們才能很方便地直接在后面添加then函數的定義。
    Promise對象在AngularJS中是一個非常重要的存在。它提供了強大的功能和便利性。

    1。異步性
    從定義的語法上看,操作似乎是同步的,但是Promise的工作其實是異步的,只有在服務端返回數據后,后續的函數才會被調用。這是一個事件驅動,非阻塞式的框架。

    2。它避免了其它框架的嵌套回調函數的缺點。
    -所有異步任務都會返回一個Promise對象
    -每個Promise對象都有一個then函數,then函數有兩個參數,分別是成功處理函數和失敗處理函數
    -失敗處理函數和成功處理函數都只會在異步處理完成后被調用一次
    -then函數也會返回Promise對象,這樣,我們可以把多個函數串連起來成為一個函數鏈
    -成功處理函數和失敗處理函數的返回值可以被傳遞到函數鏈下一個的函數中
    -如果在成功(或者失敗)處理函數中,又開始了一個異步調用,那么函數鏈中的函數將會在這個異步調用結束后才開始

    二。異步鏈式調用的后續處理
    假如我們定義了如下的函數鏈:
    $http.get('/item').then(s1, e1).then(s2, e2).then(s3, e3);
    我們如何自主的根據函數鏈中每個函數的運行結果,決定觸發后續函數的成功處理函數或者失敗處理函數呢?
    比如說,在s1處理過程中,發生問題,于是我們觸發了e2, 但是在e2處理完后,我們又想觸發s3.
    AnguarJS提供了$q來滿足這樣的需求。
    如果我們想觸發函數鏈中下一個函數的成功處理,我們只需要最后給出一個返回值,有了返回值,AngularJS會認為函數執行正確,自動調用下一個函數中的成功處理
    如果想觸發失敗處理,那么可以簡單地返回$q.reject(data),這樣就會觸發下一個函數的失敗處理

    posted @ 2015-02-27 18:39 云自無心水自閑 閱讀(2615) | 評論 (1)編輯 收藏



    在前文(http://www.tkk7.com/usherlight/archive/2015/02/01/422633.html)中我們曾經介紹過,定義controller時,需要2個參數,第一個參數是controller的名稱,第二個參數是一個數組,數組的最后一個元素將是controller的函數,前面的參數是controller的依賴項。我們現在就來仔細分析一下其中的具體過程。

    先給一個例子:
    angular. module('notesApp' , [])
     . controller('MainCtrl' , ['$log' , function($log) {
     var self = this;
     self. logStuff = function() {
     $log. log('The button was pressed' );
     };
     }])

    在這個例子中可以看到,我們在第一個參數中用字符串(服務名稱)添加了一個依賴項。當我們通過字符串聲明了這一個服務之后,我們就可以把它當作一個變量注入到函數中。AngularJS會自動查找字符串名稱對應的服務名,按照順序將其注入到函數中。
    myModule.controller("MainCtrl",  ["$log", "$window", function($l, $w) {}]);
    在這個例子中,$log, $windows是AngularJS自帶的兩個服務,在數組中通過名稱聲明后,會被注入到函數的兩個參數中。
    比較常用的AngularJS自帶的服務有:$window, $location, $http等

    從上面的例子中可以看出,AngularJS的設計思想就是不要在函數中自己去實例化或者通過其它途徑來獲取服務的實例,而是聲明需要的對象,由AngularJS來注入具體的實例。

    創建自己的服務
    什么時候應該創建服務,而不是controller呢?
    1。 需要重用的時候
    2。需要保留應用級的狀態。這是非常重要的一點,controller是會不斷地被創建和銷毀的,如果需要保存應用級的狀態,就需要使用service
    3。和頁面顯示無關
    4。需要和第三方服務整合
    5。緩存

    服務是會被延遲加載的,也就是說只有在第一次被引用的時候,才會被創建。
    服務將會被定義一次,也只會被實例化一次。

    posted @ 2015-02-09 19:28 云自無心水自閑 閱讀(7281) | 評論 (0)編輯 收藏

    主站蜘蛛池模板: 亚洲一区免费视频| 久草免费福利在线| 看一级毛片免费观看视频| 中文在线观看国语高清免费| 国产成人午夜精品免费视频| 亚洲综合熟女久久久30p| 亚洲精品伊人久久久久| 青柠影视在线观看免费高清| 国产又大又黑又粗免费视频| 亚洲人成网站色在线入口 | 免费观看理论片毛片| 亚洲va在线va天堂va四虎| 免费福利在线观看| 最近中文字幕免费mv视频7| 亚洲精品美女久久久久99| 免费无码国产V片在线观看| 亚洲性日韩精品一区二区三区| 国产无限免费观看黄网站| 亚洲大尺度无码专区尤物| 白白色免费在线视频| 国产亚洲成人在线播放va| 亚洲av综合日韩| 四虎免费在线观看| 亚洲AV无码国产精品色| 好吊妞在线成人免费| 无码毛片一区二区三区视频免费播放| 午夜高清免费在线观看| 免费精品视频在线| 亚洲av色福利天堂| 毛片免费观看视频| 一级毛片大全免费播放| 亚洲中文无韩国r级电影| 十八禁无码免费网站| 亚洲成色999久久网站| 成年女人毛片免费观看97| 日本激情猛烈在线看免费观看| 亚洲Av无码精品色午夜 | 亚洲乱码一区二区三区国产精品| 最近中文字幕高清免费中文字幕mv| 亚洲VA中文字幕不卡无码| 亚洲成aⅴ人片在线观|