简体   繁体   English

使用Java和Web模块创建项目

[英]Creating a project with Java and Web Module

I am working on a project where I have two modules, one is a web module which will handle client operations and a java module which will have some other processing and will also initialize an embedded jetty with the war created from the web module. 我正在一个项目中,我有两个模块,一个是可处理客户端操作的Web模块,另一个将具有其他处理功能的Java模块,并且还将使用从Web模块创建的战争来初始化嵌入式码头。 I am using Intellij for the development. 我正在使用Intellij进行开发。

Here are the module information: 以下是模块信息:

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

I have added a dependency of CoreService on ClientDashboard. 我在ClientDashboard上添加了CoreService的依赖项。 But when I print classpath, I do not see the war file in classpath. 但是,当我打印类路径时,在类路径中看不到war文件。

Here are my pom.xml files. 这是我的pom.xml文件。 Web Project 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: 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: 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>

Here is my java class which I am using to print the classpath and which I will be using to start jetty with web war. 这是我用于打印类路径的java类,并将用于通过网络战争开始码头。 EntryMain.java public class EntryMain { 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());
    }
}

} }

Here is the output of my classpath: 这是我的类路径的输出:

/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

What should I do to bring the generated war to the classpath? 我应该怎么做才能将引起的战争带入类路径?

WAR files are never placed in the classpath. WAR文件永远不会放在类路径中。

You will need to find out how to used the embedded Jetty to deploy the WAR file. 您将需要了解如何使用嵌入式Jetty 部署 WAR文件。

As a part of this process Jetty will create a new isolated classloader with the SystemClassLoader that you dumped as the parent (or grandparent or whatever depending on how Jetty works). 作为此过程的一部分,Jetty将使用您作为父级(或祖父母或其他取决于Jetty工作方式)转储的SystemClassLoader创建一个新的隔离类加载器。 This classloader will look for classes in itself first before delegating to the parent. 该类加载器在委派给父级之前将首先在自身中查找类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM