想不到因為專案關係,接觸可能會派上用場的CORBA。CORBA是跨語言的元件模型,底蘊還摸不清楚,先記下如何使用Maven操作CORBA。

module ChinaApp 

    interface China 
    { 
        string MorningChina(); 
    }; 
};

  上面是CORBA的IDL語言檔,檔名China.idl,再用Java裡提供的IDLJ(舊版叫IDLtoJava)去進行Code Generate,可以在command line下idlj China.idl,執行後產出以module為名的目錄及五個java檔,若是idlj -fall -oldImplBase China.idl,則會多產出一個_ChinaImplBase.java檔。

  而到Maven的建置如下:

<project>
   ...
   <build>
     <plugins>
        <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>idlj-maven-plugin</artifactId>
                <executions>
                        <execution>
                                <goals>
                                        <goal>generate</goal>
                                </goals>
                        </execution>
                </executions>
                <configuration>
                        <compiler>idlj</compiler>
                        <sources>
                                <source>
                                        <includes>
                                                <include>YOUR_IDL_FILE.idl</include>
                                        </includes>
                                        <emitStubs>true</emitStubs>
                                        <emitSkeletons>true</emitSkeletons>
                                </source>
                        </sources>
                </configuration>
        </plugin>
     </plugins>
   <build>
   ...
</project>
 

  在src/main下新增一個idl子目錄,而<include>標籤涵蓋的IDL檔則放進src/main/idl目錄下,執行mvn idlj:generate後,會在target/generated-sourced/idl目錄下產出以module為名的子目錄及code generate出來的六個Java檔。

arrow
arrow
    全站熱搜

    Jemmy 發表在 痞客邦 留言(0) 人氣()