Opening more than one of the same Mac Application at once - java

I'm developing a Mac App in Java that logs into any one of our client's databases. My users want to have several copies of this program running so they can log into a couple clients at the same time, rather than logging out and logging back in.
How can I allow a user to open several copies of my App at once?
I'm using Eclipse to develop, and Jarbundler to make the app.
Edit: More Importantly, is there a way to do so in the code base, rather than have my user do something funky on their system? I'd rather just give them a 'Open New Window' menu item, then have them typing things into the Terminal.

You've probably already gotten enough code that you don't want to hear this, but you should really not be starting up two instances of the same application. There's a reason that you're finding it so difficult and that's because Apple doesn't want you to do it.
The OSX way of doing this is to use the Cocoa Document-based Application template in XCode. Apple Documentation: choosing a project.
This is something users are very accustomed to, and it works just fine. FTP programs, IRC clients, and many other types already use different "document" windows to point to different servers or channels. There's nothing inherently different about pointing to different databases.
Depending on how much code you've written, and how your application is designed, this may be pretty much impossible to implement without starting over. Developers who are encountering this problem during design phase, however, should definitely take Apple's advice.

From the Terminal, I can run
open -n -a appName.app
Then from Applescript, I can run
tell application "Terminal"
activaate
do script "open -n -a appName.app"
end tell
Then from Java, I can execute that script. Then, I can stuff that Java code into an Action. Then, stuff that action into a menu item that says "Open New Window".
That's what I'm going with for the moment. Now I just need to get the appName.

From the Terminal (or in a script wrapper):
/Applications/TextEdit.app/Contents/MacOS/TextEdit &
Something like that should work for you.
To do this in Java:
String[] cmd = { "/bin/sh", "-c", "[shell commmand goes here]" };
Process p = Runtime.getRuntime().exec (cmd);

If you are developing it in swing, you should just be able to instantiate the top Frame to create a new window.

Related

How to move Java runtime console to different terminal window?

I executed a Java program from the command line in terminal app A. I want to move the console to terminal app B without having to exit and re-execute the program.
I can think of a few potential ways to solve this, ranging from:
A) In Java implement a new InputStream and OutputStream that somehow can be wired to a new process started in terminal app B.
...to
B) Find a way to put the main Java process in terminal app A in the "background" so that original process can be reopened in a terminal app B.
Ideally, I want to be able to "log in to" and "log out of" my Java process from any terminal on my computer. Has anything like this already been accomplished, and which approach would be best to make it myself? I am open to solutions that involve Java code, shell scripts, or both.
My specs:
OSX: 10.12.4
Usually running zsh on iTerm
If I was using Linux, the perfect solution would be reptyr, a command line tool that allows you to easily switch terminal windows.
On Mac, the best solution I have found is screen. It can also be used to switch terminal windows but must be invoked before running java in order to work and seems a lot more complex.

Is it possible to interact with a Linux Command line interface (CLI) through a Graphical user interface (GUI)?

I am quite a beginner, any advice is much appreciated.
I have a linux application OpenBTS used to simulate and run a GSM network on a software defined radio device e.g USRP.
I want to build an application that interfaces with the OpenBTS command line on Linux. I want to give the user an easier way to configure and to display the current configurations of the application. The user would have an interface in which he could play with the configurations without the need to use the terminal.
I don't know if this is possible ?
Is it possible to interact with a Linux CLI through a GUI ? If yes what is the most efficient programming language, coding technique or approach to do that ?
Thanks a lot
You could generate a config file using your GUI and then use standard in to get the configuration into OpenBts. When launching OpenBts with the configuration file config.txt you could simply run it as follows.
./OpenBts < config.txt
You could also do this from you GUI by launching OpenBts in a process from your GUI application in a similar fashion, however this requires a fork() and exec()
In C++, you can take inputs from user through GUI then run appropriate openBTS commands using system()/popen(). Based on the return values of system()/popen(), can provide status of the operation back to the user.

Ncurses not supporting color

I am writing an android SSH Client. I have a terminal object that controls the view and an SSH object to send commands to the server.
My problem is that the terminal displays in color during all sessions but when an ncurses application opens, (tmux for example), the terminal displays in black and white.
I was able to find this: http://invisible-island.net/ncurses/ncurses.faq.html#white_black
I am not really sure what that means. Can anyone guide me on more documentation on this, or if there are any open source Java clients that support this feature. I am not really sure how to fix this.
Ok, so you launched the application without the TERM environmental variable set appropriately, and that meant that during the initialization routines the remote operating system believed it wasn't talking to a terminal that could support colors.
Now that you have it set correctly, your colors work. Congratulations! However, setting it inside the application is going to be quite a trick. This is because it needs to be set before you application launches. Otherwise, when the application launches, the low level libraries you are linking into will query the "environment" to see what kind of terminal it has, which determines what kind of terminal codes will be emitted by your application.
This all happens before you app launches; so, effectively, you can't really do it from your application. However, the real solution is a bit more interesting.
SSH makes very few assumptions about the display capabilities of the remote machine. The best way to "fix" this is to have the SSH client set the terminal type according to the SSH client's capabilities. Check your ssh client configuration to see if you can pass in a "better" terminal type.
In fact, having the host operating system assume the client's capabilities will create issues; however, demanding that every ssh client be configured to hand off it's terminal capabilities properly can be logistically impossible. So, you may want to strike a compromise. On the ssh server machine, try dropping a "wrapper script" to launch the application with a color terminal script. It would read something like
#!/bin/sh
TERM=xterm-256color
export TERM
exec launch-app "$#"
and be saved as launch-app-color or something similar.

Using a Java program I made on a Web Server

I created a small application that, when run, creates or updates some tables in a database by extracting data from some PDF files. Everything works fine in this desktop application, but the next step for me would be to make it possible for an administrator on a website to upload a PDF file and my Java program would then run and update the tables accordingly.
The problem is I have no idea where to start with this (the site isn't done yet, but I'm running some tests and it is going to be coded in PHP). I'd like to know what kind of technologies I need to let the server run the program and update everything as it would in the offline version. Sometimes it takes a while to update everything, so ideally, the user uploading the PDF could continue browsing other pages while the server does its job. (I'll probably implement something that when the server is done processing the file, it says if the program ended successfully or not in a log file)
Can someone tell me what terms to search for on Google or give me some pointers? I haven't chosen where my website is going to be hosted either, so if someone could tell me what to look for to know if they support running applications like this, I'd really appreciate it as well!
This could also apply to other programming languages as I know a bit of Python and C++ as well, so in the future I might have some applications in those languages I'll want to use on the web.
If I'm not approaching this the right way, I'm open to other suggestions, but the best solution would be to keep my Java program intact as I know it works exactly like I want it to and I'd rather not have to start it all over again.
If your host is *NIX based you can use crontab (Automatic Task Scheduler) to run your program at set intervals. Make it check if a "new" PDF exists, and run the program if there is. There may be a way to use Windows Task Scheduler type programs to do it on Windows. This is probably the easiest way.
Alternately you can use You can use shell_exec() in your php to execute a command on your *NIX system directly to run your java program.

connect to the internet using java

Whenever i want to connect to internet,i double click a connection icon(i created it earlier where username and password(for broadband) are stored) and click connect.The icon is in the network places(Windows XP)
May i know how to launch this connection from java or any other language? (I am asking this because my Internet Service Provider doesn't charge anything between 2 AM and 8AM :-) )
Creating a system task to run the program. You shouldn't need Java to execute a program on windows.
To use Scheduled Tasks in XP: http://support.microsoft.com/kb/308569
This is going to be unnecessarily difficult with Java, I believe. You'd have to write some native code to do the job for you, at which point you may as well write your whole program in C# or C++ anyway.
But, since you asked for a Java approach, you might want to look at the Robot class. It lets you move the mouse to a specific location on the screen, click, and otherwise automate the manual actions that you are doing. It's a very fragile solution.
Alternatively, if you can figure out what command the network connection shortcut is invoking, you can directly invoke it from Java using Runtime.exec.
(I don't really see why Java is good for this task, though.)

Categories