I have a java app that I wrote. I am able to execute it using Ant and with "java -jar" from the command line. I want to be able to launch the file using "javaw.exe" (my app uses Swing). For some reason it doesn't seem to do anything (javaw starts for a second and then quits with no error that I can see). I tried running the same file on my Win XP computer using javaw and it executes fine. The other computer I am using it on is a Win 7 laptop.
Building on purtip31's comment ...
I expect that the problem is that some exception or error is occuring when you launch using javaw, but you can't see any diagnostics because they are going nowhere.
In the short term, redirect standard output to a file and look at what is being written.
In the long term, replace your "System.out" and "System.err" diagnostics with proper logging via a logging framework such as log4j, java.util.logging, etc.
Related
I have a JavaFX app, and I am using the maven plugin javafx-maven-plugin to create an app bundle (app.exe in Windows, generated with Inno Setup).
The app runs in console mode when arguments are given.
The problem is that when running in console mode, I can't see the mesages printed to console. The messages (written with System.out.println) don't appear in the Windows console. But they are generated, because if I redirect the output to a file (app.exe > out.txt) the file contains all the messages.
I have tried to run the .exe with cygwin and even compiled the whole project in Linux, and in both of them the output is correctly displayed in the console. So the problem seems to be only when running the javafx exe with the Windows console (cmd). I guess the stdout is redirected to somewhere. How can I change this?
First of all: thanks for using the javafx-maven-plugin, I'm the maintainer of that maven-plugin.
short version: you can't do very much
long version:
The problem comes with the native launcher of the JDK and has nothing todo with InnoSetup, nor Maven.
Quoting the source-code itself this is what happens:
Basic approach:
- Launcher executable loads packager.dll/libpackager.dylib/libpackager.so and calls start_launcher below.
- Reads app/package.cfg or Info.plist or app/<appname>.cfg for application launch configuration
(package.cfg is property file).
- Load JVM with requested JVM settings (bundled client JVM if availble, server or installed JVM otherwise).
- Wait for JVM to exit and then exit from Main
- To debug application by set env variable (TODO) or pass "/Debug" option on command line.
- TODO: default directory is set to user's Documents and Settings.
- Application folder is added to the library path (so LoadLibrary()) works.
After digging a bit inside the launcher, if found the spot, where the STD-output is retrieved, which gets compiled, because on windows-systems "USE_JLI_LAUNCH" is not set. The real problem with this comes with the condition to only append that console-writer when being compiled with DEBUG-flag
It might be a bug/fluke within the JDK itself, I'll try to find something and might file that as bug on oracle-bug-tracker.
EDIT: after some further digging, there is something I found interesting: the generated EXE-file is a simple windows-executable, no cli-executable as seen in the launcher-source-code, that is the reason you dont see any console-output but having the result when pipelining into some file.
Workaround: create/compile your own native launcher-file using some redirects as described here:
Redirecting cout to a console in windows
https://bobobobo.wordpress.com/2009/03/01/how-to-attach-a-console-to-your-gui-app-in-c/
I am trying to run the JAR "buildtools.jar" but a message keeps popping up:
The Java JAR file "BuildTools.jar" could not be launched.
in smaller writing underneath:
Check the Console for possible error messages.
The console says
12/31/14 10:19:44.021 AM WindowServer[113]: _CGXGetWindowMovementGroup: Operation on a window 0x14 requiring rights 0x5 by caller Dashboard or 12/31/14 10:19:44.021 AM DashboardClient[2747]: _NXMoveWindow: error moving window (1000)
every time I try to open the jar thing up. I know that my Java is updated because I updated before trying anything with this.
I am trying to create a minecraft server with spigot and if you have a step by step process or any hinters about please tell me but my main focus is opening up the jar.
Unfortunately this isn't the very right place to ask this question. You can ask this question at the Spigot Forums.
Are you using the very latest version of BuildTools? You seem like running on MacOS. You may need to run it with this flag, -Dmac.supported=true(refer to this post). Also, The Java JAR file "BuildTools.jar" could not be launched. most likely, you have a broken Jar file. Try to re-download it from {1}(I need 10 population to post more than 2 links). You will also need JDK(Java Development Kits) but I think it is came by default in MacOS and Git {2}.
After you've installed all required things, you can run the BuildTools from Terminal by java -Dmac.supported=true -jar BuildTools.jar You need to wait few minutes for it to be finished.
Have you had experience with running a jar file using a command line, wrapped in a Windows service?
I'm trying to find a way to run a jar file without being logged into the machine, and since it allows command shell, I was wondering if it's a good idea.
Thanks!
Original Post:
I'm trying to run Associated Press's Web Feeds Manager, which is basically a jar file that can be run when logged in by double clicking it.
I'd like to run the same file but without being logged in to the machine. In their manual (http://wfm.ap.org/admin/content/help/Running_Agent_on_a_Remote_Server.htm) they write how to do that, using a commandline parameter.
Basically I'd like the jar to run as a Windows service, regardless of who's logged in, but Googling it showed it was problematic.
Have you had experience with remotely running jar files? What are the pitfalls?
Thanks!
On a google search, I came across this article -
Running Jar Applications as a Windows Service
It mentions about open source Java Service Wrapper project from Tanukisoftware.org for accomplishing this task.
Note: I've not used this personally.
If you are not interested in having the service started/stopped at boot/shutdown, but you just want the program to be started manually and keep running after logout, here is what you do:
$ nohup java -jar foobar.jar > foobar.log 2>&1 &
which means: start my foobar.jar (java -jar) and keep it running after I logout (nohup) redirect stdout to foobar.log (>) and also the stderr (2>&1), and make it running in background (& at the end).
Instead, if you are interested in installing a "service" in your linux box, there are many options, depending on what distribution you are using.
The most common are upstart (for ubuntu) and System V init scripts (Redhat or others). Also cron can be used to start/stop services at startup/shutdown.
You can find an example of installing a java app (hudson) on an init system here, or doing the same thing with upstart. Or, as I said, cron could be an option.
On Windows, there is Java Service Wrapper. And not much more.
For windows Java Service Wrapper is a better choice
My favourite is the upstart on linux, but it is Ubuntu only.
On Windows I see many alternatives according to this forum.
I followed the instructions on the Datomic site: http://docs.datomic.com/getting-started.html, but I'm getting this error when trying to start up the datomic shell prompt. I'm using a windows machine. Any suggestions? I tried the same thing on my linux box and did not get this error.
Edit: moved to a different windows machine and it's working. If I have time to troubleshoot this problem and I find a solution I'll report back
I noticed that you cannot run the shell.cmd from within the bin directory, you need to call it with bin\shell.cmd from the parent directory... hope that helps.
In case you are using cygwin/bash and call bin/shell :
The java runtime on windows does not understand classpath with a ":"
but this is what you get from bin/classpath.
Either correct this or use DOS-CMD shell and call bin/shell.cmd inside.
Regards
Some tips for running datomic on Windows (7 at least):
Do not download datomic into Program Files. On startup, it creates logging directories and temp files into its own directories, so unless you run the command prompt as Administrator, you're gonna have screens full of Unable to write to file... errors.
You need to run datomic as such (assuming you extracted the download to C:)
c:\datomic-free-0.x.xxxx>bin\shell.cmd
Note the backslash. Tripped me up forever coming from *nix world.
After that, return to your regularly scheduled datomic tutorials.
I added a value at:
HKLM\Software\Microsoft\Windows\CurrentVersion\Run
That looks like this:
Value Name: LDE
Value Data: "java -jar C:\LDE\lde.jar"
Really with the quotes (Because all the others where also with quotes). After adding this, I restarted my computer, but it didn't start automatically.
Will wrapping my jar in an exe help?
I'm running Windows 7.
Any help?
Thanks in advance.
Update:
When I remove the quotes, it works. But now there is appears also a terminal, which I don't need...
A couple of things to note here, concerning the two different issues in the problem:
Format of Windows Run keys
From the Microsoft Windows XP knowledge base:
Run keys cause programs to
automatically run each time that a
user logs on. The Windows XP registry
includes the following four Run keys:
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce
Each of these keys has a series of
values. The values allow multiple
entries to exist without overwriting
one another. The data value for a
value is a command line.
Note the emphasis on the last line. The moment quotes are used, the command is bound to fail execution in the same manner it fails as if executed from a command prompt.
Also, note that the above approach is for Windows XP and does hold good for Windows 7. More details can be found in this Microsoft Technet article on the options available in Windows 7.
The javaw vs java application launcher
Once the java process can be initialized at Windows startup, one will get a console window that continues to stay around until the process is terminated. This occurs if the java executable is utilized to initialize the application.
From the technotes of the java application launcher:
The javaw command is identical to
java, except that with javaw there is
no associated console window. Use
javaw when you don't want a command
prompt window to appear. The javaw
launcher will, however, display a
dialog box with error information if a
launch fails for some reason.
Therefore, if you wish to avoid opening a console window for the Java process, you ought to use the javaw executable.
This is very simple. You will find the startup folder in the C:/Documents and Settings/AllUsers/YourUserName/StartUp. It will be on similar kind of path just check it. Then just paste your jar file in that folder and it will work nice. Remember that you put the jar file in the startup folder of your user name folder. You may find that this folders might be hidden so just check it out. If you find this answer useful vote it. Enjoy.....