2017-04-11 58 views
0

我正在開發一個項目,其中有兩個模塊,一個是處理客戶端操作的Web模塊和一個將進行其他處理並將初始化嵌入式碼頭的Java模塊與從網絡模塊創建的戰爭。我正在使用Intellij進行開發。使用Java和Web模塊創建項目

這裏是模塊的信息:

WebServiceViewer 
     | 
     --> CoreService - java module 
     --> ClientDashboard - web module (doesn't have pom as created as web project) 

我增加了關於ClientDashboard CoreService的依賴。但是當我打印classpath時,我在classpath中看不到war文件。

這是我的pom.xml文件。 Web項目的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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>webviewer</groupId> 
    <artifactId>service-viewer</artifactId> 
    <packaging>pom</packaging> 
    <version>1.0-SNAPSHOT</version> 

    <modules> 
     <module>ClientDashboard</module> 
     <module>CoreService</module> 
    </modules> 
</project> 

CoreService的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/xsd/maven-4.0.0.xsd"> 
    <parent> 
     <artifactId>service-viewer</artifactId> 
     <groupId>webviewer</groupId> 
     <version>1.0-SNAPSHOT</version> 
    </parent> 
    <modelVersion>4.0.0</modelVersion> 

    <artifactId>server-handler</artifactId> 
    <packaging>pom</packaging> 

    <properties> 
     <spring.version>4.3.6.RELEASE</spring.version> 
     <spring.version.agent>2.5.6</spring.version.agent> 
    </properties> 

    <dependencies> 

     <dependency> 
      <groupId>webviewer</groupId> 
      <artifactId>client-dashboard</artifactId> 
      <version>1.0-SNAPSHOT</version> 
      <type>war</type> 
     </dependency> 

     <dependency> 
      <groupId>org.eclipse.jetty</groupId> 
      <artifactId>jetty-server</artifactId> 
      <version>9.3.6.v20151106</version> 
     </dependency> 

     <dependency> 
      <groupId>org.eclipse.jetty</groupId> 
      <artifactId>jetty-util</artifactId> 
      <version>9.3.6.v20151106</version> 
     </dependency> 

     <dependency> 
      <groupId>org.eclipse.jetty</groupId> 
      <artifactId>jetty-servlet</artifactId> 
      <version>9.3.6.v20151106</version> 
     </dependency> 

     <dependency> 
      <groupId>org.eclipse.jetty</groupId> 
      <artifactId>jetty-webapp</artifactId> 
      <version>9.3.6.v20151106</version> 
     </dependency>  
    </dependencies> 

</project> 

ClientDashboard的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/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 

    <groupId>webviewer</groupId> 
    <artifactId>client-dashboard</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>war</packaging> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-war-plugin</artifactId> 
       <configuration> 
        <webXml>ClientDashBoard\web\WEB-INF\web.xml</webXml> 
       </configuration> 
      </plugin> 

     </plugins> 
    </build> 
</project> 

這裏是我的java類我正在使用打印類路徑和我將會使用網絡戰爭開始碼頭。 EntryMain.java 公共類EntryMain {

public static void main(String[] args) { 
    EntryMain entryPoint = new EntryMain(); 
    ClassLoader cl = ClassLoader.getSystemClassLoader(); 

    URL[] urls = ((URLClassLoader)cl).getURLs(); 

    for(URL url: urls){ 
     System.out.println(url.getFile()); 
    } 
} 

}

這裏是我的類路徑的輸出:

/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/charsets.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/deploy.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/access-bridge-64.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/cldrdata.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/dnsns.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/jaccess.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/jfxrt.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/localedata.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/nashorn.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/sunec.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/sunjce_provider.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/sunmscapi.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/sunpkcs11.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/ext/zipfs.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/javaws.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jce.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jfr.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jfxswt.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jsse.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/management-agent.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/plugin.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/resources.jar 
/C:/Program%20Files/Java/jdk1.8.0_121/jre/lib/rt.jar 
/C:/Users/user/IdeaProjects/WebServiceViewer/CoreService/target/classes/ 
/C:/Users/user/.m2/repository/wfs-etrade/web-dash/1.0-SNAPSHOT/web-dash-1.0-SNAPSHOT.war 
/C:/Users/user/.m2/repository/org/eclipse/jetty/jetty-server/9.3.6.v20151106/jetty-server-9.3.6.v20151106.jar 
/C:/Users/user/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar 
/C:/Users/user/.m2/repository/org/eclipse/jetty/jetty-http/9.3.6.v20151106/jetty-http-9.3.6.v20151106.jar 
/C:/Users/user/.m2/repository/org/eclipse/jetty/jetty-util/9.3.6.v20151106/jetty-util-9.3.6.v20151106.jar 
/C:/Users/user/.m2/repository/org/eclipse/jetty/jetty-io/9.3.6.v20151106/jetty-io-9.3.6.v20151106.jar 
/C:/Users/user/.m2/repository/org/eclipse/jetty/jetty-servlet/9.3.6.v20151106/jetty-servlet-9.3.6.v20151106.jar 
/C:/Users/user/.m2/repository/org/eclipse/jetty/jetty-security/9.3.6.v20151106/jetty-security-9.3.6.v20151106.jar 
/C:/Users/user/.m2/repository/org/eclipse/jetty/jetty-webapp/9.3.6.v20151106/jetty-webapp-9.3.6.v20151106.jar 
/C:/Users/user/.m2/repository/org/eclipse/jetty/jetty-xml/9.3.6.v20151106/jetty-xml-9.3.6.v20151106.jar 
/C:/Users/user/.m2/repository/org/springframework/spring-core/4.3.6.RELEASE/spring-core-4.3.6.RELEASE.jar 
/C:/Users/user/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar 
/C:/Users/user/.m2/repository/org/springframework/spring-beans/4.3.6.RELEASE/spring-beans-4.3.6.RELEASE.jar 
/C:/Users/user/.m2/repository/org/springframework/spring-context/4.3.6.RELEASE/spring-context-4.3.6.RELEASE.jar 
/C:/Users/user/.m2/repository/org/springframework/spring-aop/4.3.6.RELEASE/spring-aop-4.3.6.RELEASE.jar 
/C:/Users/user/.m2/repository/org/springframework/spring-expression/4.3.6.RELEASE/spring-expression-4.3.6.RELEASE.jar 
/C:/Program%20Files%20(x86)/JetBrains/IntelliJ%20IDEA%202016.2.2/lib/idea_rt.jar 

我應該怎麼做,使生成的戰爭到classpath ?

回答

0

WAR文件永遠不會放在類路徑中。

您需要了解如何使用嵌入式Jetty至部署 WAR文件。

作爲這個過程的一部分,Jetty將使用SystemClassLoader創建一個新的獨立類加載器,您可以根據Jetty的工作方式將其作爲父級(或祖父級或任何其他類型)轉儲。這個類加載器將在委託給父代之前首先查找類本身。

+0

感謝您的回覆。所以,我需要一種方法來爲這個類加載器提供我想要部署的文件。我將在這個方向探索選項。 – kromastorm

+0

忘記類裝載器,讓Jetty解決它。 –

+0

是的。我的意思是找到一種方法將Web模塊產生的戰爭傳遞給碼頭配置。 – kromastorm