[ 
https://issues.apache.org/jira/browse/MJAR-142?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15155708#comment-15155708
 ] 

Rakhunathan commented on MJAR-142:
----------------------------------

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



> 'Negative time' when trying to create an empty jar
> --------------------------------------------------
>
>                 Key: MJAR-142
>                 URL: https://issues.apache.org/jira/browse/MJAR-142
>             Project: Maven JAR Plugin
>          Issue Type: Bug
>    Affects Versions: 2.3
>         Environment: Windows 7
> maven 3.0.2
>            Reporter: bblasi bblasi
>            Assignee: Karl Heinz Marbaise
>
> When I try to run 'package' on a multi-module project one of the modules 
> fails. The only difference on this module being it will run an ant script so 
> no jar, or an empty one up until now, would be generated.
> Plugin 2.2 will do the job. Plugin 2.3 fails on '-X package' with:
> {code}
> [ERROR] Failed to execute goal 
> org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar (default-jar) on project 
> ETRAMPackager: Error assembling JAR: Negative time -> [Help 1]
> org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute 
> goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:jar (default-jar) on 
> project ETRAMPackager: Error assembling JAR
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
>       at 
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
>       at 
> org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
>       at 
> org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
>       at 
> org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
>       at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
>       at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
>       at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
>       at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
>       at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
>       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>       at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>       at java.lang.reflect.Method.invoke(Method.java:597)
>       at 
> org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
>       at 
> org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
>       at 
> org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
>       at 
> org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
> Caused by: org.apache.maven.plugin.MojoExecutionException: Error assembling 
> JAR
>       at 
> org.apache.maven.plugin.jar.AbstractJarMojo.createArchive(AbstractJarMojo.java:223)
>       at 
> org.apache.maven.plugin.jar.AbstractJarMojo.execute(AbstractJarMojo.java:235)
>       at 
> org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
>       at 
> org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
>       ... 19 more
> Caused by: java.lang.IllegalArgumentException: Negative time
>       at java.io.File.setLastModified(File.java:1258)
>       at 
> org.codehaus.plexus.components.io.resources.PlexusIoFileResource.setLastModified(PlexusIoFileResource.java:148)
>       at 
> org.codehaus.plexus.components.io.resources.PlexusIoFileResource.setFile(PlexusIoFileResource.java:82)
>       at 
> org.codehaus.plexus.components.io.resources.PlexusIoFileResource.<init>(PlexusIoFileResource.java:73)
>       at 
> org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection.addResources(PlexusIoFileResourceCollection.java:144)
>       at 
> org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection.getResources(PlexusIoFileResourceCollection.java:181)
>       at 
> org.codehaus.plexus.components.io.resources.AbstractPlexusIoResourceCollection.getLastModified(AbstractPlexusIoResourceCollection.java:247)
>       at 
> org.codehaus.plexus.archiver.AbstractArchiver.isUptodate(AbstractArchiver.java:768)
>       at 
> org.codehaus.plexus.archiver.AbstractArchiver.checkForced(AbstractArchiver.java:799)
>       at 
> org.codehaus.plexus.archiver.zip.AbstractZipArchiver.execute(AbstractZipArchiver.java:236)
>       at 
> org.codehaus.plexus.archiver.AbstractArchiver.createArchive(AbstractArchiver.java:852)
>       at 
> org.apache.maven.archiver.MavenArchiver.createArchive(MavenArchiver.java:543)
>       at 
> org.apache.maven.plugin.jar.AbstractJarMojo.createArchive(AbstractJarMojo.java:216)
>       ... 22 more
> [ERROR] 
> [ERROR] 
> [ERROR] For more information about the errors and possible solutions, please 
> read the following articles:
> [ERROR] [Help 1] 
> http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
> [ERROR] 
> [ERROR] After correcting the problems, you can resume the build with the 
> command
> [ERROR]   mvn <goals> -rf :ETRAMPackager
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to