2

我用tomcat7-maven-plugin:exec-war-only. 插件配置如下所示:

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <warFile>${project.build.outputDirectory}/${project.build.finalName}.war</warFile>
        <mode>both</mode>
        <enableNaming>true</enableNaming>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>exec-war-only</goal>
            </goals>
            <phase>package</phase>
        </execution>
    </executions>
</plugin>

然后tomcat7:run-war部署应用程序,它运行得很好。如果我运行mvn package应用程序 jar 将被创建。如果我再运行java -jar app.jar它,它将成功地部署在 Tomcat 7.0.37 中。但是它不能编译任何JSP。它说:

2013-09-21 00:38:05 JstlView [DEBUG] Forwarding to resource [/jsp/login.jsp] in InternalResourceView 'login'
Sep 21, 2013 12:38:05 AM org.apache.jasper.compiler.TldLocationsCache tldScanJar
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Sep 21, 2013 12:38:05 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalArgumentException: Negative time
        at java.io.File.setLastModified(Unknown Source)
        at org.apache.jasper.compiler.Compiler.compile(Compiler.java:376)

如您所见,JSP 名称中没有空格或特殊字符。我还尝试将 app.jar 放在驱动器的根目录中,以排除文件夹名称中任何可能的字符。效果是一样的。

UPD。我使用远程调试来查看会发生什么。并且线路Long jspLastModified = ctxt.getLastModified(ctxt.getJspFile());返回-1。在它ctxt.getJspFile()返回"/jsp/login.jsp"

4

1 回答 1

0

不太确定为什么会出现问题,但找到了解决方案。发生错误是因为您尝试构建的一个或多个文件的时间为负。(file.getLastModified()返回负值)。如果这是一个巨大的项目,可能很难跟踪其中哪些出错了。下面的代码可能会有所帮助:

package com.example;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ModifyAll {
    public static void main(String[] args) throws IOException {
        List<File> folderList = new ArrayList<>();
        List<File> fileList = new ArrayList<>();

        File folder = new File("D:/Rakhu/Copy/projectfolder/src");
        FileVO baseFileVO = segregateFiles(folder);
        fileList.addAll(baseFileVO.getFileList());
        folderList.addAll(baseFileVO.getFolderList());

        for (int i = 0; i < folderList.size(); i++) {
            FileVO thisVO = segregateFiles(folderList.get(i));
            fileList.addAll(thisVO.getFileList());
            folderList.addAll(thisVO.getFolderList());
        }

        for (int i = 0; i < fileList.size(); i++) {
            Date dte = new Date();
            long milliSeconds = dte.getTime();
            System.out.println("Setting Time For " + fileList.get(i) + " as " + milliSeconds);
            fileList.get(i).setLastModified(milliSeconds);
        }
        System.out.println("Succesfully Modified..!!!");
    }

    public static FileVO segregateFiles(File folder) {
        List<File> folderList = new ArrayList<>();
        List<File> fileList = new ArrayList<>();

        File[] listOfFiles = folder.listFiles();
        for (int i = 0; i < listOfFiles.length; i++) {
            if (listOfFiles[i].isFile()) {
                fileList.add(listOfFiles[i]);
            } else {
                folderList.add(listOfFiles[i]);
            }
            System.out.println(listOfFiles[i]);
        }
        return new FileVO(fileList, folderList);
    }
}



FileVO.java
package com.example;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FileVO {
    List<File> fileList = new ArrayList<>();
    List<File> folderList = new ArrayList<>();

    public FileVO(List<File> fileList, List<File> folderList) {
        this.fileList = fileList;
        this.folderList = folderList;
    }

    public List<File> getFileList() {
        return fileList;
    }

    public void setFileList(List<File> fileList) {
        this.fileList = fileList;
    }

    public List<File> getFolderList() {
        return folderList;
    }

    public void setFolderList(List<File> folderList) {
        this.folderList = folderList;
    }
}
于 2016-02-20T18:03:45.823 回答