Ye's profileYe Huang 黄晔空间PhotosBlogListsMore Tools Help

Blog


    May 27

    maven2安装包和源码包的指令

    (Source: http://www.blogjava.net/itvincent/archive/2008/04/07/133382.html)

    mvn install:install-file -DgroupId=itvincent.package -DartifactId=example -DgeneratePom=true -Dversion=1.0.0 -Dpackaging=jar -Dfile=/path/to/your/directory/example-1.0.1.jar

    以上命令是把一个名example-1.0.1.jar的包,放在本地的仓库上,路径group为itvincent.package,id为example,会创建pom文件,版本为1.0.0

    如果要上传源码把packaging=jar,jar改成java-source

    May 26

    Use Eclipse to debug Tomcat

    Go tomcat installation directory/bin.

    Touch a file (named debug.sh), and fill it as following:

    set JPDA_ADDRESS=8000
    set JPDA_TRANSPORT=dt_socket
    set CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000
    ./catalina.sh  jpda start

    Then go to eclipse debug configurations, new a "remote java application" item, make sure the connection properties refer to the right port (8000 in my case).

    Work with Axis2 and Maven

    Work with Axis2 and Maven

    1. Create a maven project
    In my case, artifactId=axisdemo, groupId=ch.hefr.tic.gridgroup.
    Please make sure: "org.apache.maven.archetypes=maven-archetype-webapp".


    2. Edit ~/.m2/setting.xml
    put admin's username/password of your installed tomcat server

    <servers>
        <server>
            <id>localtomcat</id>
            <username>admin</username>
            <password>admin</password>
        </server>
    </servers>

    3. Edit pom.xml

    Notice:
    (1) Please replace the corresponding artifactId and gridgroupId with your context.
    (2) The commented "axis2-wsdl2code-maven-plugin" is only uncommented while generating java code from wsdl (step 6).

    The pom.xml of project "axisdemo" should look as the following.

    <project 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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>ch.hefr.tic.gridgroup</groupId>
      <artifactId>axisdemo</artifactId>
      <packaging>war</packaging>
      <version>1.0</version>
      <name>axisdemo Maven Webapp</name>
     
        <properties>
            <currentVersion>${project.version}</currentVersion>
            <axis2.version>1.4.1</axis2.version>
            <axiom-api.version>1.2.7</axiom-api.version>
            <saxon.version>8.7</saxon.version>
        </properties>
       
        <build>
          <finalName>axisdemo</finalName>
          <plugins>
              <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.5</source>
                        <target>1.5</target>
                    </configuration>
                </plugin>
               
              <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                         <server>localtomcat</server>
                         <path>/axisdemo</path>
                         <contextFile>src/main/webapp/META-INF/context.xml</contextFile>
                </configuration>
            </plugin>
           
            <!--
                <plugin>
                    <groupId>org.apache.axis2</groupId>
                    <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
                    <version>1.4</version>
                    <executions>
                        <execution>
                            <goals>
                                <goal>wsdl2code</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <packageName>ch.hefr.tic.gridgroup</packageName>
                        <wsdlFile>src/main/resources/wsdl/SimpleService.wsdl</wsdlFile>
                        <databindingName>adb</databindingName>
                        <generateServerSide>true</generateServerSide>
                        <generateServerSideInterface>true</generateServerSideInterface>
                        <generateServicesXml>true</generateServicesXml>
                        <namespaceURIs>
                            <namespaceURI>
                                <uri>http://gridgroup.tic.hefr.ch/SimpleService/</uri>
                                <packageName>ch.hefr.tic.gridgroup.simpleservice</packageName>
                            </namespaceURI>
                        </namespaceURIs>
                    </configuration>
                </plugin>
                -->
        </plugins>
             
        </build>
       
     
        <dependencies>
     
              <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
           
              <dependency>
                <groupId>org.apache.ws.commons.axiom</groupId>
                <artifactId>axiom-api</artifactId>
                <version>${axiom-api.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2-kernel</artifactId>
                <version>${axis2.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2-saaj</artifactId>
                <version>${axis2.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2-adb</artifactId>
                <version>${axis2.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2-adb-codegen</artifactId>
                <version>${axis2.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2-codegen</artifactId>
                <version>${axis2.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2-mtompolicy</artifactId>
                <version>${axis2.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.axis2</groupId>
                <artifactId>axis2-xmlbeans</artifactId>
                <version>${axis2.version}</version>
            </dependency>

            <dependency>
                <groupId>xmlbeans</groupId>
                <artifactId>xbean_xpath</artifactId>
                <version>2.1.0</version>
            </dependency>

            <dependency>
                <groupId>xmlbeans</groupId>
                <artifactId>xbean</artifactId>
                <version>2.2.0</version>
            </dependency>

            <dependency>
                <groupId>net.sf.saxon</groupId>
                <artifactId>saxon</artifactId>
                <version>${saxon.version}</version>
            </dependency>

            <dependency>
                <groupId>net.sf.saxon</groupId>
                <artifactId>saxon-xpath</artifactId>
                <version>${saxon.version}</version>
            </dependency>

            <dependency>
                <groupId>net.sf.saxon</groupId>
                <artifactId>saxon-dom</artifactId>
                <version>${saxon.version}</version>
            </dependency>

            <dependency>
                <groupId>org.apache.ws.commons</groupId>
                <artifactId>XmlSchema</artifactId>
                <version>1.1</version>
            </dependency>
           
            <dependency>
                <groupId>wsdl4j</groupId>
                <artifactId>wsdl4j</artifactId>
                <version>1.6.1</version>
            </dependency>
           
            <dependency>
                <groupId>commons-httpclient</groupId>
                <artifactId>commons-httpclient</artifactId>
                <version>3.1</version>
            </dependency>
           
            <dependency>
                <groupId>annogen</groupId>
                <artifactId>annogen</artifactId>
                <version>0.1.0</version>
            </dependency>
           
            <dependency>
                    <groupId>backport-util-concurrent</groupId>
                    <artifactId>backport-util-concurrent</artifactId>
                    <version>3.1</version>
            </dependency>
           
            <dependency>
                    <groupId>org.apache.geronimo.specs</groupId>
                    <artifactId>geronimo-stax-api_1.0_spec</artifactId>
                    <version>1.0.1</version>
            </dependency>
           
            <dependency>
                  <groupId>javax.servlet</groupId>
                  <artifactId>servlet-api</artifactId>
                  <version>2.4</version>
                  <scope>provided</scope>
            </dependency>
           
            <dependency>
                  <groupId>javax.servlet</groupId>
                  <artifactId>jsp-api</artifactId>
                  <version>2.0</version>
                  <scope>provided</scope>
            </dependency>
       
      </dependencies>
    </project>

    4. Complete the project structure

    Generating a set of directories and files via the following command script:

    mkdir -p src/main/java
    mkdir -p src/main/resources/wsdl
    touch src/main/webapp/META-INF/context.xml
    mkdir -p src/main/webapp/WEB-INF/classes
    mkdir -p src/main/webapp/WEB-INF/conf
    mkdir -p src/main/webapp/WEB-INF/modules
    mkdir -p src/main/webapp/WEB-INF/services

    mkdir -p src/main/webapp/WEB-INF/services/BlankService/META-INF
    touch src/main/webapp/WEB-INF/services/BlankService/META-INF/services.xml
    touch src/main/webapp/WEB-INF/services/BlankService/META-INF/BlankService.wsdl

    Notes:
    "src/main/resources/wsdl" is used for preserving wsdl files generated by the programmer, you can change as you like.

    "src/main/webapp/META-INF/context.xml" should be edited to something like: (watch out the tomcat installation path in your context)
    <Context docBase="/path/to/my/apache-tomcat/webapps/axisdemo"
    path="/axisdemo" reloadable="true"
    source="org.eclipse.jst.j2ee.server:axisdemo"/>

    "src/main/webapp/WEB-INF/classes" is used to preserve properties files, such as log4j.properties
    "src/main/webapp/WEB-INF/conf" is used to preserve configuration files, such as axis2.xml (if you wanna keep an axis-admin website within your project, don't forget to copy the standard axis2-web directory to your webapp directory)
    "src/main/webapp/WEB-INF/modules" is used to preserve axis2 related modules, such as addressing-1.41.mar, soapmonitor-1.41.mar, etc.

    "src/main/webapp/WEB-INF/services/BlankService/" is an example directory, you don't really it. Every time you establish a set of new files/codes from a single wsdl (via "wsdl2code"), you should copy the generated code to the corresponding "src/main/java", and copy the "services.xml & ***.wsdl" here.


    5. Create the wsdl file.

    I create my wsdl based on the SimpleService from the source code of Kent Ka Iok Tong's Axis2 book: Developing Web Services with Apache Axis2 (http://www.agileskills2.org/DWSAA/index.html)

    As usual, the artifactId and groupId should be changed depending on your context.

    My final wsdl file looks like: (don't forget to validate your wsdl if you are eclipse user :-)

    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://gridgroup.tic.hefr.ch/SimpleService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="SimpleService" targetNamespace="http://gridgroup.tic.hefr.ch/SimpleService/">
      <wsdl:types>
        <xsd:schema targetNamespace="http://gridgroup.tic.hefr.ch/SimpleService/">
          <xsd:element name="contactRequest">
            <xsd:complexType>
              <xsd:sequence>
                  <xsd:element name="s1" type="xsd:string" />
                  <xsd:element name="s2" type="xsd:string"></xsd:element>
              </xsd:sequence>
            </xsd:complexType>
          </xsd:element>
          <xsd:element name="contactResponse" type="xsd:string">
          </xsd:element>
        </xsd:schema>
      </wsdl:types>
      <wsdl:message name="contactRequest">
        <wsdl:part element="tns:contactRequest" name="contactRequest"/>
      </wsdl:message>
      <wsdl:message name="contactResponse">
        <wsdl:part element="tns:contactResponse" name="contactResponse"/>
      </wsdl:message>
      <wsdl:portType name="SimpleService">
        <wsdl:operation name="contact">
          <wsdl:input message="tns:contactRequest"/>
          <wsdl:output message="tns:contactResponse"/>
        </wsdl:operation>
      </wsdl:portType>
      <wsdl:binding name="SimpleServiceSOAP" type="tns:SimpleService">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="contact">
          <soap:operation soapAction="http://gridgroup.tic.hefr.ch/SimpleService/contact"/>
          <wsdl:input>
            <soap:body parts="contactRequest" use="literal"/>
          </wsdl:input>
          <wsdl:output>
            <soap:body parts="contactResponse" use="literal"/>
          </wsdl:output>
        </wsdl:operation>
      </wsdl:binding>
      <wsdl:service name="SimpleService">
        <wsdl:port binding="tns:SimpleServiceSOAP" name="SimpleServiceSOAP">
          <soap:address location="http://localhost:8080/axisdemo/services/SimpleService"/>
        </wsdl:port>
      </wsdl:service>
    </wsdl:definitions>

    6. Generate code from wsdl

    Uncomment the "axis2-wsdl2code-maven-plugin" from the pom.xml file.
    Enter "mvn clean compile" in your command line, then you should see generated files in "target/generated-sources/axis2/wsdl2code/..."

    Enter command script:
    mkdir -p src/main/webapp/WEB-INF/services/SimpleService/META-INF

    Copy files services.xml and SimpleService.wsdl from target/generated-source/axis2/wsdl2code/resources to src/main/webapp/WEB-INF/services/SimpleService/META-INF

    Copy directory "target/generated-source/axis2/wsdl2code/src/ch" to "src/main/java"

    Finally, comment "axis2-wsdl2code-maven-plugin" in the pom.xml again.


    7. Add some logic code

    Open src/main/java/ch/hefr/tic/gridgroup/SimpleServiceSkeleton.java

    Change it into: (again, please watch out your groupId)

    package ch.hefr.tic.gridgroup;
    import ch.hefr.tic.gridgroup.simpleservice.ContactResponse;

    public class SimpleServiceSkeleton implements SimpleServiceSkeletonInterface {

        public ch.hefr.tic.gridgroup.simpleservice.ContactResponse contact(
                ch.hefr.tic.gridgroup.simpleservice.ContactRequest contactRequest0) {
           
            System.out.println(" Hello, WebServices!");
            String result = contactRequest0.getS1() + contactRequest0.getS2();
            ContactResponse response = new ContactResponse();
            response.setContactResponse(result.toUpperCase());
            return response;
        }
    }


    8. The web.xml

    Edit your web.xml to something as following:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>axisdemo</display-name>
      <servlet>
        <display-name>Apache-Axis Servlet</display-name>
        <servlet-name>AxisServlet</servlet-name>
        <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/servlet/AxisServlet</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>*.jws</url-pattern>
      </servlet-mapping>
      <servlet-mapping>
        <servlet-name>AxisServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
      </servlet-mapping>
     
    </web-app>


    9. Deploy your webapp to tomcat

    Enter command in project home directory:
    mvn clean compile tomcat:redeploy

    If you can see "BUILD SUCCESSFUL", congratulations, That's all!

    If you are an eclipse user, you can right click the wsdl (any one :-) from the project view and verify the result via "Web Service Explorer".


    10. Issue

    Everything works fine for me if you start/stop tomcat via its embedded shell script (e.g. bin/startup.sh).
    However, if I start the tomcat via eclipse WTP's embedded Server, I am very often prompted while executing "mvn clean compile tomcat:redeploy"
    ---
    Cannot invoke Tomcat manager: FAIL - Context /axisdemo is defined in server.xml and may not be undeployed
    FAIL - Application already exists at path /axisdemo
    ---

    Because the eclipse WTP's embedded Server "likes" to write a <context /> within tomcat's conf/server.xml during deployment, but cannot remove such element after usage. Such issue never happens to tomcat's own shell script.

    If there anyone know how to address this issue, I would appreciate the answer!

    Good Luck!



    May 22

    使用Axis2 Code Generator Wizard 遭遇 InvocationTargetException

    以下是来自https://issues.apache.org/jira/browse/AXIS2-3792的解决方案:

    ---
    I'm using Eclipse 3.4.0 Ganymede and Axis2 1.4.

    I tried all given hints. It still didnt work. I experimented a bit more and here is my solution:

    1) Shutdown eclipse

    2) Copying the "backport-util-concurrent-3.1.jar" from "$AXIS2_HOME/lib/" to "$ECLIPSE_HOME/plugins/Axis2_Codegen_Wizard_1.3.0/lib/"

    3) Adding the following into the "runtime" element "$ECLIPSE_HOME/plugins/Axis2_Codegen_Wizard_1.3.0/plugin.xml" :

          <library name="lib/backport-util-concurrent-3.1.jar">
             <export name="*"/>
          </library>

    4) In "$ECLIPSE_HOME/plugins/Axis2_Codegen_Wizard_1.3.0/plugin.xml" changing the version attribute of the "plugin" element from "1.3.0" to "1.4.0". This results still in the same exception. But leave it.

    5) Now changing the version also in the plugin's folder name from "Axis2_Codegen_Wizard_1.3.0" to "Axis2_Codegen_Wizard_1.4.0".

    6) Start eclipse and try the plugin

    In my case it worked then. Hope i could help you.
    ---

    Good Luck!

    May 19

    奇怪的状态

    忙过了前段时间的paper rush, 最近状态很奇怪, 其实还是有很多事情要做的, 例如: 要写一个程序的扩展包; 看一系列早就下载了的论文; 构建一个新的工作流算法; 重新做一下之前的实验, 来验证新想法的有效性; 语言的进修; 夏天的两个会议以及秋天的一个workshop, 等等等等...
    但就是有点静不下心态了, 想些奇怪的事情, 想想以后的方向应该怎么走, 其实真的是一家一本难念的经, 混口饭吃不容易阿, 呵呵.


    May 05

    搞笑的对联, 模仿唐伯虎点秋香中的对穿肠

    偶得网络上一段模仿唐伯虎点秋香中的对穿肠台词, 搞笑而又有才, 故摘之. 无任何政治寓意, 供看家娱乐而已.

           锦涛:我怎么可以以大欺小呢?
      水扁:文学切磋是不分辈份的!如果你对不出来,别怪我搞台独!接招吧!
      水扁:一年两会又三代表不思四化五谷六业,教训七八九流,十分无聊!
      锦涛:十年九谈凑得八股七条六规五讲四美,为何三刀两面,一个汉奸!
      水扁:好工整!继续:官场里,钱不贪权不沾,小小公仆可笑可笑!
      锦涛:黑道上,刀无影剑无光,混混阿扁提防提防!
      众人:好好,对得好!
      水扁:蒙蒙骗骗吹吹捧捧打打杀杀,喀嚓喀嚓!
      锦涛:唧唧歪歪嘻嘻哈哈婆婆妈妈,三八三八!
      众人:胡总真行呀,胡总好棒!
      水扁:十口心思,思钱思权思小蜜!
      锦涛:八目共赏,赏金赏银赏耳光!
      众人:好,好-----
      水扁:吾撒外汇来铺路!
      锦涛:我引台资入国库!
      水扁:说到统一我就吐!
      锦涛:你他妈的就是猪!
      水扁:(后退数步,鲜血狂喷)你……?下班就泡大陆妹
      锦涛:坐台只点吕秀莲