Java レスト サーバーとレスト クライアントの統合を Eclipse でテストしたいと思います。hello-client プロジェクトと hello-server プロジェクトはどちらも、同じ hello-model jar ファイル (POJO を含む) に依存しています。
問題は、クライアントまたはサーバーのさまざまなバージョンをチェックアウトし、eclipse でコードを編集してテストをデバッグできるようにしたいということです。
Maven shade プラグインを使用して、サーバーのモデル パッケージの名前を変更しようとしました。
hellopojo.model -> hellopojo.server.model
しかし、それはEclipseには影響しません(Mavenのステージが間違っていると思います)。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>hellopojo.model</pattern>
<shadedPattern>hellopojo.server.model</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
ユニットテストコードは次のとおりです。
@Parameters({"port"})
@BeforeClass
public static void startWebapp(
@Optional("8081") int port) throws Exception {
restUri = "http://localhost:"+port+"/rest";
client = new HelloClient(new URI(restUri));
server = new Server(port);
server.setHandler(createWebAppContext());
server.start();
}
private static ServletContextHandler createWebAppContext() {
ServletContextHandler handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
handler.setContextPath("/");
ServletHolder servlet = new ServletHolder(new ServletContainer());
servlet.setInitParameter(
"com.sun.jersey.config.property.packages",
HelloResource.class.getPackage().getName());
servlet.setInitParameter(
"com.sun.jersey.api.json.POJOMappingFeature" ,
"true");
handler.addServlet(servlet, "/rest/*");
return handler;
}
@AfterClass
public static void stopWebapp() throws Exception {
server.stop();
}
stackoverflow に関する関連する質問: さまざまなクライアントとサーバーのバージョンをテストするための最良の Git 戦略