Simply try Export --> JAR file instead of exporting Runnable JAR file : it allows you to select multiple resources to include in the generated archive.
Up vote 1 down vote favorite share g+ share fb share tw.
I have a directory of arbitrary files I want to include in my jar - however, I cannot figure out a way to do so that works with export -> "Runnable jar". I've tried the trick of making the directory a 'source path' but it is still absent when I build the jar. I realize I can manually add them into the jar (it is just a zip, after all) - or I could use an ant script or other build system - but I'm looking for something that works for an out-of-the-box Eclipse "Java project".
Here's an example. I want to try to load log4j. Properties if it exists.
If not, I want to write it out from an included 'default' in my jarfile. Finally, it loads the defaults if that fails. Note that I have no idea yet if the code below works, it will likely need tweaking.
I'm not asking for help with that, I'm just giving context for what I want to do. // initialize logging libraries File log4jFile = new File("log4j. Properties"); if (log4jFile.exists() & log4jFile.canRead()) { PropertyConfigurator.
Configure(log4jFile.getAbsolutePath()); } else { try { InputStream log4jJarstream = Main.class. GetResourceAsStream(sepd + "resources" + sep + "log4j. Properties"); OutputStream outStream = new FileOutputStream(new File("log4j.
Properties")); int read = 0; byte bytes = new byte1024; while ((read = log4jJarstream. Read(bytes))! = -1) { outStream.
Write(bytes, 0, read); } log4jJarstream.close(); outStream.flush(); outStream.close(); } catch (Exception e) { BasicConfigurator.configure(); log. Warn("Error writing log4j. Properties, falling back to defaults.
"); } } java eclipse build jar executable-jar link|improve this question asked Jan 13 at 19:31draeath1165.
Simply try Export --> JAR file instead of exporting Runnable JAR file: it allows you to select multiple resources to include in the generated archive. You can also specify the Main-Class property, just like with the latter option. BTW it is more convenient if you use some kind of build tool (like Ant target or the Maven Jar plugin).
If you use Eclipse to generate the JAR file, there is also an option to save an Ant buildfile that can do the task for you later on.
I already found the solution but cannot yet accept it. See my own answer to my question. – draeath Jan 14 at 20:13.
There was an error in the code loading the file as a resource... which it seems Eclipse "saw" and as such was refusing to package the file. I put the file along side the class files and altered the way I search for the file, and it packaged it with the . Class files and was able to be read during execution.
New code snippet: // initialize logging libraries File log4jFile = new File("log4j. Properties"); if (log4jFile.exists() & log4jFile.canRead()) { PropertyConfigurator. Configure("log4j.
Properties"); } else { try { InputStream log4jJarstream = Main.class. GetResourceAsStream("log4j. Properties"); OutputStream outStream = new FileOutputStream(new File("log4j.
Properties")); int read = 0; byte bytes = new byte1024; while ((read = log4jJarstream. Read(bytes))! = -1) { outStream.
Write(bytes, 0, read); } log4jJarstream.close(); outStream.flush(); outStream.close(); PropertyConfigurator. Configure("log4j. Properties"); } catch (Exception e) { BasicConfigurator.configure(); log.
Warn("Error writing log4j. Properties, falling back to defaults. "); log.
Warn(e); log. Warn("STACK TRACE:"); int I = 0; StackTraceElement trace = e.getStackTrace(); while (i Warn(tracei); i++; } } }.
I added the log4j. Properties to my src folder, and exported the jar as a runnable. It worked.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.