Javapackager - NoSuchFileException while copying libraries JDK 9 - java

When I use the javapacker command, I get a NoSuchFileException when it should copy the libraries to the app folder. I'm running the following command:
javapackager -deploy -nosign -v -native image -name test
-appclass test.Test
-srcdir "E:\projects\test\target"
-srcfiles test-1.0.jar;lib
-outdir "E:\projects\test\target\dist"
Anything seams to work fine, but i get the NoSuchFileException inside the output and the libraries inside the lib folder are missing (did not get copied).
Running [D:\Java64\jdk-9.0.4\bin\java.exe, -version]
Creating app bundle: test in E:\projects\test\target\dist
"Adding modules: [java.rmi, java.sql, javafx.web, ... long list ...
outputDir = E:\projects\test\target\dist\test\runtime
modulePath = [D:\Java64\jdk-9.0.4\jmods]
addModules = [java.rmi, java.sql, javafx.web, ... long list ...
limitModules = []
excludeFileList = .*\.diz
stripNativeCommands = true
userArguments = {}
Using default package resource [icon] (add package/windows/test.ico to the class path to customize)
Using default package resource [Template for creating executable properties file.] (add package/windows\test.properties to the class path to customize)
Running [D:\Java64\jdk-9.0.4\bin\javapackager.exe, --icon-swap, C:\Users\XXX\AppData\Local\Temp\fxbundler15945263774290817340\windows\test.ico, E:\projects\test\target\dist\test\test.exe]
Icon File Name: C:\Users\XXX\AppData\Local\Temp\fxbundler15945263774290817340\windows\test.ico
Executable File Name: E:\projects\test\target\dist\test\test.exe
Running [D:\Java64\jdk-9.0.4\bin\javapackager.exe, --version-swap, C:\Users\XXX\AppData\Local\Temp\fxbundler15945263774290817340\windows\test.properties, E:\projects\test\target\dist\test\test.exe]
Resource File Name: C:\Users\XXX\AppData\Local\Temp\fxbundler15945263774290817340\windows\test.properties
Executable File Name: E:\projects\test\target\dist\test\test.exe
Exception: java.nio.file.NoSuchFileException: E:\projects\test\target\lib\animal-sniffer-annotations-1.14.jar -> E:\projects\test\target\dist\test\app\lib\animal-sniffer-annotations-1.14.jar
Config files are saved to C:\Users\XXX\AppData\Local\Temp\fxbundler15945263774290817340\windows. Use them to customize package.
Result application bundle: E:\projects\test\target\dist
I don't know what the following line of the output is trying to tell me. The file clearly exists inside my lib folder and the javapackager did find it itself by looking inside the lib folder, that I provided with the -srcfiles test-1.0.jar;lib argument.
Exception: java.nio.file.NoSuchFileException: E:\projects\test\target\lib\animal-sniffer-annotations-1.14.jar -> E:\projects\test\target\dist\test\app\lib\animal-sniffer-annotations-1.14.jar
Any idea why javapacker complains that the file would not exist?

As per https://docs.oracle.com/javase/9/tools/javapackager.htm#JSWOR719,
-srcfiles should be provided with a list of files. lib is a directory. I would try using -srcdir.
Also, if you get
Exception: java.lang.Exception: Error: Modules are not allowed in srcfiles
it means you have to use --module-path, and then set the main module using -m <module name>

Related

How to access Java dependency on command line?

I have a moderately old, small Java application which has an option to read and export PDF files using the Apache PDFBox library (hereunder, "pdfbox-app.jar"). All the files, including this resource, are stored in a single flat folder.
This works fine when called from a JAR file:
D:\Prog\!GitHub\Arena>java -jar Athena.jar NPCGenerator -p
OED NPC Generator
-----------------
Writing Gwenllian-ElfFtr1Wiz1.pdf
It similarly works fine when run from my IDE (jGrasp).
But it fails when called from the command line, outside of its JAR:
D:\Prog\!GitHub\Arena>java NPCGenerator -p
OED NPC Generator
-----------------
Writing Eoin-HalflingFtr1.pdf
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/pdfbox/pdmodel/PDDoc
ument
at CharacterPDF.writePDF(CharacterPDF.java:49)
at NPCGenerator.printToPDF(NPCGenerator.java:294)
at NPCGenerator.makeAllNPCs(NPCGenerator.java:270)
at NPCGenerator.main(NPCGenerator.java:308)
Caused by: java.lang.ClassNotFoundException: org.apache.pdfbox.pdmodel.PDDocument
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.j
ava:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoader
s.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 4 more
What should I be doing to run this on the command line outside of its own JAR?
You should put the pdfbox jar, and any other dependencies, on the classpath:
java -classpath .;pdfbox-app.jar NPCGenerator -p
Without that, Java doesn't know where to look for org/apache/pdfbox classes. It looks for .class files relative to the default classpath (which is just ., the current directory), but does not look inside jars.

How to add Custom Processor to StreamSets

I have a StreamSets container in docker compose and jar file, which are created according with tutorial - https://github.com/streamsets/tutorials/blob/master/tutorial-processor/readme.md
https://github.com/streamsets/tutorials/tree/master/tutorial-processor/sampleprocessor
The source was added correctly.
Extract the tarball to the SDC user-libs directory, restart SDC, and
you should see the sample stages in the stage library:
To add Custom Processor to pipeline I copied jar file to user-labs And restart docker
docker exec -it docker-hadoop_streamsets_1 bash
sudo cp -a /data/lib/. /opt/streamsets-datacollector-3.9.0/user-libs
docker restart docker-hadoop_streamsets_1
But after restarting I don't see new destination. Also I tried to add with web interface and read this article - https://streamsets.com/documentation/datacollector/latest/help/datacollector/UserGuide/Installation/AddtionalStageLibs.html#concept_evs_xkm_s5
bash-4.4$ ls -R /opt/streamsets-datacollector-3.9.0/user-libs/
/opt/streamsets-datacollector-3.9.0/user-libs/:
com.example-1.0-SNAPSHOT com.example-1.0-SNAPSHOT.jar com.example-1.0-SNAPSHOT~ sampleprocessor sampleprocessor-1.0-SNAPSHOT sampleprocessor-1.0-SNAPSHOT.jar
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~:
CredentialStores.json Interceptors.json PipelineStages.json com default.png
Delegates.json LineagePublishers.json Services.json data-collector-library-bundle.properties
ElDefinitions.json META-INF StageDefList.json datacollector-resource-bundles.json
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/META-INF:
MANIFEST.MF maven
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/META-INF/maven:
com.example
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/META-INF/maven/com.example:
com.example
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/META-INF/maven/com.example/com.example:
pom.properties pom.xml
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/com:
example
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/com/example:
stage
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/com/example/stage:
destination lib origin processor
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/com/example/stage/destination:
sample
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/com/example/stage/destination/sample:
Groups.class SampleDTarget.class SampleTarget$1.class SampleTarget.class
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/com/example/stage/lib:
sample
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/com/example/stage/lib/sample:
Errors.class
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/com/example/stage/origin:
sample
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/com/example/stage/origin/sample:
Groups.class SampleDSource.class SampleSource.class
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/com/example/stage/processor:
sample
/opt/streamsets-datacollector-3.9.0/user-libs/com.example-1.0-SNAPSHOT~/com/example/stage/processor/sample:
Groups.class SampleDProcessor.class SampleProcessor.class
/opt/streamsets-datacollector-3.9.0/user-libs/sampleprocessor:
ElDefinitions.json PipelineStages.json data-collector-library-bundle.properties default.png
META-INF com datacollector-resource-bundles.json
/opt/streamsets-datacollector-3.9.0/user-libs/sampleprocessor/META-INF:
MANIFEST.MF maven
/opt/streamsets-datacollector-3.9.0/user-libs/sampleprocessor/META-INF/maven:
com.example
/opt/streamsets-datacollector-3.9.0/user-libs/sampleprocessor/META-INF/maven/com.example:
sampleprocessor
All you need is the com.example-1.0-SNAPSHOT.jar file, and it should be located in /opt/streamsets-datacollector-3.9.0/user-libs/sampleprocessor/lib.

After creating JAR file, command line returns 'Error: Could not find or load main class ExampleProgram`?

JAR file will not run, instead returns
Error: Could not find or load main class ExampleProgram
Caused by: java.lang.NoClassDefFoundError: ExampleProject/ExampleProgram (wrong name: ExampleProgram)
I've tried deleting the class file, then re-creating the JAR file. I've tried deleting and re-creating the program from scratch. I've tried creating the JAR file without a manifest.
package ExampleProject;
public class ExampleProgram {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
This is the exact process in how I tried to create the JAR file on the command-line.
Josephs-MBP:program jepappano4$ ls
ExampleProgram.class ExampleProgram.java
Josephs-MBP:program jepappano4$ java ExampleProgram
Error: Could not find or load main class ExampleProgram
Caused by: java.lang.NoClassDefFoundError: ExampleProject/ExampleProgram (wrong name: ExampleProgram)
Josephs-MBP:program jepappano4$ ls
ExampleProgram.class ExampleProgram.java
Josephs-MBP:program jepappano4$ ls
ExampleProgram.class ExampleProgram.java manifest.mf
Josephs-MBP:program jepappano4$ jar -cvfm myprogram.jar manifest.mf *.class
added manifest
adding: ExampleProgram.class(in = 450) (out= 301)(deflated 33%)
Josephs-MBP:program jepappano4$ java -jar myprogram.jar
Error: Could not find or load main class ExampleProgram
Caused by: java.lang.NoClassDefFoundError: ExampleProject/ExampleProgram (wrong name: ExampleProgram)
I am following a tutorial on creating JAR files and I expected this process to work, but it doesn't. What am I doing incorrect here?
Not sure if this is important or not, however, I am using Java 11.
The 'wrong name' error is the key error here. This is what it means:
In java, the full name of a class is its package, followed by a dot, followed by the classname. So, your full name for this class is ExampleProject.ExampleProgram.
To start them, you must put this full name in yor manifest: It needs to have an entry that looks like:
Main-Class: ExampleProject.ExampleProgram
In addition, folder structure must match the dots. So, the jar file (which is really just a zip file) must contain inside it at the root level a directory named ExampleProject and this dir needs a file named ExampleProgram.class.
You've gotten one or both of those wrong, causing this error. You can check the structure of your jar file as follows:
jar tvf myjar.jar
you should see a listing for:
ExampleProject/ExampleProgram.class
in that precise location.

CMake: Generate a jar file using multiple jar dependencies (out of source build)

I have spent a few days now to do the following with CMake (3.5.2). Using an out of source build, create a jar file relying on multiple external jar dependencies. In my manifest, I want only to specify Main-Class, nothing else.
This is what I have in my croco/owl2gdb/CMakeLists.txt directory:
cmake_minimum_required (VERSION 3.5)
find_package(Java REQUIRED)
include(UseJava)
project (owl2gdb)
SET(CLASSPATH ${CMAKE_CURRENT_SOURCE_DIR}/lib/commons-lang3-3.3.2.jar:${CMAKE_CURRENT_SOURCE_DIR}/lib/concurrentlinkedhashmap-lru-1.4.2.jar:${CMAKE_CURRENT_SOURCE_DIR}/lib/HermiT.jar)
list(APPEND CMAKE_JAVA_INCLUDE_PATH ${CLASSPATH})
SET(SOURCE
${CMAKE_CURRENT_SOURCE_DIR}/src/owl2gdb/OWL2GDB.java
${CMAKE_CURRENT_SOURCE_DIR}/src/graphdatabase/GraphDatabase.java
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/CPPFileWriter.java
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/CppHeaderFileWriter.java
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/CppSourceFileWriter.java
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/CppTextTemplate.java
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/GraphDatabaseHeaderWriter.java
${CMAKE_CURRENT_SOURCE_DIR}/src/cpp/GraphDatabaseSourceWriter.java
${CMAKE_CURRENT_SOURCE_DIR}/src/knowledge/MyOntology.java
${CMAKE_CURRENT_SOURCE_DIR}/src/knowledge/MyOWLClass.java
${CMAKE_CURRENT_SOURCE_DIR}/src/knowledge/MyOWLDataProperty.java
${CMAKE_CURRENT_SOURCE_DIR}/src/knowledge/MyOWLObjectProperty.java
${CMAKE_CURRENT_SOURCE_DIR}/src/knowledge/MyOWLOntology.java
${CMAKE_CURRENT_SOURCE_DIR}/src/tool/Util.java)
set(JAVA_JAR_ENTRY_POINT owl2gdb/OWL2GDB)
add_jar(owl2gdb ${SOURCE})
add_custom_command(TARGET owl2gdb
POST_BUILD
COMMAND jar u0fm owl2gdb.jar ${CMAKE_CURRENT_SOURCE_DIR}/META-INF/MANIFEST.MF ${SOURCE}
)
In my root directory, I do:
mkdir _build
cd _build
cmake ..
make
owl2gdb.jar is indeed generated in _build/owl2gdb/owl2gdb.jar. Then
cd owl2gdb
java -jar owl2gdb.jar
gives me
Exception in thread "main" java.lang.NoClassDefFoundError: com/martiansoftware/jsap/StringParser
Basically, the external jars are not included in my owl2gdb.jar. I don't really know where to go from here. Is there a problem with cmake not properly using CMAKE_JAVA_INCLUDE_PATH? What is missing in my CMakeLists.txt?
a jar tf owl2gdb.jar returns:
META-INF/
META-INF/MANIFEST.MF
tool/Util.class
graphdatabase/GraphDatabase$1.class
graphdatabase/GraphDatabase.class
cpp/CPPFileWriter.class
cpp/GraphDatabaseHeaderWriter.class
cpp/CppHeaderFileWriter.class
cpp/CppTextTemplate.class
cpp/CppSourceFileWriter.class
cpp/GraphDatabaseSourceWriter.class
owl2gdb/OWL2GDB.class
knowledge/MyOWLClass.class
knowledge/MyOWLDataProperty.class
knowledge/MyOntology.class
knowledge/MyOWLObjectProperty.class
knowledge/MyOWLOntology.class
usr/local/me/github/croco/owl2gdb/src/owl2gdb/OWL2GDB.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/graphdatabase/GraphDatabase.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/cpp/CPPFileWriter.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/cpp/CppHeaderFileWriter.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/cpp/CppSourceFileWriter.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/cpp/CppTextTemplate.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/cpp/GraphDatabaseHeaderWriter.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/cpp/GraphDatabaseSourceWriter.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/knowledge/MyOntology.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/knowledge/MyOWLClass.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/knowledge/MyOWLDataProperty.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/knowledge/MyOWLObjectProperty.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/knowledge/MyOWLOntology.java
usr/local/me/github/croco/owl2gdb/src/owl2gdb/src/tool/Util.java
This is the only thing I have in my manifest:
Main-Class: owl2gdb.OWL2GDB

ClassNotFoundException while running jar

I am getting ClassNotFoundException when I try to run a jar whith below command:
java -jar MyJar.jar
I created the jar with eclipe. MyJar depends of a couple of other jars. I saw in ecplise that all these other jars are there in the classpath.
I also added these jars to the classpath in Unix using export classpath. But still I get the ClassNotFoundException.
Exception Stack Trace:
Exception in thread "main" java.lang.NoClassDefFoundError: org.apache.hadoop.conf.Configuration
at com.a.HDFSCopy.readURI(HDFSCopy.java:16)
at com.a.CopyMain.main(CopyMain.java:9)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.conf.Configuration
at java.net.URLClassLoader.findClass(URLClassLoader.java:434)
at java.lang.ClassLoader.loadClass(ClassLoader.java:660)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358)
at java.lang.ClassLoader.loadClass(ClassLoader.java:626)
... 2 more
Class Path Before:
/opt/ibm/biginsights/IHC/lib/biginsights-gpfs-1.1.1.jar:/opt/ibm/biginsights/IHC/hadoop-core.jar:
Class Path After (included the locations of the jars needed for dependencies) :
[biadmin#big-instght-15 ~]$ echo $CLASSPATH
/opt/ibm/biginsights/IHC/lib/biginsights-gpfs-1.1.1.jar:/opt/ibm/biginsights/IHC/hadoop-core.jar::/home/biadmin/hadoop_jars/commons-logging-1.1.1.jar:/home/biadmin/hadoop_jars/commons-configuration-1.8.jar:/home/biadmin/hadoop_jars/commons-lang-2.4.jar
But, I realized that if I open a new terminal and echo $CLASSPATH, it displays only the Class Path Before. It doesn't reflect the changes I made to the classpath. i.e. it doesn't show Class Path After.
How to fix this?
Thanks,
Mahalakshmi
What is the main class listed in MANIFEST.MF? If you unjar the jar, is it in the jarfile in the correct location?

Categories