2

I've a custom java executable jar file - mytestapp.jar, which performs some basic checks like system name, ip address, canonical name, uptime etc and prints the same in customized formant on the screen. The program is working fine and I get the required and expected out put when i run

java -jar /mytestapp/mytestapp.jar

Instead of running the above command each time, I've created a file myappinfo and added the above command in the file and saved it. Added /mytestapp to the PATH variable. When I do echo $PATH, it displays /mytestapp in the PATH.

I set the file permissions of myappinfo to 755 and made it executable.

Now when I run the command myappinfo from any folder I get the same output.

Now the requirement is, I want to make this file - myappinfo to be a binary file, not to be changed or inspected by anyone by using any editor programs (like vi, nano, etc). Any advise to do this?

14
  • Use a Java class file obfuscator, I suppose. Commented May 1, 2012 at 16:40
  • 1
    I doubt that you really need to do this or want to do this. Commented May 1, 2012 at 16:41
  • 1
    @HovercraftFullOfEels The original question was a little different - the editor changed it significantly Commented May 1, 2012 at 16:41
  • 2
    @JRaymond: I saw the change, but if he really has to ask this here, then in all seriousness, the chances of anyone wanting to steal his code is as close to nil as one can get. After all, he's not coding the next incarnation of MS Office. Rather if he's coding a field-specific piece of software, the value is in the service and support, not in the code. Commented May 1, 2012 at 16:43
  • 1
    @HovercraftFullOfEels True - but it looked like the intent was not to obfuscate the code, but rather lock in the call to execute it - almost more of a sysadmin function than a programming one, so the edit totally changed the meaning of the question Commented May 1, 2012 at 16:46

3 Answers 3

1

Now the requirement is, I want to make this file - myappinfo to be a binary file, not to be changed or inspected by anyone by using any editor programs (like vi, nano, etc).

Just setting the shell script to not world readable/writeable should do what you want.

But if you insist that you want to convert your shell script into a compiled shell script there is shc which claims to do just this.

I am sure if you Google for shell script compiler you will find many other options as well. This is just the one I know about.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi Jarrad, I tried shc before I posted my question here. It does the same of converting the script to c and then compile it to an executable. Wanted to know is there anything in java which can do this, instead of using C as an additional requirement. Any way, thanks much for your valuable inputs.
0

You can use GCJ for compiling your Java program to native machine code (or any other compiler that works this way). That would be the only really working solution as Java class files can be decompiled easily.

The other solution would be a startup wrapper. There are a lot of wrappers around that combine the jar file(s) and a native launcher code part that searches for the Java runtime and then uses it to execute the embedded class files. With more or less effort you can extract the class files from the combined executable.

Comments

0

The .class files can be decompiled, so you would want to look into an obfuscator of some sort. But, to make it executable on Linux, you would only need to do chmod +x <name-of-file.jar>.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.