在Netbeans 8.0.2(3.0.5)中使用Maven我收到以下(奇怪的)错误:
Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war) on project JConnect4Server: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.3:war failed: Negative time -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.3:war (default-war) on project JConnect4Server: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.3:war failed: Negative time
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:225)
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:320)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
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:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
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.PluginExecutionException: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.3:war failed: Negative time
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:110)
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:1427)
at org.apache.maven.plugin.war.packaging.AbstractWarPackagingTask.copyFile(AbstractWarPackagingTask.java:306)
at org.apache.maven.plugin.war.packaging.AbstractWarPackagingTask$1.registered(AbstractWarPackagingTask.java:152)
at org.apache.maven.plugin.war.util.WebappStructure.registerFile(WebappStructure.java:211)
at org.apache.maven.plugin.war.packaging.AbstractWarPackagingTask.copyFile(AbstractWarPackagingTask.java:147)
at org.apache.maven.plugin.war.packaging.AbstractWarPackagingTask.copyFiles(AbstractWarPackagingTask.java:105)
at org.apache.maven.plugin.war.packaging.AbstractWarPackagingTask.copyFiles(AbstractWarPackagingTask.java:127)
at org.apache.maven.plugin.war.packaging.WarProjectPackagingTask.handeWebAppSourceDirectory(WarProjectPackagingTask.java:174)
at org.apache.maven.plugin.war.packaging.WarProjectPackagingTask.performPackaging(WarProjectPackagingTask.java:92)
at org.apache.maven.plugin.war.AbstractWarMojo.buildWebapp(AbstractWarMojo.java:479)
at org.apache.maven.plugin.war.AbstractWarMojo.buildExplodedWebapp(AbstractWarMojo.java:412)
at org.apache.maven.plugin.war.WarMojo.performPackaging(WarMojo.java:213)
at org.apache.maven.plugin.war.WarMojo.execute(WarMojo.java:175)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
... 20 more
首先,错误消息对我没有意义 - 但真正奇怪的是,在命令行上构建和打包应用程序只是运行良好,只有在Netbeans 8.0.2中调用Maven时才会出现问题。
pom本身看起来像这样:
<?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>de.dhbw.mbfl</groupId>
<artifactId>JConnect4Server</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>JConnect4Server</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>sa_viergewinnt_core-mvn-repo</id>
<url>https://raw.github.com/FlorianLoch/sa_viergewinnt_core/gh-pages/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>de.dhbw.mbfl</groupId>
<artifactId>JConnect4Lib</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
有没有更有经验的Maven用户可以帮助我?
提前致谢。
更新:Netbeans和Maven使用的JDK是:1.8.0_25,在VM外部使用的JDK(包装工作正常)是1.8.0_31(我读了一些关于这可能是JDK错误的东西......)
更新:我更新了VM中的JDK,错误保持不变。
答案 0 :(得分:0)
好吧,好像我发现了错误。它是由导致FileNotFound-Exception的JDK错误/问题引起的。这也可以解释为什么使用Windows发生错误。
简单地说,它只是没有用,因为文件的路径中只有一个空格......所以移动项目解决了问题。使用Mac OS时,问题不会发生。
答案 1 :(得分:0)
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;
}
}