I've used Amazon corretto and Java's jre(javaw.exe) to try running my jar file. The task manager says that 'Java Platform SE Binary' is running but no dialogue box(or display) of the jar program is shown on my laptop.
I even tried opening it through command prompt or through a bat file, all in vain.
Any and all help would be deeply appreciated! Thanks! Task Manager snap
A java app does.. what the java app does.
Which may well involve no GUI whatsoever. You won't notice anything whatsoever in your windows environment if the java app you're trying to start doesn't actively involve any GUI elements from e.g. the javax.swing package.
Try using java.exe - javaw.exe does not show any console input or output, whereas java.exe does. If it's a console app (that reads and prints text from the command line), it would simply appear to be doing nothing if you try to launch it with javaw.exe.
For example, this app:
// Save this as 'Example.java'
public class Example {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
then open a 'dos box' (run cmd.exe), navigate to the proper directory, and run:
javac Example.java
javaw Example
does nothing. You witness precisely what you are witnessing (or possibly you can't witness it as the app closes too fast. But you certainly won't see any windows or any text). Then run:
java Example
and you'll see: Hello, World! and then the app exits.
If 'the command line' is gobbledygook to you, well, if you want to program, you're going to have to know how it works, but, fortunately, there are plenty of tutorials around :)
Related
What the title says really. I've tried exporting it to a Runnable Jar File, checked the Manifest.MF, and tried running it with Java multiple times but with no luck. However, it does work when I navigate to the file using the command prompt and launch is using java -jar Name.jar. This shows it works but I just can't get it to launch by double clicking.
I guess you're trying to launch a commandline-app. This kind of application can be launched by double-clicking aswell. There's only one problem: Java doesn't create a commandline-window by default and instead uses the commandline of the parent-process of the JVM, which in case of double-clicking doesn't own a console-window. In other words: the output to the console gets lost somewhere in the depths of your OS and the JVM and the program hangs as soon as any input is expected.
(Assuming your on Windows OS), if you right-click on it, do you see the option 'Open with' and then 'Java (TM) Platform SE binary', or something like that? And if you opt to open with that, does it execute?
If so, then you've probably set .jar files to open with a different application by default. For example, I have my computer set up to open .jar files with jd gui as the default application.
We have a Java application based on Eclipse (main class implements IApplication) that is started from the Windows command line. Its output on System.out is not visible/printed into the command window from which it is started. Nevertheless, when piping the output to more, the output is fine. How come?
For example, consider helloworld.exe. When running C:\>helloworld.exe in a command window, the application simply returns. But when running C:\>helloworld.exe | more, the screen shows
C:>helloworld.exe | more
hello world
C:>
On linux, the output is fine. How to see the output on Windows, too?
Some reqested information:
The application is quite large. And I probably cannot cut it down. The output are simple calls to System.out.prinln("xxx");
Java version 1.8.0_60, Eclipse 3.6.2
Using >std.txt 2>err.txt shows that output is indeed on stdout.
Line endings are CR/LF
the .ini file is as follows
--launcher.suppressErrors
-vmargs
-Xms256m
-Xmx4096m
-Djava.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory
-Djava.library.path=plugins
Maybe this issue is related?
If your application is somehow started via eclipse.exe (has no console attached to it) change the call to use the eclipsec.exe (has a console attached to it, note the c in the application name).
You can launch Eclipse RCP based applications using equinox launcher as shown below:
java -jar plugins/org.eclipse.equinox.launcher_1.1.1.R36x_v20101122_1400.jar
Of course you have to find the correct version of equinox launcher you are using in your RCP Application.
This way you would see the console logs.
You can read more about it here: http://wiki.eclipse.org/index.php/Starting_Eclipse_Commandline_With_Equinox_Launcher
EDIT: The reason you don't get console logs when eclipse.exe based launcher is used is because eclipse.exe on Windows spawns a separate process which brings up another command prompt window.
You'd better use a framework to handle your logs like logback
This is much more portable and maintainable.
In your example it seems that you have created an exe from your java code. My guess is that the packager you used to create the exe made some changes to the output target because it is a wrapper for your java program.
Try creating a jar instead and try executing it by java -jar helloworld.jar.
Is the string going to stderr in place of stdout? (or the other way around depending on your expected behaviour).
https://support.microsoft.com/en-us/kb/110930
We all mostly use System.out.println in the Console of our IDE. I am using Eclipse.
I can also clearly see the println() message on my Mac's Console app. Which is nice for my personal things.
And here is the code:
public class Main {
public static void main(String[] args) {
System.out.println("Is this logged anywhere?");
}
}
And here's what I see on my Mac:
Does Windows have something similar to the Mac's version of Console?
Sadly, as previously said, we don't really have that on Windows. Your best options is to run your program from CMD and then pipe the standard out to a file. Something like java -jar HelloWorld.jar > hello.txt.
What I usually do is create a Handler to a log file (usually just [program name] log [date].txt and have all messages outputted there depending on the log level, which is good practice if you're used to only using System out prints.
Straightforward answer remains that no such functionality comes standard with Windows. You'll have to pipe to a file in some manner.
It does not. However you can simply run the process from a command prompt if you want to examine its stdout. (As you said, eclipse works too, of course.)
How do I compile and run a program in Java on my mac?
I'm new.
Also I downloaded a program that was suggested to me on here called text wrangler if that has any bearing on the situation.
Compiling and running a Java application on Mac OSX, or any major operating system, is very easy. Apple includes a fully-functional Java runtime and development environment out-of-the-box with OSX, so all you have to do is write a Java program and use the built-in tools to compile and run it.
Writing Your First Program
The first step is writing a simple Java program. Open up a text editor (the built-in TextEdit app works fine), type in the following code, and save the file as "HelloWorld.java" in your home directory.
public class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World!");
}
}
For example, if your username is David, save it as "/Users/David/HelloWorld.java". This simple program declares a single class called HelloWorld, with a single method called main. The main method is special in Java, because it is the method the Java runtime will attempt to call when you tell it to execute your program. Think of it as a starting point for your program. The System.out.println() method will print a line of text to the screen, "Hello World!" in this example.
Using the Compiler
Now that you have written a simple Java program, you need to compile it. Run the Terminal app, which is located in "Applications/Utilities/Terminal.app". Type the following commands into the terminal:
cd ~
javac HelloWorld.java
You just compiled your first Java application, albeit a simple one, on OSX. The process of compiling will produce a single file, called "HelloWorld.class". This file contains Java byte codes, which are the instructions that the Java Virtual Machine understands.
Running Your Program
To run the program, type the following command in the terminal.
java HelloWorld
This command will start a Java Virtual Machine and attempt to load the class called HelloWorld. Once it loads that class, it will execute the main method I mentioned earlier. You should see "Hello World!" printed in the terminal window. That's all there is to it.
As a side note, TextWrangler is just a text editor for OSX and has no bearing on this situation. You can use it as your text editor in this example, but it is certainly not necessary.
I will give you steps to writing and compiling code.
Use this example:
public class Paycheck {
public static void main(String args[]) {
double amountInAccount;
amountInAccount = 128.57;
System.out.print("You earned $");
System.out.print(amountInAccount);
System.out.println(" at work today.");
}
}
Save the code as Paycheck.java
Go to terminal and type cd Desktop
Type javac Paycheck.java
Type java Paycheck
Enjoy your program!
Download and install Eclipse, and you're good to go.
http://www.eclipse.org/downloads/
Apple provides its own version of Java, so make sure it's up-to-date.
http://developer.apple.com/java/download/
Eclipse is an integrated development environment. It has many features, but the ones that are relevant for you at this stage is:
The source code editor
With syntax highlighting, colors and other visual cues
Easy cross-referencing to the documentation to facilitate learning
Compiler
Run the code with one click
Get notified of errors/mistakes as you go
As you gain more experience, you'll start to appreciate the rest of its rich set of features.
You need to make sure that a mac compatible version of java exists on your computer. Do java -version from terminal to check that. If not, download the apple jdk from the apple website. (Sun doesn't make one for apple themselves, IIRC.)
From there, follow the same command line instructions from compiling your program that you would use for java on any other platform.
Other solutions are good enough to answer your query. However, if you are looking for just one command to do that for you -
Create a file name "run", in directory where your Java files are. And save this in your file -
javac "$1.java"
if [ $? -eq 0 ]; then
echo "--------Run output-------"
java "$1"
fi
give this file run permission by running -
chmod 777
Now you can run any of your files by merely running -
./run <yourfilename> (don't add .java in filename)
I'm writing a Java Swing Application running on Red Hat Enterprise Linux 5 server that I would like to launch jEdit to view log files.
Here is some example code.
public static void main(String[] args) throws IOException, InterruptedException {
String cmd = "sh -c \"java -jar /tmp/jEdit/jedit.jar /tmp/test.txt\"";
System.out.println(cmd);
Runtime.getRuntime().exec(cmd);
}
The output is:
sh -c "java -jar /tmp/jEdit/jedit.jar /tmp/test.txt"
If I copy and paste the cmd output in a terminal window, it runs fine.
I have tried a bunch of cmd values, but I can never get the jEdit window to be visible.
With changes, this process works fine on Windows.
Is what I'm doing possible on Linux?
Thanks in advance!
As jEdit is implemented in Java, perhaps it would be easier to check the source for what the main method (in the class declared in the manifest file included in the jedit.jar) does and do the same thing without using Runtime.getRuntime().exec() at all.
If you do want to stick with it, you could try passing the individual commands as an array to exec(), this often solved such problems for me.
Linux uses the concept of display ports for its X-Windows system. This allows it to maintain a different desktop environment for each user. It also allows a user on remote machine to run a desktop app from the first machine but see the UI on the remote.
Windows, having only one available desktop environment at a time, does not.
First thing you definitely have to do is add the environment variable "DISPLAY=localhost:0" to the environment from which you are launching this. However, you may also need to run 'xhost +localhost' or this may not be allowed.
Double-check, too, that you didn't successfully launch a bunch of jEdit processes that are now zombies (using top) and kill them if necessary (using kill).
Runtime.exec() needs some special attention. The exec method that accepts a String uses the space character as a delimiter to break up the string into commands. You need to use the exec method that accepts a String[]. Read more here, specifically near the bottom.
I´ve done this once and I got the same problem
What I've done is to write the command line into a text file and then execute the text file as a shell script file.
It worked fine for me.
Jedit has a launcher script, /usr/bin/jedit I guess. Simply typing jedit in command prompt runs it, at least in current version, 4.5. Try that script instead of explicit java command.