JPress二次开发规范以及入门教程

JPress之家发布 开发教程 2016-09-20 1183

在二次开发中,不要修改JPress的任何代码,而是建立自己的一个maven module模块,通过pom依赖的方式把jpress相关代码导入到自己的module中。

maven模块的pom文件如下:

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>io.jpress</groupId>
        <artifactId>jpress</artifactId>
        <version>1.0</version>
    </parent>

    <packaging>war</packaging>
    <artifactId>jpress-your-modulen-ame</artifactId>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.jfinal</groupId>
            <artifactId>jfinal</artifactId>
        </dependency>
        
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        
        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-utils</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        
        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-oauth2</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        
        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-message</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        
        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-search-api</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        
        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-search-dbsimple</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-consts</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        
        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-model</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        
        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-web-core</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <classifier>classes</classifier>
            <scope>provided</scope>
        </dependency>
        
        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-web-core</artifactId>
            <version>1.0</version>
            <type>war</type>
            <scope>compile</scope>
        </dependency>
        
        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-web-front</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <classifier>classes</classifier>
            <scope>provided</scope>
        </dependency>
        
        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-web-front</artifactId>
            <version>1.0</version>
            <type>war</type>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-web-admin</artifactId>
            <version>1.0</version>
            <type>jar</type>
            <classifier>classes</classifier>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>io.jpress</groupId>
            <artifactId>jpress-web-admin</artifactId>
            <version>1.0</version>
            <type>war</type>
            <scope>compile</scope>
        </dependency>

    </dependencies>


    <build>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <resources>
            <resource>
                <directory>src/main/config</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/language</directory>
                <includes>
                    <include>**/*.*</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>


            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat6-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <port>8080</port>
                    <path>/jpress</path>
                    <uriEncoding>UTF-8</uriEncoding>
                    <server>tomcat7</server>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <port>8080</port>
                    <path>/jpress</path>
                    <uriEncoding>UTF-8</uriEncoding>
                    <server>tomcat7</server>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.10</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <encoding>utf-8</encoding>
                    <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
                    <overlays>
                        <overlay>
                            <groupId>io.jpress</groupId>
                            <artifactId>jpress-web-core</artifactId>
                        </overlay>
                        <overlay>
                            <groupId>io.jpress</groupId>
                            <artifactId>jpress-web-front</artifactId>
                        </overlay>
                        <overlay>
                            <groupId>io.jpress</groupId>
                            <artifactId>jpress-web-admin</artifactId>
                        </overlay>
                    </overlays>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

这样,你的module就有了一个具体的web功能,你可以在里面添加自己的controller,model以及其他任何代码。此时,我们在运行我们的程序的时候,是运行我们自己新建的这个module,不再是jpress-web了,放到服务器运行的war包也是我们这个module,不再是jpress-web。

该文章来自于JPress项目中说明,一切依据海哥提供的文档为准!