JDK-8151377 : javapackager -deploy does not include files as seen in doc
  • Type: Bug
  • Component: deploy
  • Sub-Component: packager
  • Affected Version: 8u74,9,10
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: linux,os_x
  • Submitted: 2016-03-07
  • Updated: 2017-10-06
  • Resolved: 2017-07-06
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b172Resolved
Sub Tasks
JDK-8181655 :  
Description
Take a little Test-Class:
public class Test {
        public static void main(String[] args) {
                System.out.println("Just a test");
        }
}

Compile it:
[rli@rlinux javapackager2]$ javac Test.java 

Then create the jar file:
javapackager -createjar -srcdir . -srcfiles Test.class -outdir input -outfile Main.jar -appclass Test

It works:
[rli@rlinux javapackager2]$ java -jar input/Main.jar 
Just a test

Then make a bundle:
[rli@rlinux javapackager2]$ javapackager -deploy -srcdir input/ -outdir output -outfile test -native image -BmainJar=Main.jar -appclass Test
No base JDK. Package will use system JRE.
No base JDK. Package will use system JRE.
Creating app bundle: /home/rli/tmp/javapackager2/output/bundles/Test

Looks, good, however:
[rli@rlinux javapackager2]$ output/bundles/Test/Test 
Test Class Test not found.
Test Failed to launch JVM

Because:
[rli@rlinux javapackager2]$ ls output/bundles/Test/app/
Test.cfg

There is not a single jar-file in the app-Directory. 

Only if -srcfiles Main.jar is added to the command line will the Main.jar be included into the bundle.

However the documentation clearly states:

-srcfiles files
    List of files in the directory specified by the -srcdir option. If omitted, all files in the directory (which is a mandatory argument in this case) will be used. Files in the list must be separated by spaces.

So the "omitted" case seems to be not handled properly be the Linux bundler.

The problem also occurs under OSX.

But not so under Windows.
Comments
I just ran the steps as mentioned above. In the folder - output/Test.app/Contents/Java - there are two files - Main.jar and Test.cfg. So its possible this was fixed as part of some other bug and is no longer an issue. Closing this bug as "cannot reproduce" with jdk9 b172.
06-07-2017

I looked back through the source the source. At least as far back as 2013 it has been implemented this way. Also the separation has been path separator, not space. So I'm going to file the space as a separator as a documentation bug unless I can be convinced otherwise, and I will fix -srcdir to accept a path, unless I get in there to do the work and it seems like a bad idea. I'm not sure yet if it will include subdirectories. I don't think any of the subsystems can handle that so most likely not at this point in which case a future feature enhancement will need to be filed. Currently -srddir does not accept paths.
20-04-2016

Sorry, typo. Fixed.
20-04-2016

A simple Gradle project with a javapackager task to workaround the issue of files needing to be explicitly specified. Currently configured to build a .pkg file on OS X.
26-03-2016

What do you mean by "I will fix -srcfiles to accept a path" ? Do you mean as an alternative to the currently documented (but not working) inclusion of all files in -srcdir if no -srcfiles is specified? I will attach a Gradle-based project that I am currently using to work around this issue.
26-03-2016

I take it back. The same problem happens for me as well on OS X (forgot to clean my project and still had an image in my build folder from earlier). If you try to produce a .pkg all that it has in it is the JRE and supporting files. You can see this when you run: pkgutil --payload-files <output_file_from_javapackager> ./MyApplication.app ./MyApplication.app/Contents ./MyApplication.app/Contents/Info.plist ./MyApplication.app/Contents/Java ./MyApplication.app/Contents/Java/MyApplication.cfg ./MyApplication.app/Contents/MacOS ./MyApplication.app/Contents/MacOS/libpackager.dylib ./MyApplication.app/Contents/MacOS/MyApplication ./MyApplication.app/Contents/PkgInfo ./MyApplication.app/Contents/PlugIns ./MyApplication.app/Contents/PlugIns/Java.runtime ./MyApplication.app/Contents/PlugIns/Java.runtime/Contents ./MyApplication.app/Contents/PlugIns/Java.runtime/Contents/Home ...rest of JRE and nothing else.
25-03-2016

Good information, thanks Scott!
23-03-2016

I don't see the same problem on OS X.
23-03-2016

I'm having the same problem. (I've also noticed that the RPM created for 64-bit apps claims to depend on some other 32-bit packages such that the resulting RPM doesn't even install. That can be worked-around by tweaking the .spec file for the RPM after getting javapackager to generate it.) My use case has a lot of files to install, so specifying all of them on the command line is prohibitive. I could get my Gradle script to do it, but in theory it could grow the command line too long anyway.
23-03-2016

Just found another problem. According to the documentation -srcfiles should accept a list of files, separated by spaces. If I extend the example by: [rli@rlinux javapackager2]$ echo Test >> input/Extra.txt and I want to be the Extra.txt to be part of the application, neither of these works: [rli@rlinux javapackager2]$ javapackager -deploy -srcdir input/ -srcfiles "Main.jar Extra.txt" -outdir output -outfile test -native image -BmainJar=Main.jar -appclass Test No base JDK. Package will use system JRE. No base JDK. Package will use system JRE. Creating app bundle: /home/rli/tmp/javapackager2/output/bundles/Test Exception: java.io.FileNotFoundException: input/Main.jar Extra.txt (No such file or directory) Error: Bundler "Linux Application Image" (linux.app) failed to produce a bundle. [rli@rlinux javapackager2]$ javapackager -deploy -srcdir input/ -srcfiles Main.jar Extra.txt -outdir output -outfile test -native image -BmainJar=Main.jar -appclass Test It only works by giving the srcfiles option twice: [rli@rlinux javapackager2]$ javapackager -deploy -srcdir input/ -srcfiles Main.jar -srcfiles Extra.txt -outdir output -outfile test -native image -BmainJar=Main.jar -appclass Test No base JDK. Package will use system JRE. No base JDK. Package will use system JRE. Creating app bundle: /home/rli/tmp/javapackager2/output/bundles/Test [rli@rlinux javapackager2]$ ls output/bundles/Test/app/ Extra.txt Main.jar Test.cfg
07-03-2016