Q
Q
Quad_Tree2015-01-25 23:11:47
Java
Quad_Tree, 2015-01-25 23:11:47

How to compile Jar file with argument?

In IDEA, I wrote a VM argument to start the project: -Djava.library.path=src/native/windows/x64
The project starts and runs. No problems.
Later in IDEA I created a Jar file to run the project outside of IDEA. I threw the DEngine.jar file into my home folder and tried to run it, here is the result:
08c7bfccbc504ca1becfd1e68ca0b132.bmp
What's the problem?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
P
pi314, 2015-01-25
@Quad_Tree

Don't read error messages - ask questions :) Meanwhile, it specifically says what the problem is: Failed to load the native library.
There are probably some DLLs in src/native/windows/x64. When the program was run from the project folder, everything was fine. Now the JARs have been moved to another place, but the DLLs have not been taken ... and they are no longer found, because their path is relative.
There are two solutions to the problem: either specify the absolute path to the DLL, or grab them along with the JAR to another folder.

S
SerCe, 2015-01-25
@SerCe

Probably because your path is relative.

A
asd111, 2015-01-25
@asd111

For simple cases, create a jar like this:
1. First add libraries:
File > Project Structure > Libraries > click the green plus sign > select the required libraries > click OK
2. Add Artifact for Build (at this stage, the jar itself is created)
File > Project Structure > Artifacts > click the green plus sign > JAR > From module with dependencies > click the button with three dots next to Main Class > select the class in which the Main method is written > choose either extract to the target JAR (very convenient in simple cases - the library will copied to JAR) or copy to the output dir... > click OK > click OK > then click Build > Build artifacts > Build
And your Jar with all the dependencies is ready for work and defense)))
In complex cases, it is desirable to use the Maven, Gradle, Ant build systems

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question