I hav made a java application using Java Swing. It uses derby db for database and host=localhost.
I am able to start database and connect it to my application using command prompt in windows.But to deploy my application want this to happen automatically with the help few lines within my java program.I tried executing commands in a .bat file but with it black window of command prompt always remains open which I don't want.So I tried doing this:-
Process pserver=Runtime.getRuntime().exec("cmd /c set DERBY_HOME=E:\\db-derby-10.9.1.0-bin");
ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\Java\\jdk1.6.0_33\\bin\\java", "-jar", "E:\\db-derby-10.9.1.0-bin\\lib\\derbyrun.jar server start");
pserver= pb.start();
pserver=Runtime.getRuntime().exec("cmd /c set DERBY_INSTALL=E:\\db-derby-10.9.1.0-bin");
pserver=Runtime.getRuntime().exec("cmd /c start set CLASSPATH=%DERBY_INSTALL%\\lib\\derbyclient.jar;%DERBY_INSTALL%\\lib\\derbytools.jar;. ");
I also tried using API http://db.apache.org/derby/docs/10.0/manuals/admin/hubprnt14.html-NetworkServerControl. I am unable to understand what package to import and which all libraries to include.
Someone please help me connecting my java application with derby database eitherby API or by using Process and RunTime class or some better method.
Perhaps you don't need to run Derby as a Network Server. Why don't you just use Derby in embedded mode instead? See this section of the documentation for more information: http://db.apache.org/derby/docs/10.9/getstart/cgsquck70629.html
I found out what the problem was. I was trying to start the database server using the user interface of netbeans (JavaDB), which works only in netbeans IDE and doesn't put any code in program automatically as it does for other components. So to start and stop the DB serverin an external environment I had to explicitly type the code as given in http://db.apache.org/derby/docs/10.8/adminguide/tadminconfig814963.html.
Related
I'm trying to replicate the behavior of Linux where we create an application launcher using Alacarte providing it the command and file name and Icon using batch
However I have never used batch.
The batch file is in the same directory as the java application.
The Batch contains the command as:
java -javaagent:app1.jar -jar app2.jar
Which does the job but It keeps CMD running in the background which during work I always accidentally close it which turns out closing the java app.
How can I can make it so it will disappear after launching the app and keep the app running
On Windows use javaw, as this will not open the console window. See also java vs javaw
I have downloaded the zip folder of neo4j community edition version-2.3.1 in order to start connecting the neo4j server through Java code. I want to create graph database for indexing of the data. Followed this link originally.
PROBLEMS
I'm unable to start the neo4j server as the batch file is deprecated and it displays the following message:
Tried using the PowerShell scripts commands also with reference to this link, it just opens the script file. the server is not started with these commands.
Where I am going wrong and what is the right procedure to start the local neo4j server and connect it through Java code to create nodes and relationships of the graph.
The batch file will still work even though it has been deprecated. It appears that the batch file cannot find the Findstr command.
findstr.exe should be in %windir%\system32\
If it is there and you are getting the findstr is not recognized as an internal or external command” error, check that %windir%\system32\ is in your PATH.
Once that works, try the Neo4j.bat file again.
And as Anton mentioned, please explain how the Powershell didn't work and what actions you took.
I was wondering if it was possible to execute commands from PHP to a Java prompt which is already running?
I have tried the solution listed here:
How to run a shell command through PHP code?
and this provided no functionality
Let me explain
The java is running on one screen of the linux server
sudo apt-get install screen
and running the .jar file through the command line.
I am then running a webserver, which will have an admin accessibility to restricted areas, which will contain scrips to run specific commands through that already running .jar file?
You can implement some kind of IPC. The java file listens to a port and receives the commands. Or you can write the commands in a specific file which the java programm reads. I think under linux you can also use shared memory: http://www.php.net/manual/en/book.shmop.php
It is possible by sending the command to the screen session. I used this for a minecraft server once.
screen -S <sessionname> -X stuff "<command>\r"
This would (IIRC) provide the same output as if you where inside the screen, typed the command and pressed enter.
I hope this was what you wanted.
I am creating a desktop application. I know how to add program to system tray, that consists of a continuous system process, I need instructions on how to add java code to system configuration startup menu. Like antivirus program which automatically executes on starting the system. would be of great help with example code
Write a batch file(.bat) which executes you java program. Add this batch file into the registry in such a way that it will be executed during system startup.
simply write following into your batch file
java filename
In linux you will hv to create a .sh script(executable) that will execute your java program.
put .sh in /etc/rc0.d using following commands
cp name.sh /etc/rc0.d/
chmod +x /etc/rc0.d/name.sh
We work on the Java application .Our the application we need to call some service which is a window installer and that when run from the command prompt accept the input file and gives the result as an output file.
Java application is on Linux and window service is on window so my question is that how can i call this window service from my java code.
I thought of writing some kind of a scheduler but how will i make sure that the scheduler runs only when the input file gets copied on the Window env from the Linux m/c and how will i get back the result that the installer has run the programme and generated the output file.
Please help in suggesting some idea.
Use ProcessBuilder to execute the external program of installer.
Maybe this my question can help you with that, and please read before that When Runtime.exec() won't