I would use a JNI interface if the goal is quality.
For quick hacks, (on my workstation only) : System.Exec() a vbscript :-) (I know, i know).
Not only does the supplied .dll not support x64, but jshortcut is GPL
Looks like it's LGPL now, and they claim 64-bit support on a contributed version via github (didn't test it out though)
How do you create (and read) windows shortcut(.lnk file) in Java? - St...
In Java 7, yes. You can point the shortcut to c:\windows\system32\java.exe or javaw.exe as appropriate and include the same arguments you would use on the command line.
In a clean Java 8 installation, not easily. Unfortunately Java 8 no longer puts copies java.exe and javaw.exe into the system folder, but instead puts symbolic links in a ProgramData folder. Windows doesn't like shortcuts to symbolic links; sometimes they work, sometimes they don't. (Even the same shortcut might work for some user accounts but not for others.)
(It seems that if you install Java 8 over top of Java 7 it retains the old behaviour, but I haven't investigated this thoroughly yet.)
This simple launcher may be useful; you can create one or more shortcuts to it with the same command line parameters you would have used in the shortcut to javaw.exe.
#include <Windows.h> void NoCRTMain(void) { wchar_t * cmdline = GetCommandLineW(); STARTUPINFO si; PROCESS_INFORMATION pi; GetStartupInfo(&si); if (!CreateProcess(L"C:\\ProgramData\\Oracle\\Java\\javapath\\javaw.exe", cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { MessageBox(NULL, L"Unable to launch Java.", L"runjava.exe", MB_OK); } ExitProcess(0); }
- Buffer Security Check to No in C/C++ Code Generation
- Ignore All Default Libraries to Yes in Linker Input
- Entry Point to NoCRTMain in Linker Advanced
(Or you can change the main function from NoCRTMain to WinMain, but then you need to install the C runtime or link it statically.)
Additional: in Windows 10, if you have two Start Menu shortcuts pointing to the same executable, only one of them will be visible in the Start Menu. So in this case you need to have multiple copies of the launcher, one for each shortcut.
I'm using Java SE 7. Can I just create a link to .jar without java.exe?
@leolegas: a simple link to a jar file seems to work, both in Java 7 and Java 8. I've never tried doing it that way, I don't know whether adding arguments will work as expected.
java - Run .jar through Windows shortcut passing arguments - Stack Ove...
Its impractical do this in pure java yourself, although the lnk-file format is documented by microsoft (http://msdn.microsoft.com/en-us/library/dd871305.aspx), but since it originated with Win95 it underwent significant extensions and redefinitions over the years. Implementing this seems like a daunting task.
You can try to find a library that implements it for you, e.g. http://ovanttasks.sourceforge.net/ov-native/ may do what you want.
update windows shortcut icon in Java - Stack Overflow
Right click-> generate getters and setters does the job well but if you want to create a keyboard shortcut in eclipse in windows, you can follow the following steps:
- In the "Binding" textfield below, hold the desired keys (in my case, I use ALT + SHIFT + G)
- Now in your Java editor, select the field you want to create getter/setter methods for and press the shortcut you setup in Step 4. Hit ok in this window to create the methods.
java - Is there a way to automatically generate getters and setters in...
One of the provided answers (not the accepted one) has this link:
The relevant script is:
@echo off & setlocal ::For Windows NT 4.0 users only!!! ::Creates LNK and PIF files from the command line. ::Author: Walter Zackery if not %1[==[ if exist %1 goto start echo You must pass the path of a file or folder to the echo batch file as a shortcut target. if not %1[==[ echo %1 is not an existing file or folder (pause & endlocal & goto:eof) :start (set hkey=HKEY_CURRENT_USER\Software\Microsoft\Windows) (set hkey=%hkey%\CurrentVersion\Explorer\Shell Folders) (set inf=rundll32 setupapi,InstallHinfSection DefaultInstall) start/w regedit /e %temp%\#57#.tmp "%hkey%" for /f "tokens=*" %%? in ( 'dir/b/a %1? 2^>nul') do (set name=%%~nx?) for /f "tokens=2* delims==" %%? in ( 'findstr/b /i """desktop"""= %temp%\#57#.tmp') do (set d=%%?) for /f "tokens=2* delims==" %%? in ( 'findstr/b /i """programs"""= %temp%\#57#.tmp') do (set p=%%?) (set d=%d:\\=\%) & (set p=%p:\\=\%) if not %2[==[ if exist %~fs2\nul (set d=%~fs2) if not %2[==[ if exist %~fs2nul (set d=%~fs2) set x=if exist %2\nul if not %2[==[ if not %d%==%2 %x% if "%~p2"=="\" set d=%2 echo %d%|find ":\" >nul||(set d=%d%\) (set file=""""""%1"""""") for /f "tokens=1 delims=:" %%? in ("%file:"=%") do set drive=%%? (set progman=setup.ini, progman.groups,,) echo > %temp%\#k#.inf [version] echo >>%temp%\#k#.inf signature=$chicago$ echo >>%temp%\#k#.inf [DefaultInstall] echo >>%temp%\#k#.inf UpdateInis=Addlink echo >>%temp%\#k#.inf [Addlink] echo >>%temp%\#k#.inf %progman% ""group200="}new{""" echo >>%temp%\#k#.inf setup.ini, group200,, """%name%"",%file% start/w %inf% 132 %temp%\#k#.inf del %temp%\#k#.inf %temp%\#57#.tmp move %p%\"}new{\*.*" %d% >nul 2>&1 rd %p%\}new{ 2>nul move %p%\}new{.lnk %d%\"drive %drive%.lnk" >nul 2>&1 endlocal
Not sure if that will fly all the way into Win7 and 8
Is there a solution available for creating shortcuts on Windows 7?
@JoeYo I'm not sure, the OP asked for it to work on win 7 and he accepted so I assume this worked. Give it a try
since it specifically said For Windows NT 4.0 users only!!! I didn't giv a try to it but instead found a solution at link will check it as well if this doesn't work. Thanks
windows - How to create shortcut icon using BATCH file which run my Ja...
You want to check a couple of things; if this is your own jar file, make sure you have defined a Main-class in the manifest. Since we know you can run it from the command line, the other thing to do is create a windows shortcut, and modify the properties (you'll have to look around, I don't have a Windows machine to look at) so that the command it executes on open is the java -jar command you mentioned.
The other thing: if something isn't confused, it should work anyway; check and make sure you have java associated with the .jar extension.
java - Running JAR file on Windows - Stack Overflow
"Windows shortcuts" are a combination of COM/ActiveX Monikers and Win32 APIs.
Neither of which are exposed directly by Java to the JVM environment.
SUGGESTION: Just write a little VBscript that your Java program invokes (getRuntime()/Process.exec()).
Or make use of a package that already does what you're looking for.
Thanks for the comment and link. I'll look through it... I might end up just writing something in C#.
I'll be using something like the following to make the shortcuts with icons for me. eggheadcafe.com/community/csharp/2/10084566/ I'll pass the specifics via command line, then I should be able to tie it in nicely with my install process.
Make Windows Shortcuts Using Java - Stack Overflow
In the end I decided to write the correct script, because no solution works for me You will need two fileLocal Settings\ first
@echo on set VBS=createSCUT.vbs set SRC_LNK="shortcut1.lnk" set ARG1_APPLCT="C:\Program Files\Google\Chrome\Application\chrome.exe" set ARG2_APPARG="--profile-directory=QuteQProfile 25QuteQ" set ARG3_WRKDRC="C:\Program Files\Google\Chrome\Application" set ARG4_ICOLCT="%USERPROFILE%\Local Settings\Application Data\Google\Chrome\User Data\Profile 28\Google Profile.ico" cscript %VBS% %SRC_LNK% %ARG1_APPLCT% %ARG2_APPARG% %ARG3_WRKDRC% %ARG4_ICOLCT%
and second
Set objWSHShell = WScript.CreateObject("WScript.Shell") set objWSHShell = CreateObject("WScript.Shell") set objFso = CreateObject("Scripting.FileSystemObject") If WScript.arguments.count = 5 then WScript.Echo "usage: makeshortcut.vbs shortcutPath targetPath arguments workingDir IconLocation" sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0)) set objSC = objWSHShell.CreateShortcut(sShortcut) sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1)) sArguments = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(2)) sWorkingDirectory = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(3)) sIconLocation = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(4)) objSC.TargetPath = sTargetPath rem http://www.bigresource.com/VB-simple-replace-function-5bAN30qRDU.html# objSC.Arguments = Replace(sArguments, "QuteQ", Chr(34)) rem http://msdn.microsoft.com/en-us/library/f63200h0(v=vs.90).aspx http://msdn.microsoft.com/en-us/library/267k4fw5(v=vs.90).aspx objSC.WorkingDirectory = sWorkingDirectory objSC.Description = "Love Peace Bliss" rem 1 restore 3 max 7 min objSC.WindowStyle = "3" rem objSC.Hotkey = "Ctrl+Alt+e"; objSC.IconLocation = sIconLocation objSC.Save WScript.Quit end If If WScript.arguments.count = 4 then WScript.Echo "usage: makeshortcut.vbs shortcutPath targetPath arguments workingDir " sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0)) set objSC = objWSHShell.CreateShortcut(sShortcut) sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1)) sArguments = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(2)) sWorkingDirectory = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(3)) objSC.TargetPath = sTargetPath objSC.Arguments = Replace(sArguments, "QuteQ", Chr(34)) objSC.WorkingDirectory = sWorkingDirectory objSC.Description = "Love Peace Bliss" objSC.WindowStyle = "3" objSC.Save WScript.Quit end If If WScript.arguments.count = 2 then WScript.Echo "usage: makeshortcut.vbs shortcutPath targetPath" sShortcut = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(0)) set objSC = objWSHShell.CreateShortcut(sShortcut) sTargetPath = objWSHShell.ExpandEnvironmentStrings(WScript.Arguments.Item(1)) sWorkingDirectory = objFso.GetAbsolutePathName(sShortcut) objSC.TargetPath = sTargetPath objSC.WorkingDirectory = sWorkingDirectory objSC.Save WScript.Quit end If
windows - How to create shortcut icon using BATCH file which run my Ja...
If you're using Windows, right click on your eclipse shortcut and select Properties, in the Shortcut tab you can change what's in the Target: box to specify the jdk. I use
For some reason I couldn't get it to use the jdk when I tried editing the eclipse.ini file.
java - Howto start eclipse in JDK? - Stack Overflow
I use Windows 7. I suggest right-clicking the NetBeans shortcut, go to Properties, and on the Shortcut tab at the Target, add -J-Xmx1024m -J-Xms256m.
This is the value of target textfield:
"C:\Program Files\NetBeans 7.1\bin\netbeans.exe" --jdkhome "C:\Program Files\Java\jdk1.6.0_10" -J-Dorg.netbeans.modules.php.dbgp.level=400 -J-Xmx1024m -J-Xms256m
In the etc directory under your Netbeans-Home, edit the file netbeans.conf file. -Xms and -Xmx should be increased to the values that allow your program to compile.
# Note that default -Xmx and -XX:MaxPermSize are selected for you automatically. # You can find these values in var/log/messages.log file in your userdir. # The automatically selected value can be overridden by specifying -J-Xmx or # -J-XX:MaxPermSize= here or on the command line.
Put the values in the netbeans_default_options string. Example :
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true -J-Dsun.awt.disableMixing=true -J-Dswing.aatext=true -J-Dawt.useSystemAAFontSettings=lcd --laf Nimbus"
Services.msc
Startup Type
- Select Services from 3rd party (non windows) which run Automatic, Right click, click Properties and change startup type to Manual
- Sort by Status and Stop services from (3rd party) app you think unused
This sets the memory usage of the JVM. Xms is the minimal value, while Xmx is the max. I don't know how well this tweak works (I just discovered it), but obviously you should adapt the values to your hardware.
java - How to improve Netbeans performance? - Stack Overflow
I can recommend this repository on GitHub:
There I've found a simple solution to create shortcuts:
ShellLink.createLink("path/to/existing/file.txt", "path/to/the/future/shortcut.lnk");
If you want to read shortcuts:
File shortcut = ...; String pathToExistingFile = new ShellLink(shortcut).resolveTarget();
If you want to change the icon of the shortcut, use:
ShellLink sl = ...; sl.setIconLocation("/path/to/icon/file");
windows - Creating a shortcut file from Java - Stack Overflow
I had the same issue when using Eclipse in Windows 7, even when I removed the JRE from the list of JREs in the Eclipse settings and just had the JDK there. Your question doesn't state if you're using command-line Maven, or Eclipse, so I thought I'd share what fixed it for me in Eclipse.
What I ended up having to do was modify the command-line for the shortcut I use to launch Eclipse to add the -vm argument to it like so:
-vm "T:\Program Files\Java\jdk1.6.0_26\bin"
Of course, you would adjust that to point to the bin directory of your JDK install. What this does is cause Eclipse itself to be running using the JDK instead of JRE, and then it's able to find the tools.jar properly.
This worked for me in a Maven project in eclipse but to get the full effect I had to do Maven -> Update Project from the context menu
java - Build error: missing artifact com.sun:tools:jar:1.6 - Stack Ove...
I had the same issue when using Eclipse in Windows 7, even when I removed the JRE from the list of JREs in the Eclipse settings and just had the JDK there. Your question doesn't state if you're using command-line Maven, or Eclipse, so I thought I'd share what fixed it for me in Eclipse.
What I ended up having to do was modify the command-line for the shortcut I use to launch Eclipse to add the -vm argument to it like so:
-vm "T:\Program Files\Java\jdk1.6.0_26\bin"
Of course, you would adjust that to point to the bin directory of your JDK install. What this does is cause Eclipse itself to be running using the JDK instead of JRE, and then it's able to find the tools.jar properly.
This worked for me in a Maven project in eclipse but to get the full effect I had to do Maven -> Update Project from the context menu
java - Build error: missing artifact com.sun:tools:jar:1.6 - Stack Ove...
I had a similar problem with ChromeDriver (I needed to minimize the browser window while the tests are running). I could not find a better way to do it, so I ended up using the keyboard combination Alt+Space, N to do it. This should work only in Windows, the example uses the Java AWT Robot class to play the keyboard shortcuts:
//Alt + Space to open the window menu Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_SPACE); robot.keyRelease(KeyEvent.VK_ALT); Thread.sleep(200); // miNimize robot.keyPress(KeyEvent.VK_N); robot.keyRelease(KeyEvent.VK_N);
java - How to hide Firefox window (Selenium WebDriver)? - Stack Overfl...
An interesting side effect of this causes a problem when starting runnable jar files in the command prompt.
If you try (in a command prompt)
No joy, because this is being translated to the following (that doesn't work):
however the following command does work:
If you change the association in file manager as described above to:
in the command prompt and it will now work! EDIT:(However you then get a black console window when you run a form based (non console) Java app, so this is not an ideal solution)
If you run these jar files by double clicking them in windows, no parameters will be passed so your Java code needs to handle the stack overflow exception and include a "press a key" function at the end or the window will just disappear.
In order to pass a parameter in windows you have to create a shortcut to the jar file, which includes the parameter in the target line (right click on the shortcut and select properties) you can not add parameters to the jar file icon itself in this way.
There isn't a single, consistent solution here, but you would have the same problem with any other console application.
There is a windows freeware application called "bat to exe" which you can use to create an exe file from a .bat file with the apropriate command line in it. you can also embed the jar file in the exe with this application, and make it clean it up when it has finished running, so this may be a more elegant solution.
java - Running JAR file on Windows - Stack Overflow
Deploy the app. using Java Web Start.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
The desktop shortcut is typically specified in the JNLP file used to provide the values needed to launch the app. It can include an icon.
Here is a small section of my desktop (Windows 7).
The two shortcuts on the RHS are JWS apps. The bottom one (Star Zoom Animation) defined an icon, while the other uses the default 'coffee cup' icon.
I can't speak for VenomFangs but in our case users don't want automatic upgrades, and with the increasing number of java exploits that are almost all related to java webstart or applets it doesn't make sense to expose ourselves to additional vulnerability if we don't have to. Our organization has required us to minimize the use of JWS and applets as much as possible, so having a more direct method to create shortcuts in our installer like this question asked would be very helpful.
Make Windows Shortcuts Using Java - Stack Overflow
Are you new to Linux? Linux doesn't execute batch scripts like Windows, instead it executes shell scripts. Shell scripts are far easier to work with and far more powerful, but the syntax is different and therefore a Windows .bat file won't just magically work in Linux.
An equivalent script might be:
#!/bin/bash javac -d bin -cp lib/ -sourcepath src $(find src -name '*.java')
A few tips: Paths in Linux are denoted with : whereas paths in Windows are denoted with ;
The $(find...) invocation is basically just a shortcut to say "all the .java files in src".
Otherwise, listing them all out manually as you have done in your original example works just fine too.
Converting Java Compiler to Linux - Stack Overflow
if you have not restarted your computer after installing jdk just restart your computer.
if you want to make a portable java and set path before using java, just make a batch file i explained below.
if you want to run this batch file when your computer start just put your batch file shortcut in startup folder. In windows 7 startup folder is "C:\Users\user\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
make a batch file like this:
set Java_Home=C:\Program Files\Java\jdk1.8.0_11 set PATH=%PATH%;C:\Program Files\Java\jdk1.8.0_11\bin
note: java_home and path are variables. you can make any variable as you wish. for example set amir=good_boy and you can see amir by %amir% or you can see java_home by %java_home%
java - How to set java_home on Windows 7? - Stack Overflow
I write a swt win32 extension for the win32 api call.
You can use it to make a windows shortcut.
You can download the library from http://feeling.sourceforge.net, it's open source.
But if you want to use it, you should depend on the eclipse swt library.
Make Windows Shortcuts Using Java - Stack Overflow
I suggest you to create a shortcut manually and then copy it programatically into the desktop folder. c:\users\dekstop