Add Java program to Windows' context menu [duplicate] - java

How would one go about adding a submenu item to the windows explorer context menu (like for example 7-Zip does) for a Java application?

I am aware of two ways to do it. The fancy way is to write a windows shell extension, which is how powerarchiver, winzip etc do it I believe (this involves running code to determine what the context menu items will be dependent on the file chosen).
The simple way, for simple functionality, is you can add an entry in the registry :
HKEY_CLASSES_ROOT\<file type>\shell\<display text>\command
Where <file type> is the files that this context menu should apply to i.e. *, .mdb, .doc
and
<display text> what you want to show in the context menu.
Then add the default string as a path to the application you want to launch from the context menu, and you can use %1 to refer to the currently selected file i.e. for MS Access I use :
HKEY_CLASSES_ROOT\*\shell\MS Access 2000\command
"C:\Program Files\Microsoft Office\Office\MSACCESS.EXE" "%1"
This then adds a context menu item for any file I select (hence the *), which allows me to launch it in MS Access 2000.
Of course, always back up your registry before hacking it.
Your program could do this during install, or on first run.

You could also package the java program in an installer like NSIS and you could use NSIS script to generate explorer context menu

Related

IntelliJ - Take standard input from a file

I need to take standard input from a file in IntelliJ IDEA.
$ java BinarySearch tinyW.txt < tinyT.txt
'tinyT.txt' is the file which is to be taken as standard input. 'tinyW.txt' is another file which is passed as a command-line argument to the program.
How can this be achieved through IntelliJ?
PS: I am not running this program from the command-line as the class-path variable hasn't been set, and I am using functions from external libraries.
You need to create a "Run/Debug Configuration" (Menu "Run" -> "Edit Configurations...").
About halfway down in the configuration panel is an entry "Redirect input from" with a checkbox before it. After selecting the checkbox you can select the file "tinyT.txt".
"tinyW.txt" has to be entered into the field "Program arguments"

using doxygen for java with Doxywizard

Doxywizard Doxygen not scanning the packages for java files
Need help on Doxygen/Doxywizard
These are my Doxywizard settings:
Working directory from where doxygen will run:
C:/Program Files/doxygen
In 'Wizard' tab, the below values are set.
Source code directory:
C:/workspace/git/employeeapp/src/main/java
Destination directory:
C:/Doxy-docs/1
In 'Expert' tab, under Topics-'Build' , selected the 'EXTRACT_ALL'
I installed Doxywizard, open the wizard, set the above values, went to 'Run' tab
and clicked 'Run doxygen', I expected that all the folders/packages inside the 'src/main/java'
will be scanned and a project default documentation would be created.
Problem: However I see that 'C:/Doxy-docs/1/html/index.html' is blank and no other pages were created.
If I just navigate to a folder where there is a '.java' file [say src/main/java/com/app/], documentation is created for
the '.java' files inside that folder. But as in the above scenario where 'src/main/java' is mentioned,
the tool is not scanning for packages/folders inside for the '*.java' files.
Question: Am I missing some configuration? or is this the expected functionality of doxygen that it cannot scan inside
folder-folder etc?
Note: This link shows the features of doxygen and from that I think it support the feature that I am expecting.
http://www.doxygen.nl/features.html
Note: I added java tag only because I am using the wizard to scan java files
I continued my effort in finding the option to set it,
and came across this link,
http://www.ibm.com/developerworks/aix/library/au-learningdoxygen/
which mention about 'RECURSIVE'
: Set this tag to Yes if the source hierarchy is nested and you need to generate documentation for C/C++
files at all hierarchy levels. For example, consider the root-level source hierarchy /home/user1/project/kernel,
which has multiple sub-directories such as /home/user1/project/kernel/vmm and /home/user1/project/kernel/asm.
If this tag is set to Yes, doxygen recursively traverses the hierarchy, extracting information.
Got my boy - its 'RECURSIVE'
In Doxywizard, found it under 'Expert' tab and then Topics - 'Input'
checked the checkbox against 'RECURSIVE', and selected '*.java' in FILE_PATTERNS.
Executed again, and the whole documentation is on the table!!! [destination dir what i mentioned]
or,
In the 'Expert' tab itself, when we specify the 'Source code directory',
there is a checkbox for 'Scan recursively'. Just check it.

Java get current file name EXE

This is my first Stackoverflow question.
I searched across Google for getting the current file name in Java. Most of the sources tell users how to find the current file name if the file is a JAR file, but I'm asking for if the current file is an EXE file.
I saw one EXE answer in Get name of running Jar or Exe, but I don't think it worked.
I use the JSmooth EXE wrapper (launch4j somehow didn't work for me), and Java 8. Is there a straightforward solution to my question? Also, it's nice to explain how it works, or provide a link to the Java documentary about it.
EDIT: To clarify, let's say that I made a Java program and used a JAR wrapper, and I named the resulting EXE "test.exe". I want the Java program be able to give me the current directory of "test.exe", including the filename itself (test.exe).
ANOTHER EDIT: Just to clarify more, go onto your desktop, create a text file, and put some text in it. Save it, and change the text file to an EXE file. Then, try to open it. Windows will give an error. Notice how the title of the message dialog is the file path of the opened file. That is the type of output I want.
Thanks.
Per the JSmooth documentation,
JSmooth also makes some special variable accessible for your application.
Form Meaning
${EXECUTABLEPATH} Replaced by the path to the executable binary. For
instance, if the executable binary launched is located
at c:/program files/jsmooth/test.exe, this variable
is replaced with c:/program files/jsmooth
${EXECUTABLENAME} Replaced by the name of the executable binary. For
instance, if the executable binary launched is located
at c:/program files/jsmooth/test.exe, this variable is
replaced with test.exe
You set these in JSmooth under the "Environment Settings" (the last panel), which allows you to map the variable name. So,
MY_EXECUTABLEPATH=${EXECUTABLEPATH}
MY_EXECUTABLENAME=${EXECUTABLENAME}
In your application, you can get those with
String execPath = System.getProperty("MY_EXECUTABLEPATH");
String execName = System.getProperty("MY_EXECUTABLENAME");
public class JavaApplication1 {
public static void main(String[] args) {
System.out.println("Working Directory = " +
System.getProperty("user.dir"));
}
}
This will print a complete absolute path from where your application has initialized. It is used to get only the DIRECTORY.
If you are using a .exe why do you not create a installer? You can use Inno Setup, this way you are able to specify where do you want to store your .exe, and get it from your application just passing your custom directory

How can I run different projects from a script in windows?

I have two visual studio projects (for different purpose... they act on two different hardware) and also, I have a Java project that have control on something else. I am working in windows. My question is that how can I write a script (like shell script) to control different projects from a single program. More specifically, suppose I want to do something like this: execute project 1 with parameters x1,x2,...,xn, then execute project 2 with parameters y1,y2,...,yn, then execute project 1, then project 3, & so on...
Is there any tutorial or short description that I can follow to implement my concept?
There's a myriad of options/scripting languages/... to achieve this, but if you just want to run a bunch of exes then a simple windows batch file will do just fine:
#echo off
set my_exe=c:\path\to\my.exe
set my_other_exe=c:\path\to\my_other.exe
%my_exe% a
%my_exe% a b c
%my_other_exe% x
%my_other_exe% x y z
pause
Save this with your favourite editor with a .bat extension and run by double-clicking. The lines with set create variables so you don't have to paste the full path to your exes the whole time. The lines referring to those variables will invoke the executables aith the argumenst that come after it. Search the internet for 'batch file examples' or something like that and you will quickly find all the info needed.

How can i implement opening a file with my java program?

I have a basic, simple and maybe stupid question, but how do I implement that I can drag a file onto my java program and open it?
I searched really long for this basic question.....
As long as I found out you can't implement dragging it onto the .jar, because its not executable. You have to create a .exe, which also open your .jar, but that's all! I would really like to know how :)
A keyword would be enough, if I can get the answer through searching this keyword.
Thanks, Leander
//Edit: I may have expressed things a little bit complicated.
Later i want to have a shortcut on, for example, the desktop where i can drag any file on the shortcut and the programm opens with the file(it will, at this point) only move it to a special location.
I donĀ“t know how the code for this would be, I even don't know how to google for this (I only get questions how to implement "open with" with the answer Desktop.open(File f)).
For windows only:
option 1:
make a batch file into the directory of your jar file (or anywhere you like but then you need to adjust the path, you can also make a shortcut from the batch file).
#ECHO OFF
start java -jar %~dp0MYAPP.jar %1
option 2:
Make a shortcut (right click - new - shortcut)
Enter into the location "java -jar C:\path\to\myapp.jar"
drag and drop will work if your jar accepts filename as a parameter
public class Main {
public static void main(String[] args) {
if (args.length == 0)
System.out.println("No arguments");
else
System.out.println("1st argument: " + args[0]);
}
}
The place to start reading is the JDK 6 documentation on Drag and Drop. Or else you can start directly with the Drag and Drop tutorials.
If you want to create a desktop icon that will open your app when you drop a file on it, this depends on the OS. I think that Launch4j will support this, although I haven't used it in this way.
On window you can create .bat file, and if you DnD on that file you get filename as fisrt parameter
so code
echo %1
pause
writes the filename out, so you can start you java program like
java -jar myApp.jar MyAppClass %1

Categories

Resources