Running .bat file that launches .jar as administrator - java

So I am trying to set up an H2 database server. So I took the installer from their website ,
after getting the Path for windows fixed. If I run my bat as typical user the server launches , but when I try to connect it crushes because , writing a lock needs admin rights. So if I try run it as admin , I get ERROR: Could not find or load main class org.h2.tools.Console

That sounds like either
a classpath problem, if you are including the jar in your own application
or
a Windows ACL problem i.e. you're trying to access a part of the filesystem that your user cannot write to.
or
both of the above

Related

How can I host my Springboot application in my own computer like a background service?

I want to host my springboot application on my on PC, I want it to start with the computer, just like databases do. But I can't find anything related (probably because I am asking the 'wrong' way). There is any way to start the springboot application with my pc in the background, with no CMD showing or having to keep intelijj open?
I tried to search how to host the application, but didn't found any thing 'locally' based, everything was how to host in X cloud or Y domain/host. What I want is to my application run on the background of my PC so I can use it as a personal system, but don't want to keep a cmd open or intelijj
Also I can't really use docker.. that was the way I was trying before, but I can't let Hyper-v active..
There are 2 steps:
Get command line of execution of your application runned by IntelliJ. To do so:
You have to create a file with extension ".bat" (batch file) with the contents of the command copied above, than follow the steps bellow to define it to run in the startup configuration of the windows 10:
Run a batch file at loading of Windows 8 and 10 Once the shortcut is created, right-click the shortcut file and select Cut. Press Start, type Run, and press Enter . In the Run window, type shell:startup to open the Startup folder.

How to run PostgreSQL as a service in windows?

I installed postgreSQL binaries in windows 7 32bit operating system; I can start the server from cmd but I cant run it as a windows service.
This is the error that I'm getting when I try to start the service manually:
"The postgreSQL service on local computer started and then stopped. some services stop automatically if they are not in use by other servces or programs"
All I need to do is; after booting to windows when I double clicked my java application I need to run my app smoothly without any database errors. I cannot do this because postgreSQL is not running as a windows service.
I found this in windows event viewer:
The description for Event ID 0 from source PostgreSQL cannot be found.
Either the component that raises this event is not installed on your local computer or the installation is corrupted.
You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
postgres cannot access the server configuration file
"C:/Windows/system32/pgsql/data/postgresql.conf": No such file or directory
I googled about it but I was not able to find an answer.
Problem was solved
path to the data directory was wrong in windows service file.
So I delete the service file from this method:
1)Run Regedit or Regedt32.
2)Go to the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"
3)Look for the postgreSQL service that you want delete and delete it.
4)reboot the computer.
After that open the cmd (Run as administrator) Go to the postgreSQL bin directory and run this command to create a new windows service:
pg_ctl.exe register -N "PostgreSQL" -U "NT AUTHORITY\NetworkService" -D "C:/Program Files/postgresql/pgsql/bin/pgsql/data" -w
This worked for me. Hope this will help.
This is a note for a normal user. If using an official installer it should has a build-in service,
Win+R and type services.msc
Search Postgres service based on the version installed,
e.g., "postgresql-x64-13 - PostgreSQL Server 13"
Click stop, start, or restart the service option
postgres cannot access the server configuration file
"C:/Windows/system32/pgsql/data/postgresql.conf": No such file or
directory
This looks like your working directory is C:\Windows\system32 and you are running postgres there and it looks for data/postgresql.conf.
Try changing the working directory or specifying -D C:\path\to\my\data.

running a java application as superuser

I have a build java application for mac I want to run the application as root/superuser all the time when the application opened up. how would i go about to achieve this, I don't want to make a script that runs the jar or open terminal and type sudo to run the jar. I want it where if they double click on the runnable jar it will prompt the user requesting for root right.

Execute a java program on login

I need to write a program which executes
whenever some one logged In to the windows system.
It is for daily report generation purpose.
I have written the program but couldn't get how to execute it on user login.
All the help would really be appreciated.
EDIT most of the people suggesting that I should put file in startup folder, but startup files only execute if 'system started/restarted'... I need to run the program whenever a user login like if the computer is started but locked and then someone unlocks, this program should be executed.
Correct me if I am wrong.
If you are working on a Windows OS then you can create an executable jar file of your java.
In order to make it launch at login you need to include it to the windows startup list.
You can create a batch file (.bat) in which you put:
"<YOUR PATH TO JAVA>/javaw" -jar "YourJar.jar"
Add this .bat file to windows startup check this
Batch/CMD: Adding files to Startup list
Hope it helps !
Setup your java application to run as a windows service.I think this answer will help you.
Answer is here
Create a batch program and put it on startup that should start your target file to run what you want to do.....
batch code :
start java target.java
Must setup the path for startup b4 run....
#happy Dev: hope you already know how to make a .bat in windows, just create a bat file which has line to execute java. or for more help on this you can see:
http://introcs.cs.princeton.edu/java/15inout/windows-cmd.html
Just make sure you have java installed on that machine. and your environment variable is set for java other wise you have to provide the complete java bin path.
Regarding how to run on login. simple way to go:
for windows 7: start menu--> All programs--> find a folder name startup and right click on it. there you can see open for all users open it and place your file there. every time when some user login the bat file will be executed automatically. and remember this wont work on hibernate. or to open that location you can just go to:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
for Other OS path is almost similar with just a minor difference.
You can use Task Scheduler for Windows Platform and configure which file to call at Login Time.
C:\Windows\system32\taskschd is the location.
Create a basic Task or Create Task...... are the options.!!
You can schedule the time of your task to get executed.

Cannot Execute a EXE file If Tomcat Running as a service in java

I am using Apache tomcat (7.0.39) to run my java web application .
In that application I am calling the executable file . It is working well if I start the Tomcat using
Startup.bat . If I start Tomcat as a service , Executable file doesn't run and windows shows
"Exe file encoutered a problem . We are sorry for the inconvenience caused"
I need this because tomcat starts during Windows startup. If I start the Tomcat using Startup.bat , then the command prompt opens and it doesn't exit. It remains open . Anyone give solution ?
Tomcat will run as a different user when started as a service, check if that user has permission to execute the exe file.
Or maybe the exe accesses other files via a relative path and only finds them when started via command line.

Categories