jpackage error- configured main jar does not exist - java

I am trying to package my app using jpackage. I'm sure my commands are correct, but it keeps giving me an error, saying that my main jar doesn't exist.
I used jdeps to find the dependencies of my app, and then, I used jlink to create a reduced jre for the app. I checked, and the created jre runs my app. Then, I proceeded to use jpackage to package my app. For this, I wrote the following in the Command Prompt:
C:\Users\user1>jpackage --input \Desktop\Apps --name MathbeeApp --main-jar Mathbee1.jar --main-class main.MainThread --type exe
I also tried to change the type:
C:\Users\user1>jpackage --input \Desktop\Apps --name MathbeeApp --main-jar Mathbee1.jar --main-class main.MainThread --type app-image
But I always get the same errors:
Bundler EXE Installer Package skipped because of a configuration problem: the configured main jar does not exist Mathbee1.jar in the input directory
Advice to fix: the main jar must be specified relative to the input directory (not an absolute path), and must exist within that directory
and
Bundler EXE Installer Package skipped because of a configuration problem: the configured main jar does not exist Mathbee1.jar in the input directory
Advice to fix: the main jar must be specified relative to the input directory (not an absolute path), and must exist within that directory
respectively.
But I made sure that my jar file is in the directory. I attached a picture of my directory. I don't understand why it says that it doesn't exist. Can somebody help me with this problem?
enter image description here

Thanks to the comments to my question, I was able to figure out that the solution was to make sure the input directory is not in OneDrive. Once I made sure of this, jpackage was able to find the main jar.

Related

Java11/JavaFX11/Module Deployment Mess (Runnable Jar that works if clicked, but doesn't if ran from command line)

I'm new to Java11/all the overcomplicated module stuff.
The Problem
So I exported my Java11/JavaFX11 program from Eclipse as a Runnable JAR. If I click the JAR, it runs perfectly fine (Eclipse includes all of the module settings and JavaFX itself automatically in the runnable JAR). However, if I try to bundle the JAR with a JRE and run it via the command line with the following BAT file:
#ECHO OFF
%~dp0\jre\bin\java -jar javaprogram.jar
pause
I get:
Error: JavaFX runtime components are missing, and are required to run this application
Press any key to continue . . .
How can I get it to just run the JAR file like it does when I click it?
Ways I've tried to fix it
The weirdest part is, if I just use:
java -jar javaprogram.jar
Which just accesses the installed JRE, it works again. It's only when I'm directly pointing it to a JRE at a specific path that it appears to break.
Alternatively, I'd just bundle JavaFX beside the JRE, but there doesn't seem to be a way to call --module-path with a relative path (googling this nets me a bunch of entirely unrelated stuff). It seems to demand an exact path, which isn't going to work if people are downloading a zip archive and extracting it. This would be redundant though because Eclipse is already packaging JavaFX with the JAR. I don't know why it's getting confused just because I'm calling it from the command line.
The project's code
The project I'm trying to get this to work with happens to be open source, so you can check out the code for it here:
https://github.com/SkyAphid/JDialogue
The main class is JDialogueCore.
Closing
I don't want to use installers since I think that's too bloaty. I'd like to be able to deploy my software like I always have by just putting them in an archive you can extract and run.
It's difficult to simply Google the problems as well since I keep getting completely unrelated results due to the broadness of the topic. Any direction/documentation relating to this problem would be greatly appreciated.
Thank you for your time!
While Java 8, 9, and 10 allowed a JavaFX Application subclass to act as a main class for program startup, that is no longer the case as of Java 11. Placing your public static void main method in a different class and making that class the main class solves the problem. (Source: https://github.com/javafxports/openjdk-jfx/issues/236)
Your command line invocation needs to specify both the location of the JavaFX jar files, and the location of JavaFX native libraries. Normally these are the same location in the JavaFX SDK, but they must be specified in different ways: the jar files go in the classpath or module path, while the native libraries’ location must be specified in a system property:
cd /d %~dp0
jre\bin\java -cp javaprogram.jar;javafx-sdk-11\lib -Djava.library.path=javafx-sdk-11\lib com.example.MyNonApplicationClass
If you define a module-info.java in your program, your .jar is a modular .jar, and you can benefit from the additional security of modules:
cd /d %~dp0
jre\bin\java --module-path javaprogram.jar;javafx-sdk-11\lib -Djava.library.path=javafx-sdk-11\lib -m com.example.myapp/com.example.MyNonApplicationClass
If your modular .jar file has a main class defined, you can omit the class name:
cd /d %~dp0
jre\bin\java --module-path javaprogram.jar;javafx-sdk-11\lib -Djava.library.path=javafx-sdk-11\lib -m com.example.myapp
Notice that relative paths work just fine with --module-path. Relative paths use the current directory as a base. The current directory is not changed merely by putting %~dp0 in front of the invocation of Java. The current directory is a property of the command line or script actively running, and can only be changed with commands like cd or pushd.

run PMD through java

I am trying to run PMD through java following this website
http://pmd.sourceforge.net/pmd-4.3/running.html
when i run this command in the command prompt:
java net.sourceforge.pmd.PMD /path/to/source text basic,imports,unusedcode
it seems to throw the error:
Error: Could not find or load main class net.sourceforge.pmd.PMD
What is needed to run this command?
You need the -cp command line argument and the list of jar files after it. The paths to the jar file can be absolute, starting with C:\ or /, or relative to your current directory. Without the -cp listofjars Java cannot find the main class but it is not found on your filesystem relative to the current directory. It is in one of the jar files.
Edit: on second glance, the command you show is an example template command further down on the page. It is not meant to be run on its own. You need to fill in the arguments with real files and options.

Creation of a .bat file of a java application

I am a bit confused about the process to create a .bat file of a java application. I have exported the executable jar using IDE say Application.jar in C: directory. Then I have written two lines in a .txt file as stated below and saved it as .bat file in the same directory where i have my application.jar. But on double click of the .bat file, the application is not getting executed.
.BAT file code
javac Application.java
java -cp . Application
Note: I have also set the JRE and JDK path in my environment variables till bin path in My Computer properties. But it is not working. Can someone suggest me how can I fix this, because I want to execute my code by doubleclickng on a .bat file. It will be nice if someone can provide me every step I need to follow to accomplish this as I havent ever done this before.
Thanks ,
The first line in your batch file is attempting to compile your program !?
The second line is attempting to run the Application.class file.
What you want if you have produced an executable jar file is:
java -jar Application.jar
But you don't really need the batch file at all. If you double click on the jar file and it runs your program then you can just create a shortcut to it.
Your .bat is just fine. When you double click it might be executing and then closes. This is because your program might not have any UI and it isnt waiting for any input. To verify this take a command prompt and then execute your bat file via that.
In other case I assume that you have a java class called Application and you need to run this via a batch file. In that case if the class have a main method then you just need one line in .bat file
java -cp <the path to class file> Application
So you might be using a javac just to take advantage of class path as current directory. So when you say
javac Application.java
java -cp . Application
It compiles the class to current folder and set that as class path and then execute. This is absolutely file as long as the Application.java doesnt have any third party dependency. But in this case again you need not set -cp to . (current directory will be taken as classpath automatically unless otherwise specificed). So below will also work fine.
javac Application.java
java Application
I support Jurgen reply. If you have an executable jar file and a jre in path then double clicking it will run the application. The META-INF folder inside the jar will have a MANIFEST.MF file which uses a property called Main-Class: to specify the main executing class. And on double clicking this class gets executed. However its only useful if you have a UI. Else it'll also have no effect.
In all these context the Application.jar you mentioned is irrelevant. If that is a third party jar that you need to run the you should include that in -cp argument.

Folder permission issue with jarsigner

This is definitely a very beginner question that might not have to do anything with programming. After few days, I have finally identified the problem as for why I couldn't sign jar using jarsigner. I kept getting this error that says "jarsigner: unable to create hello.jar.sig".
Basically, what I did was to put a jar in Java jdk's bin folder and then I shift-left click there in the folder to click on "Open the command window here". I generated the key from keytool and also used selfcert. Then when I did the jarsigner for a jar already put in the bin folder, I got the error. I eventually figured out the reason. I couldn't create the jar.sig in the bin folder since I don't have sort of permission. The question is, how do I set the destination to some folder that is modifiable?
I have no idea how to set the path to java directory and calling jarsigner from desktop or elsewhere, so I had to learn to write command prompt right inside the java bin folder.
Move your JAR file to a directory you can read/write.
Run the original command:
"C:\Path\To\JDK\bin\jarsigner" [options] jar-file
By default the output will be written to the directory you ran the command from.
In the long term, you can add the JDK bin directory to your Windows path.

Error when executing a JAR file

I've been learning about JAR files and wanted to try and create and run one myself. I carried out the following steps:
Created a project folder with a 'source' subfolder and a 'classes' subfolder
I wrote 2 source files, one with a main method which creates an instance of the other class and runs a simple method in it.
Compiled these to the 'classes' subfolder. I checked to see if they would run. They did
I created a manifest.txt file and filled in the Main-Class: xxxx and hit the return key. I saved this in the sources subfolder
Created a jar file in the classes subfolder by writing
jar -cvmf manifest.txt zzz.jar *.class
Tried to execute the jar file by typing
java -jar zzz.jar
This gives a ClassNotFound exception. If I try to execute the jar by double clicking on it in windows I get an errorbox saying "Could not find the main class xxxx"
I've double checked the spelling of the class inside the manifest file and it's correct.
Possibly important: I have to compile my programs using java -cp . xyz as there is an issue with my classpath. Does this mean that I need to execute jars in a different way as well? I tried
java -cp . -jar zzz.jar
but ended up with the same exception.
Edit: I ended up starting from scratch and now it runs (with the basic -jar zzz.jar command). Frustrating that I don't know what I was doing wrong but glad that it is working!
Shouldn't number 5. be run in the classes subfolder, where all your class files are? And if your classes are in packages, which they should be, you'll likely want to use * instead of *.class..?
To check what your jar file contains you can run:
jar tf zzz.jar
You will probably have to supply the entire path of the .class file you wish to execute after the classpath. ie java -cp xxx.jar classes.mainProgram.class. Where classes is the name of the folder which contains your class files.

Categories