简体   繁体   中英

“Negative time” when trying to run WAR generated with tomcat7-maven-plugin:exec-war-only

I generate executable war with tomcat7-maven-plugin:exec-war-only . Plugin configuration looks like this:

<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>

Then tomcat7:run-war deploys application and it runs perfectly well. If I run mvn package application jar is created. If I then run java -jar app.jar it is successfully deployed with Tomcat 7.0.37. But then it cannot compile any JSP. It says:

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)

As you see I have no spaces or special characters in JSP name. I also tried to put app.jar to the root of the drive to exclude any possible characters in folder name. Effect is just the same.

UPD. I used remote debugging to see what happens. And the line Long jspLastModified = ctxt.getLastModified(ctxt.getJspFile()); returns -1 . In it ctxt.getJspFile() returns "/jsp/login.jsp" .

Not really sure why the problem occurs, but found out the solution. The error occurs, because one or more file that you are trying to build, has a negative time. ( file.getLastModified() returns a negative value). If it's a huge project, might be hard to track which of them has gone wrong. Below code might help:

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;
    }
}

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