I would like to know how to create a jar file that preserves the file permissions of its content.
I'm packaging up source and executables in a jar file that will be extracted before use. People should be able to immediately run the examples and demonstrations by running batch / shell script files. Then they should be able to modify source and re-compile everything.
I'm trying to make life easy for people who use it and this includes people who are new to Java and programming who might be working on Linux / Unix.
I have access to machines running Windows and Linux. I don't use Linux a lot so maybe I've done something wrong.
I created a jar file on Linux using jar cf .... after setting permissions on the files so that everything worked as needed. Then I created a new test directory and extracted the jar file contents into it. The file permissions were not preserved ... i.e. -rw-rw-r--
The jar tool doesn't store file permissions, so you can't recover what has not been stored. jar format is not intended to archive files and metadata as zip or tar, it is a simple container to embed java files for an application.
Related
I'm trying to use a software library to run some computations. These computations can be customized using a few configuration files in its share directory. Unfortunately this library only provides hard coded paths to specific files in its (read-only) share directory which store these default configurations. Thus right now only a super-user or administrator could modify them. The library doesn't search for any user-local versions of these configuration files. I'd like to develop a wrapper tool which additionally takes a path to an alternate version of one of these configuration files in the users home directory and have that file somehow appear to "mask" the original file on the file system for the duration of process execution without actually modifying the original file in any way (since it can't). Is there a Linux tool I could use to do this sort of thing?
When I download source code from perforce, the symlinks gets downloaded as files and the project, of course, doesn't build. This happens on certain computers and virtual machines but the same symlinks download fine on other computers.
The download file is often a short file which just contains path of the linked file instead of being zero byte symlink file.
This actually had to do with user permissions on windows, not so much with perforce. The problem is that the user doesn't have permission to create symlinks so perforce ends up creating a file (In my opinion, it should generate an error message instead of converting the symlink to file).
The simple solution in most cases should be to start P4V as administrator and then download the source code. You may have to force it to download everything since it will not re-download wrong symlinks because those objects already exist on disk.
You can check if you have permissions with the following command. More here.
mklink <linkFile> <ExistingFile>
Note: you may well be able to create symlinks (=shortcuts) using File Explorer but it's the command line (above) that will determine if you have the privileges or not.
I have read many posts about changing the contents of a file and replace the whole file, but little did I understand.
Referred this too. The .sh is the one that confuses me. Do I need to use .sh in my case too. I don't want to ruin the project by trying something new, without much understanding.
How do I replace a class file in a jar? I have the class file ready from my workspace. All I need to do is replace the already present class file in the jar. Moreover, need I restart the server after replacing, to see effects?
The application server that we are using is IBM websphere.
Should I also navigate to my ear file location in the server? For example, cd aaa/bbb/ccc and then execute the command.
Please help, I am totally new to this.
To extract/pull a particular class from your ear:
jar -xf sample.ear com/sample/Example.class
then overwrite com/sample/Example.class with your generated class and finally do:
jar -uf sample.ear com/sample/Example.class
To update the ear file again with updated class file.
PS: This will require you to deploy the ear file again on your app server and then restart the app server. I would also suggest looking into ant or maven for this task.
.sh file is an example of one of the file from jar that you wish to extract it from jar and edit the extracted file and then again archive it back to the jar... in EXAMPLE
so you don't need .sh if your file name is not ending with .sh..
This is a more general and noob question. I am developing a small application in Linux (Ubuntu, to be more precise) and at this point I have an executable, a shared library (.so), a configuration file (.conf) with some settings to be read by the application at the beginning, a data folder with images and other resources to be used during the application life-time (resources that can be also modified, deleted) and of course, I would need some file for logs and messages (right now I am using syslog).
So, my question is, where should each one of these be stored when the application is installed on a client's computer? What is the standard way of organizing all the application's files in Linux? On Windows everything would be found usually in the C:\Program Files\(App Folder) but it looks like on Linux things are more (or less) organized. Can you give me some advices on this matter?
Program data were historically stored in dot-prefixed folders in user's home directory. Modern Linux distributions tends to use ~/.config/program_name folder.
For all files that will not be modified after distibution follow Linux standard:
Ex: project dir: ABC
sub directories:
logs - keep log files
conf - keep configuration files here
bin - executable binaries here
traps - any trap mesg
then depend on what application we develop
Along with you can set level for starting your application from boot level if required.
I gave execute permissions to a file and then compressed into a zip file in Linux OS. Then I moved this zip file to Windows and again copied it to another Linux server. This time I don't have the execute permission.
I know that we can directly copy the files and folders using scp command withing Linux but I have to let the user copy it from Windows to Linux also.
Please let me know how can I preserve the permissions while copying from Windows to Linux.
Thanks.
Since your executable file is inside a zip-archive it doesn't really matter what filesystem you're on or what operating system you're on. As long as the zip-archive is untouched.
However, as far as I know, zip-archives cannot keep track of file permissions. You can read more about it here:
Maintain file and folder permissions inside archives
It's up to whatever application is actually doing the copy.
But there are serious differences between the idea of file permissions on Linux/UNIX and Windows. UNIX file permissions have the idea of being "executable" which is not something that exists on Windows. Windows files are noted as runnable by their file extension not its permissions.
Furthermore, file permissions on UNIX have the concept of a group owner, and I don't think this exists on Windows so such a thing might not be possible in the strictest sense.
If you just want the writable/readable permissions as assigned to the owner to stick however, it will again depend on the application you are using to do the copy.
More recently, you can also use the Linux subsystem for Windows and zip the file using the linux shell command. I successfully did this recently when copying a executable for AWS from github to my Windows machine, and then up to Amazon.
Thanks for all your responses.
I found 2-solutions for my problem:
I am copying the complete zip file to the Linux server instead of copying a single file. This way it works fine.
Using cygwin helps me in copying the file onto a Linux server by preserving the execute permissions.