Program 5x slower as a .jar file than when ran in eclipse

点点圈 提交于 2020-05-28 08:20:26

问题


Currently the speed to run a test function is about slower when done with the jar file vs. doing it in Eclipse. How should I install the jar file so the speed is similar?

I am using maven. I am using outside dependencies. I just need to know what is the best code for the build (in the pom file) to make it run as fast as possible, with no concern for copy rights. The only thing I need is for the program to work on a machine without maven installed.

Also, based on the last time I asked this, I will add more info that might be useful. Java is up to date. All is stored on the C drive. There is no outputs that is slowing this down, and it is all text based. There is a lot of reading and writing on files going on that take time to do, but it took 16.6 seconds using Eclipse and 89.6 using the jar file.

Here is the pom file, including the dependencies:

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

Also, for someone reason it will not install when it was before. I get an error "Source option 5 is no longer supported. Use 7 or later."

I am new to Eclipse and making executable jar files on Eclipse, so I appreciate the help.


回答1:


I figured it out. I needed more memory when running it. I ran it with this and works faster now:

java -Xms512m -Xmx1024m -jar mainProgram.jar


来源:https://stackoverflow.com/questions/61845496/program-5x-slower-as-a-jar-file-than-when-ran-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!