Well, i have the folder of the java program that i made with eclipse and it contains the .java and .class files along with some folders that contain images and text files needed for the proper program's operation. My question is, how can i make a whole executable(.sh in this case) program, that works exactly as i have compiled it run it? For example, i let people download it and i want them to run it just by typing ./(filename).sh .
Since i wrote the program on linux, and i have to test it on linux at the moment, how is possible to make the exact same work on windows machine?(i will transfer the eclipse project)
Thanks in advance.
Related
I've been wanting to reverse engineer this clients launcher in an effort to understand how the game was launching as a Java application despite it only having a PE32 executable alongside it.
The launching of the client goes as follows:
java -Xmx384M -Dfile.encoding="UTF-8" -cp TargetBinary.exe com.java.client.Client
Now I was curious what TargetBinary.exe actually was, as this was being ran on a *NIX system. Running file I observed this output.
TargetBinary.exe: PE32 executable (GUI) Intel 80386 (stripped to external PDB), for MS Windows
The second part is the com.java.client.Client after the TargetBinary.exe, this stands out as a Java pathing which Client is my target.
Here are my questions:
How can Java add the TargetBinary.exe to its classpath?
As a followup, are there any recommendations to decompile it to the point where I can observe Client and more so understand how it was all packed together?
Being a Portable Executable (PE) the libs, code, etc should all be there inside the TargetBinary.exe and somehow Java knows what to do with it?
Zip files are read from the back, so it's easy to put a zip (jar) file at the end of an executable file, and have it work as both.
See https://en.wikipedia.org/wiki/ZIP_(file_format)#Structure
Try running jar -tvf TargetBinary.exe to see the names of the classes and resources in the jar. If you make the file a dependency of a project in your IDE you can see decompiled code and navigate around the project, and run it and set breakpoints.
Friend cannot open an exe I made from a jar file. Gives a java exception, assuming that simply means he doesn't have the correct version of java, is there a way for me to include the files needed to run it with the exe, to remove the need of having java downloaded?
I made a java program with jframe for a friend to help him do some calculations and I was able to convert it into an exe but when he downloaded it and tried to run it, it gave a java exception, is there a way I can include the java files needed to run the app with the exe?
You have to first create a .jar file and then convert it into an .exe file. You can refer to this link https://medium.com/#sulabh4/how-to-make-a-executable-file-from-your-java-code-3f521938ae5c
I know this question would sound very stupid, but this is my first java program after all.
K, the question is, when type this: java -jar JavaApplicationTest.jar the program executes without problems, but when I go to the folder where the JavaApplicationTest.jar file is, and click on it, it does not execute. I thought that .jar files were like .exe file, are they? I mean, in the way that we click on them and the program runs; 'cos the java virtual machine is running in the back ground.
Please, any help would be very much appreciated.
No, they aren't exactly like .exe. Only .exe is an .exe.
When you execute a JAR file, it's the Java JVM that's running, not your JAR file. The JVM opens the JAR, loads the .class byte code, and executes the main class that you specified in the META-INF.
I'm guessing that your Windows operating system is doing something besides running the JVM when you double click. Try right clicking and seeing what options your Windows operating system presents to you. If one of them is to unzip the file, you'll have to add running the JVM as another choice.
The jar-file runs. But there's a big difference between:
java -jar someJar and someJar.jar/respectively double-clicking on the jar.
The full command launches the jar in the same commandline, in which you have entered the command. Double-clicking on the jar creates a process aswell. But with a completely separate console-window that is hidden.
Java archive or jar is an archive of compiled java byte code and resources which can be run on a java virtual machine. ".exe" is a windows extension for directly executable code mostly used by installers or programs that do not need to be installed.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I convert my Java program to an .exe file?
Compiling a java program into an exe
I believe this is an easy question, though I cannot find a quick answer.
I've been learning in a Java class about GUI making (and really Java coding in general) which, when compiled, creates a .java file. That .java file can be opened with some sort of IDE but not just opened like a .exe file.
This brings me to my question. When/where do you actually use a Java GUI? I don't foresee me passing out .java files for my friends or co-workers to use the tools I've made. Are they supposed to work best with online applications?
Your .java file contains your Java code, which you then compile to a class file. That could be executed by your friends.
In most cases you would bundle your app with its resources in an executable jar file. If configured correctly, the operating system can run the Java app just by double clicking on it. One other solution would be to use Java webstart to distribute your GUI app but that is essentially the same thing. Java and the file association to jnlp files have to be configured correctly.
The easiest way is probably to use an exe wrapper like launch4j to create an exe file that loads the JVM and runs the Java application. Those wrappers can even create distributions with bundled jvms to make sure your application is able to run if the user doesn't have Java installed.
Hope it helps.
A .java file is source code which is meant for a programmer to write code in a format suitable to them, to define the behaviour of the program.
Source code is compiled into .class files which you can execute (run), although they are often packaged into JAR files (which are simply collections of .class files).
These can be executable and can be passed between people to share programs.
GUIs are irrelevant. You can either create a GUI or not, but the functionality will still exist in the code and can be executable. GUIs allow you to view and interact with a program, whereas without a GUI you have to use the command line if interaction is required.
When Java is compiled, it creates .class files, not .java files. The .java files are source code; the .class files are the result of compilation.
.java files can be opened by an IDE, but it doesn't make sense to open them as an .exe file because, again, .java files are source code.
To run Java applications, you have to run a Java Virtual Machine which is specific to your operating system. You provide the .class file as input, and the JVM runs it.
The .class files are the Java-equivalent to Windows .exe files, in the sense that they are "executable". However, while .exe files can be directly executed by Windows, .class files aren't directly executable by any operating system but by an operating system-specific JVM.
The "strength" of Java in that respect is that the same .class file (executable) can be run on any operating system that has a JVM installed on it.
It really doesn't matter if you develop a Java GUI (graphic user interface) or a Java CL (command line) program as in the end your software is supposed to run just like an *.exe as long as the user have the "Java Virtual Machine" installed.
I recently installed a java software in my PC and started writing some simple programs. I didn't face any problem while compiling the programs, but while executing it, it shows this error message -
"Windows can't open this file.
File: HelloWorld.java
To open this file, windows need to know what program you want to open it. Windows can go online to lookup it automatically, or you can manually select from a list of programs that are installed on your computer.
I know all the path settings are correct. In fact, there was no problem at all while compiling the program. What can be the problem of this? I even reinstalled JRE and that didn't help. Can someone help me?
Note: I'm using Windows 7 64 bit architecture OS and I'm using command prompt for compilation and execution of the file.
I'll assume that you've double-clicked the .java file, e.g. in the file explorer. A java source file isn't a (click-launchable) executable, and - without some acrobatics - neither is a compiled .class file: you shouldn't expect to double-click either and start your program.
In order to get this sort of behavior, you'll need to build a launchable program, and there are a few ways to do this. One is by making a batch file that runs the java VM with your code, another is creating an executable jar file.
To just run your code outside your IDE, you can invoke the java VM on the command line:
c:\> java HelloWorld
As to your specific error message, you haven't associated any program with .java files. Typically, as programmers, we want this Windows file association to be our editor of choice or our IDE. You can create this association by Right-clicking on the file, choosing Properties from the menu and then clicking the Change button beside Opens with: to pick an application.
But this is a side-issue: you still won't use this to make .java file executable. Search around this site for questions and answers about building executable jar files. If you're using a specific IDE like Eclipse or NetBeans, use that to refine your search.
When you want to execute the program, you specifiy the class name rather than the file name:
java HelloWorld
Don't use java HelloWorld.java, for instance.