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

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

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

    http://webtide.intalio.com/2012/10/jetty-9-updated-websocket-api/

    Creating WebSockets in Jetty is even easier with Jetty 9!

    While the networking gurus in Jetty have been working on the awesome improvements to the I/O layers in core Jetty 9, the WebSocket fanatics in the community have been working on making writing WebSockets even easier.

    The initial WebSocket implementation in Jetty was started back in November of 2009, well before the WebSocket protocol was finalized.

    It has grown in response to Jetty’s involvement with the WebSocket draft discussions to the finalization of RFC6455, and onwards into the changes being influenced on our design as a result of WebSocket extensions drafts such as x-webkit-perframe-deflatepermessage-deflate, fragment, andongoing mux discussions.

    The Jetty 7.x and Jetty 8.x codebases provided WebSockets to developers required a complex set of knowledge about how WebSockets work and how Jetty implemented WebSockets.  This complexity was as a result of this rather organic growth of WebSocket knowledge around intermediaries and WebSocket Extensions impacted the original design.

    With Jetty 9.x we were given an opportunity to correct our mistakes.

    The new WebSockets API in Jetty 9.x

    Note: this information represents what is in the jetty-9 branch on git, which has changed in small but important ways since 9.0.0.M0 was released.

    With the growing interest in next generation protocols like SPDY and HTTP/2.0, along with evolving standards being tracked for Servlet API 3.1 and Java API for WebSockets (JSR-356), the time Jetty 9.x was at hand.  We dove head first into cleaning up the codebase, performing some needed refactoring, and upgrading the codebase to Java 7.

    Along the way, Jetty 9.x started to shed the old blocking I/O layers, and all of the nasty logic surrounding it, resulting on a Async I/O focused Jetty core.  We love this new layer, and we expect you will to, even if you don’t see it directly.  This change benefits Jetty with a smaller / cleaner / easier to maintain and test codebase, along with various performance improvements such as speed, CPU use, and even less memory use.

    In parallel, the Jetty WebSocket codebase changed to soak up the knowledge gained in our early adoption of WebSockets and also to utilize the benefits of the new Jetty Async I/O layers better.   It is important to note that Jetty 9.x WebSockets is NOT backward compatible with prior Jetty versions.

    The most significant changes:

    • Requires Java 7
    • Only supporting WebSocket version 13 (RFC-6455)
    • Artifact Split

    The monolithic jetty-websocket artifact has been to split up the various websocket artifacts so that developers can pick and choose what’s important to them.

    The new artifacts are all under the org.eclipse.jetty.websocket groupId on maven central.

    • websocket-core.jar – where the basic API classes reside, plus internal implementation details that are common between server & client.
    • websocket-server.jar – the server specific classes
    • websocket-client.jar – the client specific classes
    • Only 1 Listener now (WebSocketListener)
    • Now Supports Annotated WebSocket classes
    • Focus is on Messages not Frames

    In our prior WebSocket API we assumed, incorrectly, that developers would want to work with the raw WebSocket framing.   This change brings us in line with how every other WebSocket API behaves, working with messages, not frames.

    • WebSocketServlet only configures for a WebSocketCreator

    This subtle change means that the Servlet no longer creates websockets of its own, and instead this work is done by the WebSocketCreator of your choice (don’t worry, there is a default creator).
    This is important to properly support the mux extensions and future Java API for WebSockets (JSR-356)

    Jetty 9.x WebSockets Quick Start:

    Before we get started, some important WebSocket Basics & Gotchas

    1. A WebSocket Frame is the most fundamental part of the protocol, however it is not really the best way to read/write to websockets.
    2. A WebSocket Message can be 1 or more frames, this is the model of interaction with a WebSocket in Jetty 9.x
    3. A WebSocket TEXT Message can only ever be UTF-8 encoded. (it you need other forms of encoding, use a BINARY Message)
    4. A WebSocket BINARY Message can be anything that will fit in a byte array.
    5. Use the WebSocketPolicy (available in the WebSocketServerFactory) to configure some constraints on what the maximum text and binary message size should be for your socket (to prevent clients from sending massive messages or frames)

    First, we need the servlet to provide the glue.

    We’ll be overriding the configure(WebSocketServerFactory) here to configure a basic MyEchoSocket to run when an incoming request to upgrade occurs.

    package examples;  import org.eclipse.jetty.websocket.server.WebSocketServerFactory; import org.eclipse.jetty.websocket.server.WebSocketServlet;  public class MyEchoServlet extends WebSocketServlet {     @Override     public void configure(WebSocketServerFactory factory)     {         // register a socket class as default         factory.register(MyEchoSocket.class);     } }

    The responsibility of your WebSocketServlet class is to configure theWebSocketServerFactory.     The most important aspect is describing how WebSocket implementations are to be created when request for new sockets arrive.  This is accomplished by configuring an appropriate WebSocketCreator object.  In the above example, the default WebSocketCreator is being used to register a specific class to instantiate on each new incoming Upgrade request.

    If you wish to use your own WebSocketCreator implementation, you can provide it during this configure step.

    Check the examples/echo to see how this is done with factory.setCreator() andEchoCreator.

    Note that request for new websockets can arrive from a number of different code paths, not all of which will result in your WebSocketServlet being executed.  Mux for example will result in a new WebSocket request arriving as a logic channel within the MuxExtension itself.

    As for implementing the MyEchoSocket, you have 3 choices.

    1. Implementing Listener
    2. Using an Adapter
    3. Using Annotations

    Choice 1: implementing WebSocketListener interface.

    Implementing WebSocketListener is the oldest and most fundamental approach available to you for working with WebSocket in a traditional listener approach (be sure you read the other approaches below before you settle on this approach).
    It is your responsibility to handle the connection open/close events appropriately when using the WebSocketListener. Once you obtain a reference to the WebSocketConnection, you have a variety of NIO/Async based write() methods to write content back out the connection.

    package examples;  import java.io.IOException;  import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.websocket.core.api.WebSocketConnection; import org.eclipse.jetty.websocket.core.api.WebSocketException; import org.eclipse.jetty.websocket.core.api.WebSocketListener;  public class MyEchoSocket implements WebSocketListener {     private WebSocketConnection outbound;      @Override     public void onWebSocketBinary(byte[] payload, int offset,                                   int len)     {         /* only interested in text messages */     }      @Override     public void onWebSocketClose(int statusCode, String reason)     {         this.outbound = null;     }      @Override     public void onWebSocketConnect(WebSocketConnection connection)     {         this.outbound = connection;     }      @Override     public void onWebSocketException(WebSocketException error)     {         error.printStackTrace();     }      @Override     public void onWebSocketText(String message)     {         if (outbound == null)         {             return;         }          try         {             String context = null;             Callback callback = new FutureCallback<>();             outbound.write(context,callback,message);         }         catch (IOException e)         {             e.printStackTrace();         }     } }

    Choice 2: extending from WebSocketAdapter

    Using the provided WebSocketAdapter, the management of the Connection is handled for you, and access to a simplified WebSocketBlockingConnection is also available (as well as using the NIO based write signature seen above)

    package examples;  import java.io.IOException; import org.eclipse.jetty.websocket.core.api.WebSocketAdapter;  public class MyEchoSocket extends WebSocketAdapter {     @Override     public void onWebSocketText(String message)     {         if (isNotConnected())         {             return;         }          try         {             // echo the data back             getBlockingConnection().write(message);         }         catch (IOException e)         {             e.printStackTrace();         }     } }

    Choice 3: decorating your POJO with @WebSocket annotations.

    This the easiest WebSocket you can create, and you have some flexibility in the parameters of the methods as well.

    package examples;  import java.io.IOException;  import org.eclipse.jetty.util.FutureCallback; import org.eclipse.jetty.websocket.core.annotations.OnWebSocketMessage; import org.eclipse.jetty.websocket.core.annotations.WebSocket; import org.eclipse.jetty.websocket.core.api.WebSocketConnection;  @WebSocket(maxTextSize = 64 * 1024) public class MyEchoSocket {     @OnWebSocketMessage     public void onText(WebSocketConnection conn, String message)     {         if (conn.isOpen())         {             return;         }         try         {             conn.write(null,new FutureCallback(),message);         }         catch (IOException e)         {             e.printStackTrace();         }     } }

    The annotations you have available:
    @OnWebSocketMessage: To receive websocket message events.

    Examples:

      @OnWebSocketMessage   public void onTextMethod(String message) {      // simple TEXT message received   }    @OnWebSocketMessage   public void onTextMethod(WebSocketConnection connection,                             String message) {      // simple TEXT message received, with Connection       // that it occurred on.   }    @OnWebSocketMessage   public void onBinaryMethod(byte data[], int offset,                               int length) {      // simple BINARY message received   }    @OnWebSocketMessage   public void onBinaryMethod(WebSocketConnection connection,                               byte data[], int offset,                               int length) {      // simple BINARY message received, with Connection       // that it occurred on.   }

    @OnWebSocketConnect: To receive websocket connection connected event (will only occur once).

    Example:

      @OnWebSocketConnect   public void onConnect(WebSocketConnection connection) {      // WebSocket is now connected   }

    @OnWebSocketClose: To receive websocket connection closed events (will only occur once).

    Example:

      @OnWebSocketClose   public void onClose(int statusCode, String reason) {      // WebSocket is now disconnected   }    @OnWebSocketClose   public void onClose(WebSocketConnection connection,                        int statusCode, String reason) {      // WebSocket is now disconnected   }

    @OnWebSocketFrame: To receive websocket framing events (read only access to the rawFrame details).

    Example:

      @OnWebSocketFrame   public void onFrame(Frame frame) {      // WebSocket frame received   }    @OnWebSocketFrame   public void onFrame(WebSocketConnection connection,                        Frame frame) {      // WebSocket frame received   }

    One More Thing … The Future

    We aren’t done with our changes to Jetty 9.x and the WebSocket API, we are actively working on the following features as well…

    • Mux Extension

    The multiplex extension being drafted will allow for multiple virtual WebSocket connections over a single physical TCP/IP connection.  This extension will allow browsers to better utilize their connection limits/counts, and allow web proxy intermediaries to bundle multiple websocket connections to a server together over a single physical connection.

    • Streaming APIs

    There has been some expressed interest in providing read and write of text or binary messages using the standard Java IO Writer/Reader (for TEXT messages) and OutputStream/InputStream (for BINARY messages) APIs.

    Current plans for streamed reading includes new @OnWebSocketMessage interface patterns.

      // In the near future, we will have the following some Streaming   // forms also available.  This is a delicate thing to    // implement and currently does not work properly, but is    // scheduled.    @OnWebSocketMessage   public void onTextMethod(Reader stream) {      // TEXT message received, and reported to your socket as a      // Reader. (can handle 1 message, regardless of size or       // number of frames)   }    @OnWebSocketMessage   public void onTextMethod(WebSocketConnection connection,                             Reader stream) {      // TEXT message received, and reported to your socket as a      // Reader. (can handle 1 message, regardless of size or       // number of frames).  Connection that message occurs      // on is reported as well.   }    @OnWebSocketMessage   public void onBinaryMethod(InputStream stream) {      // BINARY message received, and reported to your socket      // as a InputStream. (can handle 1 message, regardless      // of size or number of frames).   }    @OnWebSocketMessage   public void onBinaryMethod(WebSocketConnection connection,                               InputStream stream) {      // BINARY message received, and reported to your socket      // as a InputStream. (can handle 1 message, regardless      // of size or number of frames).  Connection that       // message occurs on is reported as well.   }

    And for streaming writes, we plan to provide Writer and OutputStream implementations that simply wrap the provided WebSocketConnection.

    • Android Compatible Client Library

    While Android is currently not Java 7 compatible, a modified websocket-client library suitable for use with Android is on our TODO list.

    • Support Java API for WebSocket API (JSR356)

    We are actively tracking the work being done with this JSR group, it is coming, but is still some way off from being a complete and finished API (heck, the current EDR still doesn’t support extensions). Jetty 9.x will definitely support it, and we have tried to build our Jetty 9.x WebSocket API so that the the Java API for WebSockets can live above it.

    posted @ 2014-06-10 11:55 小馬歌 閱讀(873) | 評論 (0)編輯 收藏
     

    from:http://blog.csdn.net/marshalchen/article/details/12401597

    Go語言的hello world!代碼:

    1. package main  
    2.   
    3. import "fmt"  
    4.   
    5. func main() {  
    6.     fmt.Println("Hello, 世界")  
    7. }  


    接下來為大家帶來,Go開發環境的安裝。

      首先是安裝Go,這里有很詳細的安裝說明,http://code.google.com/p/golang-china/wiki/Install 或者http://golang.org/doc/install

    下面我們在window下面安裝,google有提供win安裝包,對于新手還是非常簡單的!

    https://code.google.com/p/go/downloads/list

    直接下一步.......安裝非常簡單!

      安裝好Go以后,我們就可以搭建開發環境了,這里我用的是 Sublime Text 2 + GoSublime + gocode。對于不了解Sublime Text 2的朋友,可以看看官網:http://www.sublimetext.com/(總的來說是一個輕量級,用起來很方便的工具)

    1. 下載 Sublime Text 2,地址如下:http://www.sublimetext.com/

    2. 解壓以后,雙擊 sublime_text,就可以使用 Sublime Text 2 了。

    3. 安裝 Package Control,在打開 Sublime Text 2以后,按下快捷鍵 Ctrl + `,打開命令窗行,這個按鍵在Tab鍵的上面,我剛開始還沒找到,呵呵。輸入以下內容,并回車:

      import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'

    4. 重啟Sublime Text 2后,就可以發現在 Preferences菜單下,多出一個菜單項 Package Control。

    5.現在安裝GoSublime插件了,按住Ctrl+Shilft+p會彈出一個對話框


    輸入install回車彈出一個安裝包的對話框


    如入GoSublime選擇GoSublime回車

    輸入Go build選中回車(這個屬于可選)

    搞定,GoSublime安裝成功。

    6.下面安裝gocode,

    打開控制臺,輸入以下內容:

        go get github.com/nsf/gocode

        go install github.com/nsf/gocode

    也可以去github下載https://github.com/nsf/gocode.git(要安裝google的git版本管理工具)

      安裝完成后,我們可以在 go/bin 目錄下,發現多出了個 gocode 文件。(一定要放在bin目錄下)

    7. 修改GoSublime配置:在 Preferences菜單下,找到Package Settings,然后找到 GoSublime,再往下找到 Settings - Default。再打開的文件中,添加如下配置,并保存:


    好了,到目前為止,開發環境搭建完成。

    打開 Sublime Text 2,新建 helloworld.go,編寫代碼如下:

    見證Go代碼自動提示的時刻了

    輸入一個p


    回車(enter鍵)


    main方法,包自動給你生成了。

    下面是一個打印的例子:




    按下快捷鍵 Ctrl + b 界面下方會出現如下界面:



    輸入 go build hello.go


    運行,同樣 按下快捷鍵 Ctrl + b 界面下方會出現如下界面,輸入 hello回車 。如圖:


    好了,到現在,開發環境就搭建完畢了,希望大家也來學習Go這門語言。


    新手入門參考:

    新手入門api是我見過的最好的新手入門文檔,希望go能發揚光大。


    上述內容轉載http://blog.csdn.net/love_se/article/details/7754274 



    但是linux下需要再變通的配置了

    環境變量部分:

    修改/etc/profile或者.bashrc或者.bash_profile


    如同JDK般加入

    export JAVA_HOME=/usr/lib/jvm/java-7-sun  

    export JRE_HOME=${JAVA_HOME}/jre  
    export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib  
    export PATH=${JAVA_HOME}/bin:$PATH 

    posted @ 2014-05-20 16:45 小馬歌 閱讀(261) | 評論 (0)編輯 收藏
     
         摘要: It is a well known fact that HTTP(Hypertext Transfer Protocol) is a stateless request-response protocol. This simple design of the HTTP protocol makes it very scalable but inefficient and un...  閱讀全文
    posted @ 2014-05-19 13:38 小馬歌 閱讀(234) | 評論 (0)編輯 收藏
     
    * Java-WebSocket 
    http://java-websocket.org/
    "A barebones WebSocket client and server implementation written in 100% Java"
    * jWebSocket  
    http://jwebsocket.org/
    "jWebSocket is a pure Java/JavaScript high speed bidirectional communication solution for the Web  server and various clients"
    * Grizzly 
    http://grizzly.java.net/
    Framework for building web servers of various scales and types incl Web Socket client & server apis.
    * Apache Tomcat 7
    Java Web Container
    http://tomcat.apache.org/download-70.cgi
    new api & sup[port in 7.0.7: http://tomcat.apache.org/tomcat-7.0-doc/api/index.html?org/apache/catalina/websocket/package-summary.html
    * Glassfish
    http://glassfish.java.net/
    WebSockets via Grizzly and latterly WebSocket SDK also.
    * Autobahn  
    http://autobahn.ws/developers
    Including Android web socket client
    * WeberKnecht
    http://code.google.com/p/weberknecht/ 
    Project with Java SE / Android clients
    * Jetty
    http://www.eclipse.org/jetty/
    Java Web Container including WebSockets support, client and server apis.
    JBoss
    Java EE App server
    https://github.com/mikebrock/jboss-websockets
    (in development)
    * Caucho Resin
    Java Server including web container with WebSockets support. 
    see for example: http://www.caucho.com/resin-4.0/examples/websocket-java/index.xtp
    * Kaazing WebSocket Gateway
    Gateway products, includes Java developer APIs for web sockets.
    e.g. http://tech.kaazing.com/documentation/html5/3.3/o_dev_java.html
    * WebSocket SDK
    Prototyping high level APIs & annotations for Web Sockets.
    http://java.net/projects/websocket-sdk
    * Webbit http://webbitserver.org/
    A Java event based WebSocket and HTTP server
    http://groups.google.com/group/webbit  / http://webbitserver.org/
    * Servlet 3.1
    Proposing API for server side of Http Upgrade mechanism to enable websockets support to be build on the Servlet Container
    e.g.: http://java.net/projects/servlet-spec/lists/jsr340-experts/archive/2012-02/message/8
    *Atmosphere:
    "The only Portable WebSocket/Comet Framework supporting Scala, Groovy and Java"
    https://github.com/Atmosphere/atmosphere
    *websockets4j:
    "Websockets4j Is a simple implementation of the WebSockets protocol. Currently supports the plain text version of Drafts 75 and 76 of the protocol."
    http://code.google.com/p/websockets4j/
    *GNU WebSocket4J:
    "GNU WebSocket4J is a WebSocket protocol implementation in Java. It allows you to build Web applications that interact with applications running in a JVM. GNU WebSocket4J implements both server and client side of the protocol, so it can be used to build both WebSocket servers and clients."
    http://maarons.alwaysdata.net/software/GNU/WebSocket4J/
    * Netty
    Asynchronous event-driven network application framework, including websockets amongst many other things.
     http://netty.io/ / http://netty.io/docs/stable/api/
    TorqueBox
    Ruby application server built on JBoss AS7 and JRuby.
    http://torquebox.org/documentation/
    http://torquebox.org/news/2011/08/15/websockets-stomp-and-torquebox/
    posted @ 2014-05-19 13:20 小馬歌 閱讀(294) | 評論 (0)編輯 收藏
     
         摘要: from:http://www.oracle.com/technetwork/articles/java/jsr356-1937161.htmlJSR 356, Java API for WebSocketby Johan VosLearn how to integrate WebSockets into your applications.Published April 2013For many...  閱讀全文
    posted @ 2014-05-19 13:18 小馬歌 閱讀(540) | 評論 (0)編輯 收藏
     
         摘要: Profiles是maven的一個很關鍵的術語:profile是用來定義一些在build lifecycle中使用的environmental variations,profile可以設置成在不同的環境下激活不同的profile(例如:不同的OS激活不同的profile,不同的JVM激活不同的profile,不同的dabase激活不同的profile等等)。 定義Profiles&nbs...  閱讀全文
    posted @ 2014-05-16 12:55 小馬歌 閱讀(263) | 評論 (0)編輯 收藏
     
         摘要: 概述繼 Spring 2.0 對 Spring MVC 進行重大升級后,Spring 2.5 又為 Spring MVC 引入了注解驅動功能?,F在你無須讓 Controller 繼承任何接口,無需在 XML 配置文件中定義請求和 Controller 的映射關系,僅僅使用注解就可以讓一個 POJO 具有 Controller 的絕大部分功能 —— Spring MVC 框架...  閱讀全文
    posted @ 2014-05-14 17:06 小馬歌 閱讀(287) | 評論 (0)編輯 收藏
     

    如果要使插件開發應用能有更好的國際化支持,能夠最大程度的支持中文輸出,則最好使 Java文件使用UTF-8編碼。然而,Eclipse工作空間(workspace)的缺省字符編碼是操作系統缺省的編碼,簡體中文操作系統 (Windows XP、Windows 2000簡體中文)的缺省編碼是GB18030,在此工作空間中建立的工程編碼是GB18030,工程中建立的java文件也是GB18030。

    如果要使新建立工程、java文件直接使UTF-8則需要做以下工作: 

    1、windows->Preferences...打開"首選項"對話框,左側導航樹,導航到general->Workspace,右側Text file encoding,選擇Other,改變為UTF-8,以后新建立工程其屬性對話框中的Text file encoding即為UTF-8。 

    2、windows->Preferences...打開"首選項"對話框,左側導航樹,導航到general->Content Types,右側Context Types樹,點開Text中每一個子項,并將其編碼設置為"UTF-8",點update!

     其他java應用開發相關的文件如:properties、XML等已經由Eclipse缺省指定,分別為ISO8859-1,UTF-8,如開發中確需改變編碼格式則可以在此指定。 

    3、window-->preference-->MyEclipse-->Files and Editors,將每個子項的"Encoding"改為"ISO 10645/Unicode(UTF-8)",點Apply! 

    4、經過上述三步,新建java文件即為UTF-8編碼,Eclipse編譯、運行、調試都沒問題,但是做RCP應用的Product輸出時、或者插件輸出時,則總是出錯,要么不能編譯通過(輸出時要重新compile)、要么輸出的插件運行時中文顯示亂碼。此時需要再RCP應用、或插件Plugin工程的build.properties中增加一行,javacDefaultEncoding.. = UTF-8。讓輸出時編譯知道java源文件時UTF-8編碼。這個設置需要保證所有的java源文件時UTF-8編碼格式,如果不全是,可以參考 Eclipse幫中(Plug-in Development Environment Guide > Reference > Feature and Plug-in Build configuration),建議全部java源文件是UTF-8編碼。 

    如果插件開發、RCP應用開發原來基于其他編碼,如GB18030,想轉換為UTF-8,則首先,做以上工作;然后通過查找編碼轉換工具,如基于 iconv的批量轉換工具,將原編碼轉換

    posted @ 2014-05-13 21:07 小馬歌 閱讀(25742) | 評論 (0)編輯 收藏
     
    1. <build>  
    2.         <sourceDirectory>src/main/java</sourceDirectory>  
    3.         <plugins>  
    4.             <plugin>  
    5.                 <groupId>org.apache.maven.plugins</groupId>  
    6.                 <artifactId>maven-compiler-plugin</artifactId>  
    7.                 <configuration>  
    8.                     <defaultLibBundleDir>lib</defaultLibBundleDir>  
    9.                     <source>1.5</source>  
    10.                     <target>1.5</target>  
    11.                     <encoding>UTF-8</encoding>  
    12.                 </configuration>  
    13.             </plugin>  
    14.             <plugin>  
    15.                 <groupId>org.apache.maven.plugins</groupId>  
    16.                 <artifactId>maven-jar-plugin</artifactId>  
    17.                 <configuration>  
    18.                     <archive>  
    19.                         <manifest>  
    20.                             <addClasspath>true</addClasspath>  
    21.                             <classpathPrefix></classpathPrefix>  
    22.                             <mainClass>com.xx.xx.xx</mainClass>  
    23.                         </manifest>  
    24.                     </archive>  
    25.                 </configuration>  
    26.             </plugin>  
    27.             <plugin>  
    28.                 <groupId>org.apache.maven.plugins</groupId>  
    29.                 <artifactId>maven-dependency-plugin</artifactId>  
    30.                 <executions>  
    31.                     <execution>  
    32.                         <id>copy</id>  
    33.                         <phase>install</phase>  
    34.                         <goals>  
    35.                             <goal>copy-dependencies</goal>  
    36.                         </goals>  
    37.                         <configuration>  
    38.                             <outputDirectory>  
    39.                                 ${project.build.directory}  
    40.                             </outputDirectory>  
    41.                         </configuration>  
    42.                     </execution>  
    43.                 </executions>  
    44.             </plugin>  
    45.             <plugin>  
    46.                 <groupId>org.apache.maven.plugins</groupId>  
    47.                 <artifactId>maven-resources-plugin</artifactId>  
    48.                 <version>2.2</version>  
    49.                 <configuration>  
    50.                     <encoding>UTF-8</encoding>  
    51.                 </configuration>  
    52.             </plugin>  
    53.         </plugins>  
    54.     </build>  
    posted @ 2014-05-13 17:36 小馬歌 閱讀(344) | 評論 (0)編輯 收藏
     

    參考官方網站:http://maven.apache.org/plugins/maven-assembly-plugin/usage.html

    方法一:將pom.xml引入的jar包打到zip文件夾中

      1、pom.xml的配置

    <!-- 打包配置 start --> 	<build> 		<plugins> 			<plugin> 				<!-- NOTE: We don't need a groupId specification because the group is  					org.apache.maven.plugins ...which is assumed by default. --> 				<artifactId>maven-assembly-plugin</artifactId> 				<version>2.4</version> 				<configuration> 					<descriptors> 						<descriptor>src/main/assembly/src.xml</descriptor> 					</descriptors> 					<descriptorRefs> 						<descriptorRef>jar-with-dependencies</descriptorRef> 					</descriptorRefs> 				</configuration> 				<executions> 					<execution> 						<id>make-assembly</id> <!-- this is used for inheritance merges --> 						<phase>package</phase> <!-- bind to the packaging phase --> 						<goals> 							<goal>single</goal> 						</goals> 					</execution> 				</executions> 			</plugin> 		</plugins> 	</build> 

      2、src.xml文件內容

    <assembly xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/assembly-1.0.0.xsd">     <id>package</id>     <formats>         <format>zip</format>     </formats>     <includeBaseDirectory>true</includeBaseDirectory>     <fileSets>         <fileSet>             <directory>src/main/bin</directory>             <outputDirectory>/</outputDirectory>         </fileSet>         <fileSet>             <directory>src/main/config</directory>             <outputDirectory>config</outputDirectory>         </fileSet>     </fileSets>     <dependencySets>         <dependencySet>             <outputDirectory>lib</outputDirectory>             <scope>runtime</scope>         </dependencySet>     </dependencySets> </assembly> 

      方法1能把所有引入的包打成jar包,方便自己保存和引入。

      3、最后一步

      cmd進入在項目根目錄下,鍵入“mvn package”,OK完事!

    方法二:將pom引入的jar包打進你的項目工程jar包內

      1、pom.xml的配置

    <!-- 打包配置 start --> 	<build> 		<!-- <finalName>im-dal-service</finalName> 		<sourceDirectory>src/main/java</sourceDirectory> 		<resources> 			控制資源文件的拷貝 			<resource> 				<directory>src/main/resources</directory> 				<targetPath>${project.build.directory}</targetPath> 			</resource> 		</resources> --> 		<plugins> 			<plugin> 				<artifactId>maven-assembly-plugin</artifactId> 				<configuration> 					<descriptors> 						<descriptor>src/main/assembly/src.xml</descriptor> 					</descriptors> 				</configuration> 			</plugin> 		</plugins>  	</build> 

      2、src.xml

    <?xml version="1.0" encoding="UTF-8"?> <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">   <id>jar-with-dependencies</id>   <formats>     <format>jar</format>   </formats>   <includeBaseDirectory>false</includeBaseDirectory>   <dependencySets>     <dependencySet>       <unpack>false</unpack>       <scope>runtime</scope>     </dependencySet>   </dependencySets>   <fileSets>     <fileSet>       <directory>/lib</directory>     </fileSet>   </fileSets> </assembly> 

      3、最后一步

      cmd進入在項目根目錄下,鍵入“mvn assembly:assembly”,OK完事!

    分享到:
    posted @ 2014-05-13 17:35 小馬歌 閱讀(895) | 評論 (0)編輯 收藏
    僅列出標題
    共95頁: First 上一頁 19 20 21 22 23 24 25 26 27 下一頁 Last 
     
    主站蜘蛛池模板: 亚洲三级在线免费观看| 亚洲v高清理论电影| 99久久99这里只有免费费精品| 一级毛片无遮挡免费全部| 亚洲国产精品无码观看久久| 亚洲黄色在线播放| 亚洲AV无码久久精品狠狠爱浪潮| 亚洲精品国产福利一二区| 毛片网站免费在线观看| 猫咪免费人成网站在线观看| 光棍天堂免费手机观看在线观看| 免费人成视频在线播放| 色天使色婷婷在线影院亚洲| 亚洲中文字幕久久精品蜜桃| 亚洲人成电影在线观看青青| 亚洲精品成人av在线| 亚洲国产精品一区二区第一页| 亚洲日韩在线观看免费视频| 亚洲AⅤ优女AV综合久久久| 日韩精品视频免费网址| 天天看免费高清影视| 操美女视频免费网站| 18禁超污无遮挡无码免费网站国产| 99在线精品视频观看免费| 亚洲视频在线免费播放| 37pao成人国产永久免费视频 | 免费无码又爽又刺激毛片| 久久精品网站免费观看| 国产a视频精品免费观看| 蜜桃成人无码区免费视频网站| 色欲国产麻豆一精品一AV一免费 | 亚洲真人无码永久在线| 国产亚洲一区二区三区在线不卡 | 在线毛片片免费观看| 国产色爽免费无码视频| 在线毛片片免费观看| 真实国产乱子伦精品免费| 蜜桃AV无码免费看永久| 无码日韩人妻av一区免费| 欧洲美熟女乱又伦免费视频| 国产大片免费观看中文字幕|