I wanted to upload some .java files on github, I don't remember if I uploaded the right files. I have been told that the files I should've submitted were missing. I checked the last commit, and the files I should've submitted were marked with "BIN" and were of type "classname".class instead of "classname".java, underneath each one of them it says "Binary file not shown" instead of the code. I would like to know what happened so that I can avoid this in the future. I have never experienced this before on github. What did I upload? I don't think I had any .class files regarding this project.
From what you say seems like you added files to your commit that shouldn't be added.
Well, to fix this, just remove those files, commit and push the changes. Done.
To avoid this scenario in the future and not only for you but for your team, you can create a .gitignore file at the root of the repository. This file contains patterns of paths (files and folders) so git will ignore those files when showing the state of the branch. If there's no such .gitignore file then create one and add the following:
*.class
bin/
Also, you can add more entries in this file to support omitting other files generated by IDE, for example. There are curated lists you can find like https://gist.github.com/chhh/4961200 or https://www.gitignore.io/api/eclipse
/bin is usually a folder that contains binary files or compiled stuff in general. You should never put it in a repo.
It's not dangerous, but it wastes space and it's something that has to be compiled in each one's computer anyway, so it's pointless to put them in the repo :)
Related
I have two issues i would like to get fixed, yet in my attempt to fix the issues i have managed to descend down to an angry primate screaming and shouting at my pc.
Here are my issues (some of which cannot be solved by an online community),
Earlier today i thought it would be a great idea to create a folder called "res", res would be used to store images and wav files for a game i am making. Now, if the wav file i am testing is not inside this folder and the directory to the wav file is right it works fine, it looks like this ".getResource(fileName);". But when i do have the wav file in the "res" folder, i changed the directory to the following .getResource("res/"+fileName); i get the following
warning: [options] bootstrap class path not set in conjunction with -source 1.6
1 warning
as well as a nullPointerException pointing to all the stuff relating to sound.
So after being incredibly frustrated, i removed "res" folder, then the project stopped compiling as it cannot find "res", so i recreated res folder, keeping the wav file out of it which worked just fine. I then felt happy about it and thought, ya i'm done for a while, lets commit this to SVN.
On attempt to commit my work i get a "is already under version control" error for the "res" folder
so to recap this
i created a folder called "res" in my project folder (via netbeans)
i put a wav file into "res" and found it threw errors
i removed the wav file from "res" and it worked just fine
i deleted res folder and project refused to compile without this very important folder
i recreated res folder and then tried to commit my work to SVN and SVN doesn't want my children anymore.
I am now left with children i cannot put somewhere safe and an unwanted ghost in my house (folder in my project folder that wont do anything)
assistance, as always is greatfully accepted and welcomed.
With respect to the SVN problem:
NB tends to add or delete directories on SVN automatically (but not commit) and it might be confused after the delete/recreation.
I'd suggest using a different tool (SVN command line or TortoiseSVN, for example) to verify which operations does SVN are pending and try reverting operations on the res directory. If SVN marks res as existing then you might try veryfing that the directory is not already on the repository.
Also you might remove the SVN cache from your Netbeans directory (previously called %HOME%\.netbeans\cache\svn and now (NB 7.2) changed to %HOME%\Netbeans\Cache\7.2\svncache.
An extreme solution would be to make a new checkout and copy your changes from the old working copy to the new one.
I have a project set-up with two source folders. Folder1 is an automatically generated set of java source files that I don't want to touch, Folder2 is a folder with slight edits of some of these files.
What I want the compiler to do is ignoring the files from Folder1 if there's an edited file in Folder2.
I tried finding how to turn off the "Type X is already defined" error in Eclipse, but I can't find it under Errors/Warnings in the settings. I assume turning off this error and setting the order correctly will make the compiler use the correct file of the two.
What I don't want, obviously, is excluding all duplicates in Folder1 from the build path by hand. I don't necessarily want you to fix my set-up, if there's a better way entirely to set this up, feel free to suggest. Do remember that whatever happens, all of the sources need to end up in the same bin folder, due to a path complexity I can't solve. I'd also like to stay clear of build scripts if at all possible.
You can create two projects:
prj1 has only Folder1 and
prj2 has only Folder2. prj1 is listed as a required project on prj2. That way sources in Folder2 will override the ones in Folder1.
When this kind of problem occurs to me, I use SVN, I cautiously create a new branch, and work on it.
After, it is up to you to migrate intricated pathes here.
If as Dave Newton said, you can consider it is a broken project, this may help you to save it.
For your requirement of:
...ignore files from Folder1 if there is an edited file in Folder2...
You need an overlay/union file system in which there is
a RO mount that contains your original file set
a RW mount that initially contains nothing
an overlay/union mount for use by an application
When an application updates a file, the file system saves the file to the RW location. The file system always hides a file in the RO location once a file by the same name exists in the RW location.
The concept will sound strange at first.
Ask google to show you "What is an overylay filesystem" and "What is a union filesystem" to learn more.
How do I clean up stale .class files out of ${workdir} given set of existing .java files in ${srcdir}? By stale I mean .class files that were generated from now removed .java files. I have tried coming up with something using Ant mappers and filesets etc. but I failed. Removing all .class files older than their respective source .java files would be acceptable, too.
I'm pretty sure there's an ant task to kill .classes older than the .java...
Depend sounds close, and may actually do what you want, but this isn't its intended purpose. Given developmentalinsanity's answer however, this may be the only thing that will Actually Work.
The problem is determining whether a class file without an obviously corresponding source file is really stale.
Try this in a single file (A.java)
public class A{}
class B{}
This will result in both A.class and B.class. So, B.class would seem stale because of the missing java file. You'd probably get similar issues with any inner classes.
Safest bet if you want to make sure there's no old class files lying around would be just to delete them all.
As it’s just not possible to detect what’s stale and what’s not, most builds have a clean target (that’s also part of cleanbuild). The clean target, just removes all files from you’re build directory. This directory normally is unversioned (svn:ignore).
Not all files in you’re build will be the result of the compiler, for example .property files, these files can be stored in an alternative directory that will be copies in to the build directory. For example in a web application build you can store those files in /web/WEB-INF/classes and let Ant copy them into the build directory.
I would like to modify a file inside my jar. Is it possible to do this without extracting and re jarring, from within my application?
File i want to modify are configuration files, mostly xml based.
The reason i am interested in not un jarring is that the application is wrapped with launch4j if i unjar it i can't create the .exe file again.
You can use the u option for jar
From the Java Tutorials:
jar uf jar-file input-file(s)
"Any files already in the archive having the same pathname as a file being added will be overwritten."
See Updating a JAR File.
Much better than making the whole jar all over again. Invoking this from within your program sounds possible too. Try Running Command Line in Java
You can use Vim:
vim my.jar
Vim is able to edit compressed text files, given you have unzip in your environment.
Java jar files are the same format as zip files - so if you have a zip file utility that would let you modify an archive, you have your foot in the door. Second problem is, if you want to recompile a class or something, you probably will just have to re-build the jar; but a text file or something (xml, for instance) should be easily enough modified.
As many have said, you can't change a file in a JAR without recanning the JAR. It's even worse with Launch4J, you have to rebuild the EXE once you change the JAR. So don't go this route.
It's generally bad idea to put configuration files in the JAR. Here is my suggestion. Search for your configuration file in some pre-determined locations (like home directory, \Program Files\ etc). If you find a configuration file, use it. Otherwise, use the one in the JAR as fallback. If you do this, you just need to write the configuration file in the pre-determined location and the program will pick it up.
Another benefit of this approach is that the modified configuration file doesn't get overwritten if you upgrade your software.
Not sure if this help, but you can edit without extracting:
Open the jar file from vi editor
Select the file you want to edit from the list
Press enter to open the file do the changers and save it
pretty simple
Check the blog post for more details
http://vinurip.blogspot.com/2015/04/how-to-edit-contents-of-jar-file-on-mac.html
I have similar issue where I need to modify/update a xml file inside a jar file.
The jar file is created by a Spring-boot application and the location of the file is BOOT-INF/classes/properties
I was referring this document and trying to replace/update the file with this command:
jar uf myapp.jar BOOT-INF/classes/properties/test.xml
But with this, it wont change the file at the given location. I tried all the options also but wont work.
Note: The command I am executing from the location where jar file is present.
The solution I found is:
From the current location of jar file, I created folders BOOT-INF/classes/properties
Copy the test.xml file into the location BOOT-INF/classes/properties.
Run the same command again. jar uf myapp.jar BOOT-INF/classes/properties/test.xml
The xml file has been changed in the jar file.
Basically you need to create a folder structure like where the file is located into the jar file. Copy the file at that location and then execute the command.
The problem with the documentation is that, it does not have enough examples as well as explanation around common scenarios.
This may be more work than you're looking to deal with in the short term, but I suspect in the long term it would be very beneficial for you to look into using Ant (or Maven, or even Bazel) instead of building jar's manually. That way you can just click on the ant file (if you use Eclipse) and rebuild the jar.
Alternatively, you may want to actually not have these config files in the jar at all - if you're expecting to need to replace these files regularly, or if it's supposed to be distributed to multiple parties, the config file should not be part of the jar at all.
To expand on what dfa said, the reason is because the jar file is set up like a zip file. If you want to modify the file, you must read out all of the entries, modify the one you want to change, and then write the entries back into the jar file. I have had to do this before, and that was the only way I could find to do it.
EDIT
Note that this is using the internal to Java jar file editors, which are file streams. I am sure there is a way to do it, you could read the entire jar into memory, modify everything, then write back out to a file stream. That is what I believe utilities like 7-Zip and others are doing, as I believe the ToC of a zip header has to be defined at write time. However, I could be wrong.
Yes you can, using SQLite you can read from or write to a database from within the jar file, so that you won't have to extract and then re jar it, follow my post http://shoaibinamdar.in/blog/?p=313
using the syntax "jdbc:sqlite::resource:" you would be able to read and write to a database from within the jar file
Check out TrueZip.
It does exactly what you want (to edit files inline inside a jar file), through a virtual file system API. It also supports nested archives (jar inside a jar) as well.
Extract jar file for ex. with winrar and use CAVAJ:
Cavaj Java Decompiler is a graphical freeware utility that reconstructs Java source code from CLASS files.
here is video tutorial if you need:
https://www.youtube.com/watch?v=ByLUeem7680
The simplest way I've found to do this in Windows is with WinRAR:
Right-click on the file and choose "Open with WinRAR" from the context menu.
Navigate to the file to be edited and double-click on it to open it in the default editor.
After making the changes, save and exit the editor.
A dialogue will then appear asking if you wish to update the file in the archive - choose "Yes" and the JAR will be updated.
most of the answers above saying you can't do it for class file.
Even if you want to update class file you can do that also.
All you need to do is that drag and drop the class file from your workspace in the jar.
In case you want to verify your changes in class file , you can do it using a decompiler like jd-gui.
As long as this file isn't .class, i.e. resource file or manifest file - you can.
I'm trying to update a file in an existing jar (in this example antlr) using the command:
jar -uf antlrworks-1.2.3.jar org/antlr/codegen/templates/Java/Java.stg
But I get the following message
java.util.zip.ZipException: duplicate entry: antlr/ANTLRError.class
at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:175)
at java.util.jar.JarOutputStream.putNextEntry(JarOutputStream.java:92)
at sun.tools.jar.Main.update(Main.java:508)
at sun.tools.jar.Main.run(Main.java:185)
at sun.tools.jar.Main.main(Main.java:1044)
Any ideas?
You're trying to do the right thing, but the jar file is problematic - it's got the same entry twice :( (This is legal for a zip file, but not really helpful - and as you can see, it makes jar complain.)
If you run
jar tvf antlrworks-1.2.3.jar > contents
and then look at the generated contents file you'll see that there are various duplicate files. You should probably report this to the antlr project (after checking they don't already know).
As a workaround, you can extract the contents of the jar file, jar it up again, and then you'll have a "working" jar file you can update. (If you only need to do this once, you can just extract, put the file you want in there, and then jar the whole lot up rather than updating it afterwards.)
You can do the same operation with the Ant jar task.
<jar duplicate="preserve" jarfile="...">
your files
</jar>
the duplicate attribute with the preserve value will take care of the duplicate entries.
As mentioned here, the update attribute with the value “preserve” does tell you that duplicates exist, in this form:
aPath/aFile already added, skipping
If your file is on top of the list the jar task has to pick tp build itself, your new file will be taken into account.
If you're on OS X, try the Jar Inspector application. I used it to patch a javascript bug in wicket. You can open a jar file, and it lists all the contents. Navigate to the file you want to save (in this case, a .js file) and modify the file, then save the contents, and it takes care of modifying the .jar file for you. Not sure if this would work with .java files or not.