I am using eclipse to create a runnable jar. During runtime my code looks through the classpath for a config file, which it reads in. However, as a runnable jar it is not finding this config file.
I guess the config file will need to exist as a seperate entity on the filesystem somewhere. How do I specify the classpath in the Manifest to include this location when eclipse creates the runnable jar?
Thanks
Ensure your config file is under an eclipse source folder:
I use
src\main
src\test
src\resources
All three are folders, added to the Eclipse project as source folders
If I add three files (one.xml, one.properties and one.config) to the src/main/package/ folder and then export a runnable jar they all appear in the runnable jar.
Related
I am trying to excute runnable jar file which is exported from eclipse wizard of my local project which have "sapjco3.jar" in build path. So, as soon as i try to execute jar file it gets following error:
Illegal JCo archive "autobot.jar"(is my local jar file of my project).
It is not allowed to rename or repackage the original archive "sapjco3.jar".
above problem occours while establishing java SAP connection(lib: "sapjco3.jar") at runtime.
Note: I am not Renaming or repackging Original sapjco3.jar
You can also create your own runnable jar, but then you have keep the sapjco3.jar file separate from your runnable jar and just include the 'sapjco3.jar' in its class path, e.g. specify in your MANIFEST.MF:
Class-Path: <path>/sapjco3.jar
If using the eclipse Runnable JAR File export wizard this is achieved by selecting the library handling option:
Copy required libraries into a sub-folder next to the generated JAR
You cannot include sapjco3.jar in a runnable jar, as Eclipse is trying to do. Include it in the classpath.
I had sapjco version 3.1.2, to fix it i change by 3.0.10, the solution that worked for me is in the follow link:
https://jira.talendforge.org/browse/TUP-23506?_ga=2.92427421.1653413528.1593728315-903540588.1593728315
When I try to run the jar file creating by eclipse Iv been getting a bunch of errors.
I unarchive the jar file and saw it had 3 of the 4 lib files (all external)
The lib files are
commen2-logging-1.2.jar
jason-2.4.jar
httpclient.4.5.1.jar
httpcore-4.4.4.jar
the one that does not get included is
commen2-logging-1.2.jar
what I did
1. removed jar files, put them all in same foil,er, added them to project again
2. created a new project
you need to export your project as a runnable jar and check the choice "package required librarie into generated jar..."
I am using Java Simple Plugin Framework. I export a jar that has my plugin implementation. The implementation depends on a library, which I have as a jar. That jar gets exported within the lib directory of my jar, and added to the classpath of my jar.
But when I load my jar with JSPF, it fails with "NoClassDefFound" because it can't find the jar in the lib director of my jar.
My apologies if my approach off base; I just need to know how this is supposed to be done. How should I bundle my plugin implementation as a jar if it depends on another jar?
I used JSPF and achieved this requirement the following way:
place the library jar file in a folder called lib outside the plugin jar file. (So that
the lib folder and the plugin jar file is in the same folder). Then I added lib/"name_of_libjar" to the classpath entry in the manifest.mf file of the plugin jar file (Which should be inside the plugin jar files META-INF folder), and it worked fine for me.
I am building an assembly in Maven for a command line utility. I can run it as an executable jar, but it fails because I need to load the config file externally. Assuming the following config, how would I run the jar?
Jar is in /opt/myapp/lib/myapp-assembly.jar
Config is in /etc/myapp/config/settings.xml
I'm loading the code from the classpath using ClassPathResource("/settings.xml");
Any help is appreciated!
I see two ways you could do it:
Launch the program using the jar as an archive rather than an executable jar, specifying the main class at run time. In other words, do java -classpath /opt/myapp/lib/myapp-assembly.jar:/etc/myapp/config [name of your main class].
Use the Class-Path field of the jar manifest file. Entries in it are directly added to the run time classpath, and there's nothing stopping you from specifying a filesystem directory rather than another jar file. So your manifest would contain: Class-Path: /etc/myapp/config/
I created a JAR file from my java project.
Using Eclipse, I added a JAR as a referenced library in my own project.
However, now when I try to run my program's JAR using java -jar myProgram.jar, I get an exception stating that my referenced jar is not available.
So how can I create a JAR consisting a reference to a different JAR and make it work?
Right, an executable JAR cannot contain its own JAR dependencies.
You have to have the main class and classpath set in the executable JAR manifest, then package all your JAR dependencies along with the executable JAR in a relative directory structure that matches the manifest CLASSPATH. Reading this might help.
You need to use Eclipse's runnable JAR exporter. Since Eclipse 3.5 you've the following options when you rightclick project, choose Export > Runnable JAR file:
Either way, Eclipse should take care that you'll be able to run the JAR the way you want on the exported location.
See jarjar project. It is exactly what you are looking for. http://code.google.com/p/jarjar/