我正在开发一个项目,我有两个模块,一个是处理客户端操作的Web模块和一个将进行其他处理的java模块,还将使用Web模块创建的war来初始化嵌入式jetty 。我正在使用Intellij进行开发。
以下是模块信息:
WebServiceViewer
|
--> CoreService - java module
--> ClientDashboard - web module ( doesn't have pom as created as web project)
我在ClientDashboard上添加了CoreService的依赖项。但是当我打印classpath时,我没有在classpath中看到war文件。
这是我的pom.xml文件。 Web Project 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类,我将使用它来用web war启动jetty。 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
如何将生成的战争带到类路径?
答案 0 :(得分:0)
WAR文件永远不会放在类路径中。
您需要了解如何使用嵌入式Jetty 部署 WAR文件。
作为此过程的一部分,Jetty将使用SystemClassLoader创建一个新的隔离类加载器,您将其作为父级(或祖父母或其他任何东西,具体取决于Jetty的工作方式)。在委托给父类之前,这个类加载器首先会查找类。