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

Currently the speed to run a test function is about 5× 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.

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

Related

JavaFX Application won't run when converted to executable

I've created a JavaFX GUI and it worked fine until I exported it as a JAR file and converted it to an Executable file.
Running it using VS Code Run and Debug works fine but, whenever I open the executable, which I exported from
and converted using Launch4j, nothing happens.
But when I try to run it on the Terminal using
Java -jar <filename>.jar
It shows the error
Error: Could not find or load main class ?jar
Caused by: java.lang.ClassNotFoundException: ?jar
below is my launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Launch App",
"request": "launch",
"mainClass": "infixToPostfix.App",
"vmArgs": "--module-path D:/Programming/Projects/School/javafx-sdk-19/lib --add-modules javafx.controls,javafx.fxml"
}
]
}
and bellow is my folder structure
I've seen a few post that is related to the one I currently have but nothing helped. I'm new to JavaFX and i've been trying different solutions for hours. Maybe I just missed something important. Thank you in advance.
I've checked similar post but most of them are using IntelliJ or Eclipse. I've also seen some which uses VS Code and when I tried them, still nothing worked.
Config file
The error you got is a very similar one I got months ago when I first started to develop a JavaFX application. I needed to tell Maven what class my Main class was so that Maven could compile a .jar file for me
I understand your issue. With Maven we need to assign the Main class in the config file, like this: ${project.mainClass} I don't know where you need to do it. Maybe in settings.json or launch.json. You need to check the Java VSCode plugin which provides you with the export function. Check the documentation and it will tell you where you need to put the Main class in the configuration file.
Example pom.xml file (Maven config file)
This is a Maven example and you need to do something similar. It's important that you also compile and tell the Java plugin to compile a single fat JAR with dependencies, otherwise, it won't run.
<?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>
<name>My example project</name>
<groupId>nl.hva</groupId>
<artifactId>my_example_artifact</artifactId>
<version>1.0.0.</version>
<packaging>jar</packaging>
<properties>
<javafx.version>19</javafx.version>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<project.mainClass>my_example_package_name.Main</project.mainClass>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<type>maven-plugin</type>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath/>
<addDefaultImplementationEntries/>
<addDefaultSpecificationEntries/>
<addExtensions/>
<classpathLayoutType/>
<classpathPrefix/>
<customClasspathLayout/>
<mainClass>${project.mainClass}</mainClass>
<packageName/>
<useUniqueVersions/>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${project.url}</url>
<key>value</key>
</manifestEntries>
</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>
VS Code docs
VS Code docs also mention using Maven! So it's easy for me to help you because I have workable JavaFX 19 applications (in another IDE, but Maven is the same everywhere). See vscode docs: https://code.visualstudio.com/docs/java/java-project

Maven-compiler-plugin throws wanted compile errors but deny the compile progress

A few days ago i started with Maven. I have to put only a few of my dependencies in my generated jar file. This is needed because my code is only a plugin (Minecraft Plugin) executed by an api (Minecraft Server Software Spigot). Now the Problem is, that my Plugin depends on an other api (json-simple-1.1).
The last days i tried to edit the maven shade plugin to get the wished result. I failed, and now i did it in this way:
maven include the json-simple-1.1 api, i needing for my plugin
eclipse include the spigot api (Minecraft server software), which will executing my plugin
pom.xml:
<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.falco.essentialsXXX</groupId>
<artifactId>EssentialsXXX-bungeecord</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>Basic class for every Plugin
</description>
<build>
<sourceDirectory>src</sourceDirectory>
<!-- COMPILE -->
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- BUILD -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-json</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
</project>
When i now execute 'mvn clean install' (in the right directory) i get many many errors. That make completely sense. Maven can not find types or classes and everything else comeing from the spigot-api.
My Problem is, that this isnt a real error because when the spigot-api execute my plugin i have the classes and types i need. Maven dont know that and dont compile my Programm :(
At this point a have no idea what to do. I read so many articles but i couldnt find a solution. Every article say ohhh an error here try to use tags and the right api values. That isnt what i need.
I need something like a "bypass" attribute for the compiler so the compiler know "yes this is an error but the coder knows what he does"
If you need something for compilation, it needs to be a Maven dependency.
So take that artifact, install it in your local repository and add it as dependency.
Then your compilation process will probably work.
Note that using a dependency does not mean that you have to include the dependency into the resulting jar.

Is there a way to checkout git repository, to certain folder with maven?

I am attempting to automatize download of repository containing only protocol-buffers (with structure), to "resource" folder for later processing.
I need this kind of functionality, to keep my *.proto files separated from c++ and java code, as they are technically not connected with each other (java application is used for debugging).
My desired effect is to at least checkout repo into project —
My dreamed effect is to get this repo updated every time I run maven.
BR
EDIT
After working a lot with such a problem, I found personally that the git submodule might be a solution for you (if you are not using svn).
Okay, so after googling, I have came across this: maven-scm-plugin, which even from description solves my request.
To save time for most people I will paste example of usage, to make it work.
You need to add this to your pom structure:
<project>
<scm>
<connection>scm:git:[YOUR_PROJECT_URL]</connection>
</scm>
<--! second part -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<version>1.0</version>
<configuration>
<connectionType>connection</connectionType>
<!-- YOUR PATH HERE -->
<checkoutDirectory>src/main/resources/meta</checkoutDirectory>
</configuration>
<executions>
<execution>
<id>tag</id>
<phase>deploy</phase>
<goals>
<goal>tag</goal>
</goals>
</execution>
</executions>
</plugin>
</project>

IKVM jar to dll issues

I'm having hard times trying to convert my .jar library in .dll and make it working by IKVM framework.
I wrote a Java library that works fine since it has been tested succesfully in several java projects, but I strongly need the .dll for .NET.
When I launch the command:
ikvm -jar mylib.jar
everything is ok (I also tried with a Main file to be sure: it works).
But, when I type:
ikvmc -target:library mylib.jar
I got a lot of warnings but still it creates the .dll file. It is important to say that ALL the warnings are related to libraries that I DO NOT use in my project, but I am pretty sure are in the packages I imported in Maven that are essential to me.
I don't know if the true problem is in this step since I read online to ignore those warnings, but to be sure I post a little bit of the output:
warning IKVMC0100: Class "junit.framework.TestCase" not found
warning IKVMC0100: Class "javax.servlet.http.HttpServlet" not found
warning IKVMC0100: Class "javax.servlet.ServletOutputStream" not found
warning IKVMC0100: Class "org.junit.Assert" not found
warning IKVMC0100: Class "junit.framework.TestSuite" not found
warning IKVMC0100: Class "org.apache.tools.ant.taskdefs.MatchingTask" not found
Let us suppose this step is ok, now I have to import the IKVM libraries and the mylib.dll file in the References of my C# app. I did and the outcome is pretty strange: the autocomplete environment suggest me to use only 4 Java classes, ignoring the 99% of the others. I suppose that something went wrong, but it's pretty hard to me understand where and how to fix it.
Just more helpful info: I'm using Maven, Java8 (sdk 1.8) and IKVM 8.
I also tried the same with IKVM 7 and still got the same errors.
In the end, this is my pom.xml:
<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>org.fra.mylibrary</groupId>
<artifactId>MyLibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MYLIBRARY</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- https://mvnrepository.com/artifact/net.sourceforge.owlapi/owlapi-distribution -->
<dependencies>
<!-- https://mvnrepository.com/artifact/net.sourceforge.owlapi/owlapi-distribution -->
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>4.1.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.antlr/antlr4-runtime -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.sourceforge.owlapi/jfact -->
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>jfact</artifactId>
<version>4.0.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- ANTLR4 -->
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.5.3</version>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
<!-- Maven Assembly Plugin to create Jar -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<!-- Maven Compiler Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Just remove all code related to latest version of method and classes , and change it to lower version of library of java , may it work , because I have same error like this

WebcamCapture working in Netbeans but not in jar file?

Hello Guys I have folowwing problem.
I am using Webcam Capture API to capture Pictures. The Problem is that when i compile everything in Netbeans everything works fine. But if i compile everything to one jar file and then run it again everything works besides that webcam feature. Does anyone of you know where the problem could be because i have no idea anymore.
If i download the example jar file from the page http://www.java2s.com/Code/Jar/w/Downloadwebcamcapture033jar.htm
i also cannot start the main jar file.
i already tried to change the JDK versions but it didnt work.
Thank you for your help
The link you point to is just a library jar with no main not an example to be executed.
There are many ways to compile into one jar file, not including all the necessary dependencies could easily create one that will not work.
To create a project that worked for me, create a directory webcamtest.
Save this in the directory as pom.xml
<?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>com.github.wshackle</groupId>
<artifactId>webcamtest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.github.sarxos</groupId>
<artifactId>webcam-capture</artifactId>
<version>0.3.10</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<main.class>Main</main.class>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<configuration>
<archive>
<manifest>
<mainClass>${main.class}</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Make sub directories src\main\java and save this as Main.java
import com.github.sarxos.webcam.Webcam;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Main {
public static void main(String[] args) throws IOException {
Webcam webcam = Webcam.getDefault();
webcam.open();
File f = new File("webcam_snap.png");
ImageIO.write(webcam.getImage(), "PNG",f);
System.out.println("Saved image "+f.getAbsolutePath());
}
}
Open the directory as a project in Netbeans and build.
To run single jar file:
java -jar target/webcamtest-1.0-SNAPSHOT-jar-with-dependencies.jar

Categories

Resources