what I want is to regenerate sdovis.jar complete file, I took mapbuilder.jar tool, after that I unzip it using winrar, the result contains a folder named oracle, and I want generate from that folder a .jar file in order to use it in a specific project.
Thank you.
(You have winRar!) This should work with any unsigned jar:
Extract "original.jar" to (a new folder) /modify. (via context menu, or within a WinRar instance...the jar will open like a folder/zip/rar)
Apply your modifications to /modify.
(Per context menu/Or from within WinRar) Execute the "Add To Archive ..." dialog on /modify.
Use "ZIP" as the archiving format.
Rename the archive to "modified.jar".
Don't use a password!
Click Ok.
After this process and assuming that:
orginal.jar was a valid/working jar before
your modifications didn't break the validity (META-INF...) nor the functionality (so were correct).
... you should have a valid & working "modified.jar"!
Of course WinRar is not obligatory and can be replaced by any other (working) zip or (the) jar tool.
Related
I need to replace a single class file from a jar file. The jar file is quite big and every time I don't want to extract it and replace manually. I want to automate this procedure. Can someone please help me on this.
When jar file is extracted below folders are created :
render
classes
com
I need to go inside "com/cgp/f1/cmmi/" folder and replace a class file inside it.
Things I tried :
zip file.jar com/cgp/f1/cmmi/services.class Services.class
jar uf file.jar com/cgp/f1/cmmi/ services.class
jar -uf file.jar com\cgp\f1\cmmi\ services.class
jar uf file.jar com/cgp/f1/cmmi/services.class services.class
The error I am getting is :
when using jar command
com\cgp\f1\cmmi\ : no such file or directory
when using zip command :
zip warning: name not matched: com\cgp\f1\cmmi\Services.class
can some one please guide me where I am going wrong.
Maybe the jar -uf found here could help you: How to update one file in a zip archive
If graphical apps are an option, you could use winrar or 7-zip to replace the class. You don't need to extract the jar file to make this work. Just open the jar with one of those apps, go to de directory where is the class file to be replaced, drag-and-drop the new file to replace the old one and save.
I took the java implementation of the Factual API (reference http://developer.factual.com/) and made a JAR file for factual. I did this by opening a new project in eclipse with the factual java files and then exporting to a new jar file.
I put that jar file in my coldfusion installation's /WEB-INF/lib/ folder.
After restarting Coldfusion, I tried to create a new cfobject like so
<cfscript>
// Initialize the Java class.
factualClass=CreateObject("java", "src.main.java.com.factual.driver.Factual");
</cfscript>
I get an error indicating that it cannot find the Factual class.
Can anybody give me some guidance?
(Summary from comments)
It sounds like you may be exporting the source files ie *.java rather than the compiled class files, ie *.class. In the Jar Export wizard, be sure to select the "Export generated class files and resources" option. (To automatically compile the project sources before expi, enable the setting: JAR packaging > Build projects if not build automatically option). If you prefer you can also find pre-compiled jars in the MVN repository.
put that jar file in my coldfusion installation's /WEB-INF/lib/
folder.
CF10+ also supports dynamic class loading via a new application level setting THIS.javaSettings.
// Initialize the Java class.
factualClass=CreateObject("java", "src.main.java.com.factual.driver.Factual");
Just as a point of interest, src/main/java/ is not actually part of the libary class name. It is a standard directory structure used in Maven projects. It is probably included when exporting the sources, but not the compiled classes.
You can always verify the correct path and class name either by examining the API ie javadocs or by viewing one the source files. Package declarations are always at the top of the source file, such as on line 1 of src/main/java/com/factual/driver/Factual.java:
package com.factual.driver; // ie "com.factual.driver"
.. and the class declaration on line 39.
public class Factual { // ie "Factual"
Combined that gives you the exact (case-sensitive) path to use with createObject:
factualClass=CreateObject("java", "com.factual.driver.Factual");
We are programming a game, which shall be startable from a .jar file. First we created a Project in IntelliJ and loaded the Images from a ZIP with the following code:
ZipFile zf = null;
try {
zf = new ZipFile(zipPath);
Image Image = ImageIO.read(zf.getInputStream(zf.getEntry("Block/Air.png")));
} catch (IOException ignored) {}
Now the attempt without the ZIP (just from the .jar) is:
Image image=ImageIO.read(getClass().getResourceAsStream(path+ "Block/Air.png"));
It doesn't load any texture. Do you have a better way to do this in combination?
Edit:Seems not to be the Problem.
Since jars are zip files you could place them in the jar file and placing them the classpath.
Image image=ImageIO.read(getClass().getResourceAsStream(path+ "Block/Air.png");
Path must be a relative path from a source path root. E.g. I have a file in "src/main/resource/my/cool/game/" path is "/my/cool/game".
If you want to use a zip file, it must be outside of your jar file. To load the zip, you could use a relative file path, which is the same if you start your game from Intellij and from dekstop.
To change the working directory in intellij look here.
The best way would be to place the zip file alongside the jar so you can use "." as working directory to load the zip file.
Alternatively you could use a fixed directory, but then your game needs some sort of installation so it knows where to finde the zip file.
If you use ".", the zip file needs to be in the root of the project directory.
The Class.getResource and Class.getResourceAsStream methods take a URL (not a file path!) which is relative to the root of each classpath entry. For classpath entries which are .jar files, this means the path of a file packaged within the respective .jar file.
If your entire program is in one .jar file, the classpath consists of just one item: that .jar file. Therefore, there is only one classpath root, and the String you pass to getResourceAsStream is the URL of an entry within your .jar file. Do not include the path to the .jar file in that String.
If you are not sure what you should pass, examine your .jar file's contents. Every IDE (that I know of) provides a way to do this. You can also use any unzip utility to examine a .jar file, since every .jar file is actually a .zip file. (If you only have Windows, with no zip tools installed, make a copy of the .jar file and change the copy's extension to ".zip", then open it.)
Inside the .jar file are, of course, zip entries. The full path of the entry you want to load (without the path to the .jar file) is what you must pass to getResourceAsStream. getResourceAsStream accepts a URL, and URLs always use forward slashes (/) on all platforms, so do not use any backslashes. Also, the first character of the String must be /.
It is actually possible to specify a shorter path, depending on how your images are packaged in the .jar, but that is a separate topic. See the documentation for full details.
Side note: Never, ever write an empty catch block. Ever. That caught exception is by far the easiest way for you or anyone else to know when and why your program is not working. At the very least, put exc.printStackTrace(); in your catch block. More often, the correct course of action is to abort the program with something like throw new RuntimeException(exc);. After all, your program can't continue to function properly if it can't load that image, right?
Why do you need to store your images in a zip file? If you're doing it to reduce the file size, you gain absolutely nothing from zipping it first. JAR files are zipped files anyway (if you don't believe me, rename your .jar file to .zip, and try to open it). What you're basically doing is attempting to zip an already zipped file, which doesn't really do anything.
I would recommend you unzip your images and store them somewhere like < resources >/images
If you insist on leaving them zipped, you'll need to change it to something like this. Otherwise, it's looking for the zip file in the working directory (directory from which the jar was executed)
ZipFile zf = new ZipFile(getClass().getResourcesAsStream("path/to/zip"));
Disclaimer: I am not familiar with the ZipFile class, so I do not know if that constructor exists.
I have a JAR file that I wanted to edit a string inside on of it's classes . So I extracted it using Winrar , done the changes I wanted and saved it . Now I have a folder with subfolders inside that contains class files (about 30 one) .My question here is how can I recreate the Jar file from those folders&files ? Like it's it's doing the reverse action of extracting the Jar file .. ?
You could create a .zip file, rename it (with WinRAR) to something.jar so it becomes a .jar archive and then copy the folders in there.
But what you are doing is not really recommended to be done
You shouldn't extract and re-archive it like that.
And DON'T I repeat DON'T edit .class files!
Jar file is basically a zip file - however the best way to edit jars is to use a file manager (like Total Commander). You can delete, copy, rename, ... whatever, transparently inside the archive.
http://en.wikipedia.org/wiki/JAR_%28file_format%29
May be only one tip for the Total Commander - to enter the archive just use Ctrl-Pagedown. And I don't think that is something wrong on jar editing (in some circumstances you have no other option). However class files editing... it is a different game ...
my problem is that I want to add some .class files from a normal directory into an .jar file. Do I have to extract it before or can I add the files "on the fly"?
Although I agree with Jordan and suggest using the system command, that was not an option for the team I work on.
If you have to use his second solution, it is extremely important to note that Zip::ZipOutputStream will override any existing jars; i.e., you won't be adding to an existing jar, you will be creating a new one. This code will add a file to an existing jar:
require 'zip/zip'
Zip::ZipFile::open 'path/to/jar' do |jar|
jar.add 'filename_in_jar', 'path/to/file/you/want/to/add'
end
If it was me I would almost certainly just call the jar command within Ruby to do this:
system 'jar uf jar_file.jar input_file(s).class'
# or
%x[ 'jar uf jar_file.jar input_file(s).class' ]
Reference here.
If you still want to do this without calling jar you should be able to do it with rubyzip, since JAR files are just ZIP files with a particular structure. Something like this:
require 'zip/zip'
filename = 'class_file.class'
Zip::ZipOutputStream::open "jar_file.jar" do |zip|
zip.put_next_entry 'dest/path/in/jar/' + filename # don't forget the path
File.open filename, 'rb' {|f| zip.write f.read }
end
There are also a few Ruby wrappers for libarchive that could do this. E.g.