目前,与jar文件相比,与Eclipse中相比,运行测试功能的速度要慢 5倍。我应该如何安装jar文件,使速度相近?
我正在使用Maven。我正在使用外部依赖项。我只需要知道什么是构建的最佳代码(在pom文件中),以使其尽可能快地运行,而不用担心复制权限。我唯一需要的是使程序在未安装maven的计算机上运行。
此外,基于我上次询问时,我将添加更多可能有用的信息。 Java是最新的。全部存储在C驱动器中。没有输出会减慢此速度,它全部基于文本。正在进行的文件读取和写入需要很多时间,但是使用Eclipse花费了16.6秒,使用jar文件花费了89.6。
这是pom文件,包括依赖项:
<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>kov</groupId>
<artifactId>etf-creator</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- to get html request for api -->
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
<!-- for a fast way to read in a file -->
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- https://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven -->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>Driver</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
此外,由于某种原因,它将无法在以前安装。我收到错误消息“不再支持源选项5。请使用7或更高版本。”
我是Eclipse的新手,正在Eclipse上创建可执行jar文件,因此我感谢您的帮助。
答案 0 :(得分:1)
我知道了。运行它时需要更多内存。 我用它运行它,现在可以更快地工作:
java -Xms512m -Xmx1024m -jar mainProgram.jar