1 创建原型
使用maven官方提供的原型(maven-archetype-archetype)来创建自己的原型(test-archetype)
cmd进入要创建原型的目录,输入
mvn archetype:create -DgroupId=com.sdecp -DartifactId=test-archetype -DarchetypeArtifactId=maven-archetype-archetype
注意:maven-archetype-archetype 不可更改
生成原型将同时生成一个archetype.xml文件,内容如下
<archetype>
<id>test-archetype</id>
<sources>
<source>src/main/java/App.java</source>
</sources>
<testSources>
<source>src/test/java/AppTest.java</source>
</testSources>
</archetype>
2 生成eclipse项目
进入到test-archetype目录下。运行 mvn eclipse:eclipse 可以生成eclipse项目
3 导入到eclipse
将生成的原型eclipse项目导入到eclipse中,可以查看现有的目录结构
4 编写SCA 的maven模型
现在需要增加一个 App.composite 构件文件,位置在src/main/resources/archetype-resources/src/main/resources
<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
targetNamespace="http://test-archetype"
name="App">
<component name="AppComponent">
<implementation.java class="${package}.App"/>
</component>
</composite>
5 修改原型描述文件 archetype.xml
增加对App.composite的配置
<archetype>
<id>test-archetype</id>
<sources>
<source>src/main/java/App.java</source>
</sources>
<sources>
<source>src/main/resources/App.compsite</source>
</sources>
<testSources>
<source>src/test/java/AppTest.java</source>
</testSources>
</archetype>
6 修改项目对象文件 pom.xml
<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>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<packaging>jar</packaging>
<version>${version}</version>
<name>${artifactId}</name>
<repositories>
<repository>
<id>apache.incubator</id>
<url>http://people.apache.org/repo/m2-incubating-repository</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-webapp</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-binding-ws-axis2</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-java-runtime</artifactId>
<version>1.6</version>
<scope>runtime</scope>
</dependency>
<!-- exclude stax 1.0.1 as we're also pulling in javax\xml\stream\stax-api\1.0-2 -->
<dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<version>1.0.1</version>
<scope>provided</scope>
</dependency>
<!-- marking dependency as provided to exclude from war file -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<!-- compiler plugin configuration -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compliler-plugin</artifactId>
<version>2.0.11</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>