• tomcat源码环境的安装



    ⎛⎝。◕⏝⏝◕。⎠⎞⎛⎝。◕⏝⏝◕。⎠⎞

    ⎛⎝≥⏝⏝≤⎛⎝⎛⎝≥⏝⏝≤⎛⎝

    build.xml 编译二进制文件,使用 ant 就可以编译可以发布的 tomcat

    1. 添加 pom.xml,内容如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <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>org.apache.tomcat</groupId>
        <artifactId>tomcat9</artifactId>
        <name>tomcat9</name>
        <version>9.0</version>
        <build>
            <finalName>tomcat9</finalName>
            <sourceDirectory>java</sourceDirectory>
            <!--<testSourceDirectory>test</testSourceDirectory>  test 下的有些文件报错,因此将test文件夹去掉了-->
            <resources>
                <resource>
                    <directory>java</directory>
                </resource>
            </resources>
            <testResources>
                <testResource>
                    <directory>test</directory>
                </testResource>
            </testResources>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.6.0</version>
                    <configuration>
                        <encoding>UTF-8</encoding>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
            </plugins>
        </build>
        <dependencies>
            <dependency>
                <groupId>org.apache.ant</groupId>
                <artifactId>ant</artifactId>
                <version>1.9.5</version>
            </dependency>
            <dependency>
                <groupId>org.apache.ant</groupId>
                <artifactId>ant-apache-log4j</artifactId>
                <version>1.9.5</version>
            </dependency>
            <dependency>
                <groupId>org.apache.ant</groupId>
                <artifactId>ant-commons-logging</artifactId>
                <version>1.9.5</version>
            </dependency>
            <dependency>
                <groupId>javax.xml.rpc</groupId>
                <artifactId>javax.xml.rpc-api</artifactId>
                <version>1.1</version>
            </dependency>
            <dependency>
                <groupId>wsdl4j</groupId>
                <artifactId>wsdl4j</artifactId>
                <version>1.6.2</version>
            </dependency>
    <!--        <dependency>-->
    <!--            <groupId>org.eclipse.jdt.core.compiler</groupId>-->
    <!--            <artifactId>ecj</artifactId>-->
    <!--            <version>4.6.1</version>-->
    <!--        </dependency>-->
            <!-- 需要注意这个,这里使用的本地的jar,没有使用 maven 仓库中的jar,因为这个 jar 的最新版本在 maven 仓库中没有 -->
            <!-- 这里 jar 是 build.xml 中配置的 jar 信息 -->
            <dependency>
                <groupId>org.eclipse.jdt.core.compiler</groupId>
                <artifactId>ecj</artifactId>
                <version>4.10</version>
                <scope>system</scope>
                <systemPath>D:/.m2/repository/system/ecj-4.10.jar</systemPath>
            </dependency>
        </dependencies>
    </project>
    
    1. 将这个项目转换为 maven 项目,然后 clean, compile 就可以了,一般是不会报错的

    2. 找到 org.apache.catalina.startup.Bootstrap 启动就可以了

    3. 如果不指定 cataline.home 的目录,则会在当前目录下运行,如果指定了 VM 参数,比如 -Dcatalina.home=D: omcatcataline-home 则会在指定的目录下运行
      注意,需要将 conf 目录和 webapps 目录复制到指定的目录下

    4. 避免报错,将 webapps 目录下的 examples 项目删除,它需要额外的编译,会导致启动报错

    5. docs 项目,也需要额外的编译,可以看到原来的都是一些 *.xml 的文件,具体的编译可以查看 build.xml 的 build-docs 任务,所以我的做法是使用 ant 先编译好 docs 复制到 webappas 下

    6. 乱码问题,这里不深究为什么会乱码,也不跟踪乱码的原因,只写一种解决方案

      1. 第一步,修改 org.apache.tomcat.util.res.StringManager.getString(String) 方法,在 return 前添加代码
        // 解决乱码问题
        try {
            str = new String(str.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
        } catch (UnsupportedOperationException e) {
            e.printStackTrace();
        }
        
        return str;
        
      2. 第二步,修改 org.apache.jasper.compiler.Localizer.getMessage(String) 方法,在 return 前添加代码
        // 解决乱码问题
        try {
            errMsg = new String(errMsg.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
        } catch (UnsupportedOperationException e) {
            e.printStackTrace();
        }
        
        return errMsg;
        
    7. 解决 JSP 无法解析的问题,在 org.apache.catalina.startup.ContextConfig.configureStart() 中,webConfig()之后添加:

    ...
    webConfig();
    
    // 初始化 jsp 解析引擎
    context.addServletContainerInitializer(new JasperInitializer(), null);
    ...
    
  • 相关阅读:
    对开发者有用的英文网站合集
    比较全的OA系统功能模块列表
    OA系统权限管理设计方案
    OA系统启动:基础数据,工作流设计
    JS生成UUID
    java类过滤器,防止页面SQL注入
    Restful安全认证及权限的解决方案
    把表单转成json,并且name为key,value为值
    JDBC上关于数据库中多表操作一对多关系和多对多关系的实现方法
    Jquery 获取第一个子元素
  • 原文地址:https://www.cnblogs.com/catelina/p/14797559.html
Copyright © 2020-2023  润新知