简体   繁体   中英

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. I am using Intellij for the development.

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. But when I print classpath, I do not see the war file in classpath.

Here are my pom.xml files. 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>

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. EntryMain.java public class 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.

You will need to find out how to used the embedded Jetty to deploy the WAR file.

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). This classloader will look for classes in itself first before delegating to the parent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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