I have a Java app which needs to be used in a Remote Desktop Services environment.
As the javaw.exe process holds a file handle of the JAR file, I can not replace the JAR as long as other users are working with it.
I can also not see the current users as there might be many other javaw.exe processes for other JAR files running on the same server. And in a server farm I would have to check every single server for open instances.
Is there a best practice to deploy and update Java apps in this environment?
Some ideas:
use a launcher app which has a configuration file which specifies the location of the JAR file
modify the entry in the start menu to point to the new JAR file location
copy the jar to a user-specific work folder on logon
use JWS
Option 3 and 4 however would mean that Log4J output needs to be directed to a location in a folder which can be accessed by operations / developers
Related
Can anyone help me understand the classpath logic when deploying Java applications to remote hosts?
Netbeans will build, deploy and execute my Java application correctly on a remote Linux (Ubutntu 20.x) host.
Lets say that the executable JAR is deployed and executed in:
/home/user/project/dist
With any supporting library files copied to:
/home/user/project/dist/lib
This all makes sense to me.
However, I wish to read application and log4j2 configuration files. I would think that these should be placed in the same directory as the jar file. However they must be placed in the parent directory:
/home/user/project
Okay... BUT...
If I amend my code to write out a text file (to the executable directory) the resulting text file is written to:
/home/user/project/
<Edited 19Jun22>
I want my deployed application to read the log4j2.xml and configuration files from the same directory that my application writes to. What configuration settings must I change in Netbeans?
Alternatively is there a way to make Netbeans deploy to /home/user/project instead of /home/user/project/dist?
I have a Java project which gives me output based on user's request in the front end.
The output is like it will give me the list of devices from each and every server(based on click of a radio button).
Now I need to set up a crontab job which will run at a particular time and it will automatically get the output of all the servers without user's request.
Can anyone give me an approach as how I need to tune my program so that it will automatically give the list of all devices.?
Also do I have to create a war file and deploy that in crone tab to run the daily job?
WAR files are Web ARchives, meant to run inside a Web Container (think Tomcat, JBOSS, etc) - probably you want an executable JAR file. You are probably thinking of Java ARchive (JAR) files.
I would first create an executable JAR file and then schedule it as a CRON job to run at the frequency you wish.
How to create an executable JAR file
How to setup a CRON
job
I am using apache log4j from java 1.6.
I am creating exe file using exe4j and when I place it in the production folders -
logs are being created successfully.
Now, I have turned it into service exe
(checked a "service" checkbox in exe4j and installed it with SC command )
and log files stopped being created .
is there an explanation/solution for it ?
Thanks.
Your service most likely is running as an account (LOCAL SERVICE?) that does not have permission to write to the log folder.
To check the account under the service is running on, right-click the service in the Services panel, select Properties, and view the LogOn tab (for Windows 7... exact steps for other Windows versions will vary but the idea is the same).
I would suggest continuing to run your service with the least privileges it needs and modify access rights to the log folder to allow the account the service is running under to write to that folder (Principal of Least Privilege). Of course, don't have anything except logs in that folder.
I'm going to develop a java web start application, which need to access protected system directory and install a program there.
I know, how to exit sandbox, my application is signed and have access to filesystem. The problem is, that it sill can't access directories like C:/windows/system32.
I found solutions for standalone java applications:
Java: run as administrator
How to do this in java web start?
Thanks in advance for answer!
In your case you can probably try to use the following trick:
Precompile a jar file with the Manifest pointing to the main
class, that carries out all of the required filesystem routines
Put this jar somewhere into the resources folder of your Web-Start
application and then copy it into the user's Temp folder upon
Web-Start execution
Provision required files from the elevation
PowerToys
in the similar manner
Call " %PATH_TO_USER_TEMP%/elevate"
command together with "java -jar %PATH_TO_USER_TEMP%/yourJar.jar"
(please refer to the article above or additional documentation on
the Elevation PowerToys to find out the details)
If everything
works out, user shall be presented with a request to grant the
executed java process required Admin privileges.
I've created a web application using Netbeans. Before, when I was running the web app via netbeans and tomcat server (which was a zip), all my external files (uploaded files and other helper files I use for my app) are stored in bin directory.
Now, I tried installing an apache tomcat service using windows installer because I wanted to know how to deploy the project on a dedicated server. I have successfully deployed the war file using tomcat's deploy utility. However, when I run the project via the apache tomcat windows service, it is not saving the files in bin dir and it cannot read my files that I pasted in bin dir, too.
Where do you think should I place my files?
EDIT: Upon observing the tomcat service directory, I found out that it is store in the root. If I have my tomcat installed at 'E:\Apache\services\tomcat\', it is stored at the 'tomcat' directory.
Ultimately, it is what your application does that determines where the files are stored.
By the sounds of it, your application is storing files in the current directory of the JVM, which happens to be the "bin" directory when you launch the web server via NetBeans. If so, you will find them, in whatever the current directory is when Tomcat is launched as a windows service.
Frankly, I think you've got this wrong. You should be making a conscious decision as to were uploaded files should be stored, and then making sure that the upload mechanism you are using puts them there.
Obviously, putting them in the current directory is a bad idea. You don't want them being stored in different places depending on how the web container is started. And obviously the "bin" directory is an inappropriate place. (What happens if the user tries to upload a file whose name matches one of the scripts that live in "bin"?)
So where should you be putting the files?
In my opinion, you've got three choices:
In a subdirectory of the work directory ... which is where Tomcat conventionally puts transitory files such as compiled JSPs.
In a custom subdirectory of the Tomcat installation directory.
In a separate directory somewhere else in the file system.
You shouldn't be dropping then in the webapp directory, because files there are typically blown away when the webapp is redeployed, and because there's a greater risk that uploaded files will interfere with your webapp.
You shouldn't be dropping them in the bin or logs or lib or config directories because of the risk of interference ... and because they are simply not the logical place.
If you want to write files relative to the root of the tomcat installation directory, you can find out what that is by calling System.getProperty("catalina.base").
But what ever you do, you need to make sure that a user can't accidentally or deliberately upload files to the wrong place; e.g by supplying an absolute pathname, or a pathname that uses "../../...." to escape from your upload area.
When you install Apache, the project should be inside the webapp folder :
C:\Apache\tomcat\webapps
Like my Project is gaganisonline so the directory structure is something like this :
Path : C:\Apache\tomcat\webapps\gaganisonline
gaganisonline
| |
WEB-INF index.html
|
---------------------------
| | | |
web.xml src lib classes