Using one-jar to build one jar file - java

I'm trying to use one-jar to generate one jar file that contains clojure jar file and java class file: Creating one jar file that for execution from Java/Clojure
Following the instruction, I could generate directories using one-jar-appgen-0.97.jar. As instructed, I replaced the java source, and added the ThingOne-1.0.0-SNAPSHOT-standalone.jar
Running ant, it builds jar file without an error, but I got error messages when I try to execute the jar file.
java -jar build/test-one-jar.jar
test_one_jar main entry point, args=[]
Hello from Java!
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.simontuffs.onejar.Boot.run(Boot.java:342)
at com.simontuffs.onejar.Boot.main(Boot.java:168)
Caused by: java.lang.ExceptionInInitializerError
at clojure.lang.Namespace.<init>(Namespace.java:34)
at clojure.lang.Namespace.findOrCreate(Namespace.java:176)
at clojure.lang.Var.internPrivate(Var.java:149)
at ThingOne.core.<clinit>(Unknown Source)
at onejar.main.TestOneJarMain.run(TestOneJarMain.java:27)
at onejar.main.TestOneJarMain.main(TestOneJarMain.java:20)
... 6 more
Caused by: java.lang.NullPointerException
at clojure.lang.RT.lastModified(RT.java:374)
at clojure.lang.RT.load(RT.java:408)
at clojure.lang.RT.load(RT.java:398)
at clojure.lang.RT.doInit(RT.java:434)
at clojure.lang.RT.<clinit>(RT.java:316)
... 12 more
What might be wrong?

Lines 168 and 342 in the Boot.java class of One-Jar indicate a problem with setting properties. This problem is happening when unit tests fail. My guess is it's related to bug 3090800 in the SourceForge One-Jar Bug Tracker.

Related

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger after creating an executable JAR but this is a JAVA Project

I have a JAVA (awt) Project to build a desktop base utility. When I try to run this from other machine with only JRE Installed this is giving an exception as
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at DataProcessor.DataProcessor.App.<clinit>(App.java:73)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:56)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
here I am not using a maven project, creating an executable JAR directly from eclipse. All though I see the JAR for log4J (log4j-1.2.17.jar) in the MANIFEST. But this is giving an exception when I try to run it from other machines. ( Other machines has only JRE not JDK) following command I am using to run JAR
C:\Users\<username>\Desktop\Utility\latest>"C:\Program Files\Java\jre1.8.0_161\bin\java.exe" -jar Utility.jar
The exception is sayin' that you don't have the log4j dependency found on your class path: are you providing the log4j.jar in the same folder as the one in which your jar is placed?
It is not so easy to reference other jars when running an application as java -jar yourApp.jar ...
You can take a look to this post about this referencing a jar when running another one;
If you want to investigate about MANIFEST usage, take a look here;
However, i suggest you to use maven (or do it manually) exporting a fatjar with the needed dependencies packaged into (take a look to maven-assembler plugin or Eclipse runnable jar export options).

"No dependency satisfies type class org.neo4j.kernel.api.index.SchemaIndexProvider" when building über-jar

I have manually downloaded and added the libraries log4j, jsoup and neo4j for a project in Intellij Idea.
Before adding neo4j, I could build a jar as an artifact with all the libraries extracted to it so i could directly copy it somewhere and run with java -jar file.jar.
When I run the application in IntelliJ Idea it always works!
Now i get the following error when running the jar:
Error: A JNI error has occurred, please check your installation and try again Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
at sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:314)
at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:268)
at java.util.jar.JarVerifier.processEntry(JarVerifier.java:316)
at java.util.jar.JarVerifier.update(JarVerifier.java:228)
at java.util.jar.JarFile.initializeVerifier(JarFile.java:383)
at java.util.jar.JarFile.getInputStream(JarFile.java:450)
at sun.misc.JarIndex.getJarIndex(JarIndex.java:137)
at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:839)
at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:831)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:830)
at sun.misc.URLClassPath$JarLoader.<init>(URLClassPath.java:803)
at sun.misc.URLClassPath$3.run(URLClassPath.java:530)
at sun.misc.URLClassPath$3.run(URLClassPath.java:520)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:519)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:492)
at sun.misc.URLClassPath.getNextLoader(URLClassPath.java:457)
at sun.misc.URLClassPath.getResource(URLClassPath.java:211)
at java.net.URLClassLoader$1.run(URLClassLoader.java:365)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
I already searched for the error and found that a library seems to be signed and I can't just pack it into another jar, because it thinks it was modified then.
The suggested solution was to exclude the signing files through the build system.
I tried to manually delete the BCKEY.dsa and the BCKEY.sf files (only signing files in META-INF folder) in the resulting jar but then I get the following error:
Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.impl.factory.CommunityFacadeFactory, /home/xuiqzy/Documents/uni/4.Semester/PRG_practicum/WikiXtractor/data
at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:144)
at org.neo4j.kernel.impl.factory.CommunityFacadeFactory.newFacade(CommunityFacadeFactory.java:40)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:108)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newDatabase(GraphDatabaseFactory.java:100)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.lambda$createDatabaseCreator$0(GraphDatabaseFactory.java:89)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:183)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:65)
at de.bened.wikixtractor.DatabaseManager.initialize(DatabaseManager.java:43)
at de.bened.wikixtractor.Main.main(Main.java:83)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.NeoStoreDataSource#5c67716' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:444)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107)
at org.neo4j.kernel.impl.transaction.state.DataSourceManager.start(DataSourceManager.java:99)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:434)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:107)
at org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory.newFacade(GraphDatabaseFacadeFactory.java:140)
... 8 more
Caused by: org.neo4j.kernel.impl.util.UnsatisfiedDependencyException: No dependency satisfies type class org.neo4j.kernel.api.index.SchemaIndexProvider
at org.neo4j.kernel.impl.util.Dependencies.resolveDependency(Dependencies.java:71)
at org.neo4j.kernel.impl.util.Dependencies.resolveDependency(Dependencies.java:67)
at org.neo4j.kernel.NeoStoreDataSource.start(NeoStoreDataSource.java:418)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:434)
... 13 more
I also searched that error, a META-INF/services/org.neo4j.kernel.extension.KernelExtensionFactory file exists in my jar, there are also the jars lucene-analyzers-commen, lucene-codecs, lucene-core, lucene-queryparser, neo4j-lucene-index and neo4j-lucene-upgrade all integrated in the über-jar and the build in IntelliJ Idea seems to have enough dependencies, too.
So I'm a bit clueless why the jar doesn't work as opposed to the build in the IDE.
Long term I'm willing to switch to a build system but for now:
Is there a way to get the jar to run?
Any help or pointers in the right direction are appreciated! :)

UnsatisfiedLinkError when running Jetty9's setUID feature

I just tried to run Jetty 9 as non root users, using setuid feature without success for binding low port numbers.
I enabled the module setuid in the start.ini and added -Djava.library.path=/opt/jetty/lib/setuid
But I have the following stack trace when starting Jetty:
2015-06-09 16:27:27.211:WARN:oejx.XmlConfiguration:main: Config error
at | |
java.lang.reflect.InvocationTargetException in
file:/opt/jetty/etc/jetty-setuid.xml
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jetty.start.Main.invokeMain(Main.java:321)
at org.eclipse.jetty.start.Main.start(Main.java:817)
at org.eclipse.jetty.start.Main.main(Main.java:112) Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.set(XmlConfiguration.java:479)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:411)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:815)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.itemValue(XmlConfiguration.java:1125)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.value(XmlConfiguration.java:1030)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.call(XmlConfiguration.java:721)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:417)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:354)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:262)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1243)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1174)
... 7 more Caused by: java.lang.UnsatisfiedLinkError: org.eclipse.jetty.setuid.SetUID.getpwnam(Ljava/lang/String;)Lorg/eclipse/jetty/setuid/Passwd;
at org.eclipse.jetty.setuid.SetUID.getpwnam(Native Method)
at org.eclipse.jetty.setuid.SetUIDListener.setUsername(SetUIDListener.java:53)
... 23 more
Those are the only references to this error:
dev.eclipse.org/mhonarc/lists/jetty-users/msg01657.html
groups.google.com/forum/#!topic/dropwizard-user/aap2B_U_QPo
But they are either stopped or do not show the solution.
The source code I found for the setuid package is:
https://github.com/jetty-project/codehaus-jetty-project/blob/master/jetty-setuid/modules/java/src/main/java/org/mortbay/setuid/SetUID.java
Even though I cannot be sure this is the version I am using, given this one is from a org.mortbay package, while the one Jetty 9 uses is an Eclipse one.
I tried setting -Djetty.libsetuid.path in the java args (first try-catch block), either adding the path to the $PATH variable or setting -Djava.library.path (second try-catch block) or copying the so to /lib and, finally, leaving it as it is (third try-catch block). I got the same exception stack in all the cases.
I cannot be sure if Jetty is either not finding the so file or not being able to load it, given that, if I remove all the references to the path (the cases I described latter), I still get the same error message.
I use Java7 to run Jetty.
Edit
I added the following snippet to one of my webapps as as matter of test, given that if the webapp succeed, I would know the problem is not in finding the shared object:
SetUID.setgid(1002);
SetUID.setuid(1002);
Passwd pw = SetUID.getpwuid(1002);
System.setProperty("user.name", pw.getPwName());
System.setProperty("user.home", pw.getPwDir());
I have the same UnsatisfiedLinkError as a result.
Edit2
I tried, instead, the following:
System.load(SetUID.__FILENAME);
SetUID.setgid(1002);
Which got me the following error message:
javax.servlet.ServletException: java.lang.UnsatisfiedLinkError: Native
Library /lib/libsetuid.so already loaded in another classloader
I may conclude, therefore, that the library has been loaded, at least.
Exploring the libsetuid file (nm -D /path/to/the/so), I realized that the so I was using was outdated and was not compatible with Jetty 9, the functions were named as mortbay:
root#root:~/# nm -D libsetuid.so --size-sort | less
0000000000000010 T Java_org_mortbay_setuid_SetUID_setgid
0000000000000010 T Java_org_mortbay_setuid_SetUID_setuid
0000000000000015 T Java_org_mortbay_setuid_SetUID_setumask
0000000000000018 T throwNewJavaSecurityException 0000000000000058 T
throwNewJavaException 000000000000008e T
Java_org_mortbay_setuid_SetUID_setrlimitnofiles 00000000000000a7 T
getJavaMethodId 00000000000000f5 T
Java_org_mortbay_setuid_SetUID_getrlimitnofiles 0000000000000102 T
getJavaFieldInt 0000000000000111 T setJavaFieldInt 0000000000000111 T
setJavaFieldLong 0000000000000121 T setJavaFieldString
00000000000001ba T Java_org_mortbay_setuid_SetUID_getpwuid
00000000000001e5 T Java_org_mortbay_setuid_SetUID_getpwnam
000000000000027e T Java_org_mortbay_setuid_SetUID_getgrgid
000000000000029e T Java_org_mortbay_setuid_SetUID_getgrnam
Now, I am using the shared object that already comes in the jetty download, not the one linked in the wiki.
In addition to that, looking through the code of the setuid module, I decided using the property -Djetty.libsetuid.path in my java args for indicating the absolute path of the lib, e.g., -Djetty.libsetuid.path=/opt/jetty/lib/setuid.so

Jar file with Jaudiotagger, NoClassDefFoundError

I made a java class using the library Jaudiotagger, and it runs without problems. I then made a jar out of it and I got NoClassDefFoundError. Here's how it went:
I put the main class id3tag.java and the library jaudiotagger-2.0.3.jar in a folder and compiled using the command line. The program ran smoothly without problems.
javac -cp .;jaudiotagger-2.0.3.jar id3tag.java
java -cp .;jaudiotagger-2.0.3.jar id3tag
I then created the manifest and the jar file.
echo Main-Class: id3tag >manifest.txt
jar cvfm id3tag.jar manifest.txt id3tag.class jaudiotagger-2.0.3.jar
I got the following output:
added manifest
adding: id3tag.class(in = 5952) (out= 2997)(deflated 49%)
adding: jaudiotagger-2.0.3.jar(in = 811441) (out= 740599)(deflated 8%)
I then ran the jar file, and got "A Java Exception has occurred.". I also tried:
java -jar id3tag.jar
And I got the output:
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaudiotagger/tag/
FieldDataInvalidException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.getMethod0(Class.java:2694)
at java.lang.Class.getMethod(Class.java:1622)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.jaudiotagger.tag.FieldDataInval
idException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 6 more
I then replaced all (both) error classes used from Jaudiotagger with Exception and recreated the jar. Now the same thing happens as for seemingly all other jar files when I run them (with Java(TM) Platform SE binary, or through writing id3tag.jar in the command prompt) - nothing. java -jar, however, works and gave me a runtime error.
Exception in thread "main" java.lang.NoClassDefFoundError: org/jaudiotagger/audi
o/AudioFileIO
at id3tag.tagSong(id3tag.java:112)
at id3tag.tagAlbum(id3tag.java:82)
at id3tag.tagArtist(id3tag.java:40)
at id3tag.main(id3tag.java:170)
Caused by: java.lang.ClassNotFoundException: org.jaudiotagger.audio.AudioFileIO
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 4 more
It seems like the entire library just doesn't do shit for me. How do I fix this, and how do I get jar files to run without java -jar? (Also, how do I get the full pile'o'errors in case someone needs it, rather than just having it say "x more"?)
I'm not very savvy with this kinda shit so the more specific the answer, the better. Thanks.
I'm on windows 8 and latest java (1.7.0_17).
this is informing you that you have no main class, as you might or might not already know all programs in almost all non web based programming languages must have a main class to start from. In java it looks like this
public static int main(String[] args){
}
The message is informing you that this class is no longer there, this could be a compiler error or something entirely different.
please try downloading the library again, and downloading eclipse ide for java ee developers.
this ide has a built in compiler that will work better than a command line sometimes.
i hope this helped.
I worked around it by including the org folder from jaudiotagger in my .jar instead of the actual .jar file, and I then used a .bat file to run it instead of running the .jar directly. Feel free to add your own answer if you find a better solution, and I'll check back.
I extracted jaudiotagger-2.0.3.jar with winrar so that the org folder was in the same folder as my main class. Then I could compile and run the main class simply by:
javac id3tag.java
java id3tag
I then created the manifest file the same way as before, and created the jar:
jar cvfm id3tag.jar manifest.txt id3tag.class org
The jar file worked with java -jar id3tag.jar, but simply writing id3tag.jar still did nothing. Turns out it's because jar files are by default run by the javaw.exe file, so you have to right click the jar file -> open with -> choose default program and navigate to the java.exe file in your java folder (just search the folder). Running the .jar then gets you "Error: Could not find or load main class path\id3tag.jar". I worked around this by using a .bat file. I entered
java -jar path\id3tag.jar
into Notepad and saved as whatevername.bat (save as type: all files).
I created a new question for getting the .jar file to work properly. See .jar error - could not find or load main class.

Making an executable jar that evals Clojure strings

I'm building a Java app that loads Clojure files. I'm having trouble making a single executable jar. I'm using One-Jar, but I get an exception when I try to run the jar file:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.simontuffs.onejar.Boot.run(Boot.java:340)
at com.simontuffs.onejar.Boot.main(Boot.java:166)
Caused by: java.lang.ExceptionInInitializerError
at com.ziroby.clojure.App.main(App.java:14)
... 6 more
Caused by: java.lang.NullPointerException
at clojure.lang.RT.lastModified(RT.java:374)
at clojure.lang.RT.load(RT.java:408)
at clojure.lang.RT.load(RT.java:398)
at clojure.lang.RT.doInit(RT.java:434)
at clojure.lang.RT.<clinit>(RT.java:316)
... 7 more
When I look at the line that's causing it, it seems to be trying to get jar information for the relative class files:
return ((JarURLConnection) url.openConnection()).getJarFile()
.getEntry(libfile).getTime();
I think this means that it's trying to get jar information for an embedded jar, which doesn't actually exist on the file system. It's looking at that to see if it needs to recompile a file (like common/core.clj).
Am I doing something wrong? Is there some other way to create an executable jar (with dependencies) without confusing Clojure?
I have come to the conclusion that this is a bug in Clojure. I am able to add a single null check (just before the .getTime() call), and it works correctly. I've entered a bug in Clojure's Jira: http://dev.clojure.org/jira/browse/CLJ-971

Categories