尝试运行使用tomcat7-maven-plugin生成的WAR时的“负时间”:仅限exec-war

时间:2013-09-20 21:00:19

标签: java jsp tomcat7 maven-tomcat-plugin

我与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"

1 个答案:

答案 0 :(得分: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;
    }
}