How to configure current working directory in Tomcat? - java

I recently migrated a tomcat application from one Linux server to another. Since then, I am facing a new file creation issue on the new server. In the new server, when I try to create a file it fails, which works fine in the old server:
File convFile = new File(file.getOriginalFilename());
convFile.createNewFile(); //this FAILS
FileOutputStream fos = new FileOutputStream(convFile);
fos.write(file.getBytes());
fos.close();
To investigate the issue, I printed the working directory using:
String cwd = new File("").getAbsolutePath();
System.out.println(cwd);
And this debugging revealed the root cause behind the issue:
The old server returned: var/lib/tomcat, whereas the new server returned: / (the root directory)
As the tomcat user did not (and should not) have write permission on root directory, it failed to create the file.
My question, which factor decides the current working directory of Tomcat, and how to configure it?
Here are my Tomcat and java environment variables.
Environment="JAVA_HOME=/usr/lib/jvm/jre"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"
Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Update: I tried -Duser.dir to configure the working directory. After using this, I get expected result from System.out.println(cwd);. But the issue still persists, the file creation fails. apparently, this does not work for FileOutputStreams.
Source: Changing the current working directory in Java?
The ownership and permissions are handled properly. I am looking for a system-side solution without making any code change, as the same code is working in the old server.

I'm doing startup with systemd on RHEL 8.3.
For that, I found that adding this stanza before the ExecStart got desired result:
WorkingDirectory=/data/desired/catalina_base
YMMV with other flavours and startup options - just use absolute path for both ExecStart & WorkingDirectory
Full platform:
Server version name: Apache Tomcat/9.0.54
Server built: Sep 28 2021 13:51:49 UTC
Server version number: 9.0.54.0
OS Name: Linux
OS Version: 4.18.0-240.22.1.el8_3.x86_64
Architecture: amd64
Java Home: /usr/lib/jvm/java-11-openjdk-11.0.10.0.9-4.el8_3.x86_64
JVM Version: 11.0.10+9-LTS
JVM Vendor: Red Hat, Inc.

Related

"Unavaliable io exception" when connecting to remote Bazel master on bazel-buildfarm

I want to setup a small POC remote area with 1x master (192.168.60.99) and 1x worker (192.168.60.98) using bazel-buildfarm. Both are CentOS 7 machines provisioned with Vagrant. When connection from a Ubuntu workstation (third machine) in the network, the following error occurs:
$ bazel build --verbose_failures //projects/myproj:app
Starting local Bazel server and connecting to it...
INFO: Options provided by the client:
Inherited 'common' options: --isatty=1 --terminal_columns=229
INFO: Reading rc options for 'build' from /home/user/tests/ecommerce/.bazelrc:
'build' options: --strategy=TypeScriptCompile=worker --strategy=AngularTemplateCompile=worker --symlink_prefix=dist/ --define=compile=legacy --incompatible_strict_action_env --experimental_allow_incremental_repository_updates --distdir=third_party/_distdir
INFO: Reading rc options for 'build' from /home/user/.bazelrc:
'build' options: --spawn_strategy=remote --genrule_strategy=remote --strategy=Javac=remote --strategy=Closure=remote --remote_executor=192.168.60.99:8980
INFO: Writing tracer profile to '/home/user/.cache/bazel/_bazel_user/24700f1ad3e201a00a1c26bd59dc6502/command.profile.gz'
INFO: Invocation ID: 569b59ca-edcb-4922-92a0-b6f0b5ca2819
ERROR: Failed to query remote execution capabilities: UNAVAILABLE: io exception
The network connection is working and I even can connect to Bazel using telnet:
telnet 192.168.60.99 8980
Trying 192.168.60.99...
Connected to 192.168.60.99.
Escape character is '^]'.
.bazelrc file of the third Ubuntu machine:
$ cat ~/.bazelrc
build --spawn_strategy=remote --genrule_strategy=remote --strategy=Javac=remote --strategy=Closure=remote --remote_executor=192.168.60.99:8980
Buildfarm setup
Both got a clon of the buildfarm git repo. The example config files were used. Just on the server I replaced localhost by 192.168.60.99 (master server ip).
I know that bazel run is not recommended. But in lack of better alternatives that works, my idea is to get the documented way working first (Bazel itself doesn't mention any alternative). Since not even bazel run works, I think that something is wrong with my installation.
All machines use version 1.1.0, which is the latest stable one at the time of writing. It's definitely an issue with bazel-buildfarm, since the local build works fine on the Ubuntu machine.
Master server
bazel run //src/main/java/build/buildfarm:buildfarm-server $(pwd)/examples/server.config.example
Worker
bazel run //src/main/java/build/buildfarm:buildfarm-operationqueue-worker $(pwd)/examples/worker.config.example --distdir ~/distdir/
The distdir is a workaround for our company proxy, that manipulates files with MITM attacks. Since Bazel doesn't allow this, I downloaded the affected file for it's jdk manually:
[vagrant#localhost bazel-buildfarm]$ l ~/distdir/
total 188M
-rw-rw-r--. 1 vagrant vagrant 188M Jan 17 2019 zulu11.2.3-jdk11.0.1-linux_x64.tar.gz
If Bazel >= 1.0 is used , we need to specify the protocol grpc in .bazelrc like this:
--remote_executor=grpc://192.168.60.99:8980
Without the protocol, the UNAVAILABLE: io exception occurs. There is currently no documentation about this issue.

Netbeans set root as author

I'm running Linux Mint 18.3 cinnamon 64 bits
I just downloaded Apache NetBeans IDE 9.0
It wasn't necessary to run any script to install it, i just had to run the following command to launch it: sudo /opt/netbeans/bin/netbeans
Then enter my password and netbeans opens.
Then i made a launcher for the program because i didn't want to type the command and my password every time i open netbeans.
But the launcher didn't worked.
I realize that i didn't put "sudo" in the command that the launcher would execute so i put it. And didn't work.
I thought that it wasn't working because the launcher executes sudo /opt/netbeans/bin/netbeans but don't put the password.
After some research i end up adding star_man ALL=(ALL) NOPASSWD: /opt/netbeans/bin/netbeans at the end of /etc/sudoers and it finally works. But when i create a new project Netbeans sets root as the author of every file it creates.
For example, when i type ls -l in my project directory it outputs this:
-rw-r--r-- 1 root root 3527 sep 15 20:01 build.xml
-rw-r--r-- 1 root root 82 sep 15 20:01 manifest.mf
drwxr-xr-x 3 root root 4096 sep 15 20:01 nbproject
drwxr-xr-x 3 root root 4096 sep 15 20:01 src
Root is the group and the owner of every file an directory.
This causes that when Netbeans generates documentation files it put "root" instead my username.
Update:
I only can start neatbeans as root (sudo ./netbeans).
when i run neatbean without sudo from the terminal it looks like it's starting:screen shot
but then it closes.
This is the output:
>Log Session: Sunday, September 16, 2018 at 12:58:20 PM Eastern Daylight Time
>System Info:
Product Version = Apache NetBeans IDE 9.0 (Build incubator-netbeans-release-334-on-20180708)
Operating System = Linux version 4.15.0-34-generic running on amd64
Java; VM; Vendor = 10.0.1; Java HotSpot(TM) 64-Bit Server VM 10.0.1+10; Oracle Corporation
Runtime = Java(TM) SE Runtime Environment 10.0.1+10
Java Home = /opt/java/jdk-10.0.1
System Locale; Encoding = es_DO (nb); UTF-8
Home Directory = /home/star_man
Current Directory = /opt/netbeans
User Directory = /home/star_man/.netbeans/9.0
Cache Directory = /home/star_man/.cache/netbeans/9.0
Installation = /opt/netbeans/nb
/opt/netbeans/ide
/opt/netbeans/extide
/opt/netbeans/java
/opt/netbeans/apisupport
/opt/netbeans/websvccommon
/opt/netbeans/profiler
/opt/netbeans/harness
/opt/netbeans/javafx
/opt/netbeans/platform
Boot & Ext. Classpath =
Application Classpath = /opt/netbeans/platform/lib/boot.jar:/opt/netbeans/platform/lib/org-openide-modules.jar:/opt/netbeans/platform/lib/org-openide-util.jar:/opt/netbeans/platform/lib/org-openide-util-lookup.jar:/opt/netbeans/platform/lib/org-openide-util-ui.jar
Startup Classpath = /opt/netbeans/platform/core/core-base.jar:/opt/netbeans/platform/core/org-netbeans-libs-asm.jar:/opt/netbeans/platform/core/asm-all-5.0.1.jar:/opt/netbeans/platform/core/org-openide-filesystems.jar:/opt/netbeans/platform/core/org-openide-filesystems-compat8.jar:/opt/netbeans/platform/core/core.jar:/opt/netbeans/nb/core/org-netbeans-upgrader.jar:/opt/netbeans/nb/core/locale/core_nb.jar
-------------------------------------------------------------------------------
INFO [org.netbeans.modules.netbinox]: Install area set to file:/opt/netbeans/
!SESSION 2018-09-16 12:58:21.698 -----------------------------------------------
eclipse.buildId=unknown
java.version=10.0.1
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=es_DO
!ENTRY org.eclipse.osgi 4 0 2018-09-16 12:58:21.706
!MESSAGE Error reading configuration: Permission denied
!STACK 0
java.io.IOException: Permission denied
at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.base/java.io.File.createTempFile(File.java:2090)
at org.eclipse.osgi.storagemanager.StorageManager.initializeInstanceFile(StorageManager.java:188)
at org.eclipse.osgi.storagemanager.StorageManager.open(StorageManager.java:708)
at org.eclipse.osgi.internal.baseadaptor.BaseStorage.initFileManager(BaseStorage.java:226)
at org.eclipse.osgi.internal.baseadaptor.BaseStorage.initialize(BaseStorage.java:160)
at org.eclipse.osgi.baseadaptor.BaseAdaptor.initializeStorage(BaseAdaptor.java:123)
at org.eclipse.osgi.framework.internal.core.Framework.<init>(Framework.java:192)
at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.internalInit(EquinoxLauncher.java:67)
at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.init(EquinoxLauncher.java:37)
at org.eclipse.osgi.launch.Equinox.init(Equinox.java:178)
at org.netbeans.modules.netbinox.Netbinox.init(Netbinox.java:61)
at org.netbeans.core.netigso.Netigso.prepare(Netigso.java:145)
at org.netbeans.NetigsoHandle.turnOn(NetigsoHandle.java:115)
at org.netbeans.ModuleManager.enable(ModuleManager.java:1331)
at org.netbeans.ModuleManager.enable(ModuleManager.java:1148)
at org.netbeans.core.startup.ModuleList.installNew(ModuleList.java:315)
at org.netbeans.core.startup.ModuleList.trigger(ModuleList.java:251)
at org.netbeans.core.startup.ModuleSystem.restore(ModuleSystem.java:276)
at org.netbeans.core.startup.Main.getModuleSystem(Main.java:156)
at org.netbeans.core.startup.Main.getModuleSystem(Main.java:125)
at org.netbeans.core.startup.Main.start(Main.java:282)
at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:98)
at java.base/java.lang.Thread.run(Thread.java:844)
java.lang.RuntimeException: Permission denied
at org.eclipse.osgi.framework.internal.core.Framework.<init>(Framework.java:194)
at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.internalInit(EquinoxLauncher.java:67)
at org.eclipse.osgi.framework.internal.core.EquinoxLauncher.init(EquinoxLauncher.java:37)
at org.eclipse.osgi.launch.Equinox.init(Equinox.java:178)
at org.netbeans.modules.netbinox.Netbinox.init(Netbinox.java:61)
at org.netbeans.core.netigso.Netigso.prepare(Netigso.java:145)
at org.netbeans.NetigsoHandle.turnOn(NetigsoHandle.java:115)
at org.netbeans.ModuleManager.enable(ModuleManager.java:1331)
at org.netbeans.ModuleManager.enable(ModuleManager.java:1148)
at org.netbeans.core.startup.ModuleList.installNew(ModuleList.java:315)
at org.netbeans.core.startup.ModuleList.trigger(ModuleList.java:251)
at org.netbeans.core.startup.ModuleSystem.restore(ModuleSystem.java:276)
at org.netbeans.core.startup.Main.getModuleSystem(Main.java:156)
at org.netbeans.core.startup.Main.getModuleSystem(Main.java:125)
at org.netbeans.core.startup.Main.start(Main.java:282)
at org.netbeans.core.startup.TopThreadGroup.run(TopThreadGroup.java:98)
at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.io.IOException: Permission denied
at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.base/java.io.File.createTempFile(File.java:2090)
at org.eclipse.osgi.storagemanager.StorageManager.initializeInstanceFile(StorageManager.java:188)
at org.eclipse.osgi.storagemanager.StorageManager.open(StorageManager.java:708)
at org.eclipse.osgi.internal.baseadaptor.BaseStorage.initFileManager(BaseStorage.java:226)
at org.eclipse.osgi.internal.baseadaptor.BaseStorage.initialize(BaseStorage.java:160)
at org.eclipse.osgi.baseadaptor.BaseAdaptor.initializeStorage(BaseAdaptor.java:123)
at org.eclipse.osgi.framework.internal.core.Framework.<init>(Framework.java:192)
... 16 more
I find out that every file and directory under ~/.netbeans has root as owner and group. I thought that might be the problem so i changed the owner and group with ~/.netbeans $ sudo chown -R myusername: .netbeans/. And still i'm only able to run netbeans as root.
This is a basic unix permissions problem.
For reasons that escape me, you used sudo to launch the netbeans IDE.
- You should not have done that.
- You should not have needed to do that!
When you use sudo to run something, you are typically running as the root user. (That is what sudo does!)
So, naturally, the something (in this case, the netbeans application run using sudo) will create files and directories owned by the "root" user. So when you try to update them as a normal user, the operating system says "Nope: you don't own those files / directories, so you can't modify them.".
Solution: use the chown command to change the ownership of the files and the directories as required.
How? Read man chown, or look for a tutorial on how to change the ownership of a file.
Hint: you will need to use sudo when chowning ...
Hint 2: be very, very careful when you use sudo, because sudo has the power to trash your system if you make a mistake.

Launching Jade In Ubuntu10.04 Linux

When I run the below command in terminal of ubuntu linux and also I set the ClassPath properly but I wasn't successful.
java jade.Boot -gui
I got following errors in terminal window:
15 Jun, 2011 6:33:10 PM jade.core.Runtime beginContainer
INFO: ----------------------------------
This is JADE snapshot - revision 6357 of 2010/07/06 16:27:34
downloaded in Open Source, under LGPL restrictions,
at http://jade.tilab.com/
----------------------------------------
Retrieving CommandDispatcher for platform null
15 Jun, 2011 6:33:11 PM jade.imtp.leap.CommandDispatcher addICP
WARNING: Error adding ICP jade.imtp.leap.JICP.JICPPeer#ae506e[Error: Not possible to launch JADE on a remote host (127.0.1.1). Check the -host and -local-host options.].
15 Jun, 2011 6:33:11 PM jade.core.AgentContainerImpl joinPlatform
SEVERE: Communication failure while joining agent platform: No ICP active
jade.core.IMTPException: No ICP active
at jade.imtp.leap.LEAPIMTPManager.initialize(LEAPIMTPManager.java:138)
at jade.core.AgentContainerImpl.init(AgentContainerImpl.java:316)
at jade.core.AgentContainerImpl.joinPlatform(AgentContainerImpl.java:482)
at jade.core.Runtime.createMainContainer(Runtime.java:165)
at jade.Boot.main(Boot.java:89)
15 Jun, 2011 6:33:11 PM jade.core.Runtime$1 run
INFO: JADE is closing down now.
help me to recover from this error.
I am so tired of this problem. It is one of many quirks and problems with JADE.
The problem you are facing is that you need to supply correct host information in the command line. Example
java jade.Boot -gui -local-host
This is all described here: http://jade.tilab.com/doc/tutorials/JADEAdmin/startJade.html
In many cases you don't have this problem and then it is sufficient to use the -gui option only. However I have discovered that Jade does not work very well when your resolves to 127.0.1.1. You can fix this by setting your IP address in or if you are on Linux edit your /etc/hosts file for a more permanent solution.
just type in JADE path..
java -cp lib/jade.jar jade.Boot -gui -local-host 127.0.0.1
(JADE has some problems to set local host adress)
The problem might be is previous java process might be still running on the local port , Make sure to check if port is in use or not if in use kill the java process before you rerun.
It's simple.
Modify /etc/hosts
Modify the line for the address 127.0.0.1, as follows:
127.0.0.1 localhost.localdomain localhost <machine_name>
Remove or comment the line with 127.0.1.1:
# 127.0.1.1 <machine_name>
and you're done.
The error isn't in the jade. It's a bug used by jade to start the default parameters with a bugged java method that should be fixed.
When jade runs the java method, it will retrieve 127.0.1.1 instead the loop-back 127.0.0.1.
I'm saying it because I tested. I read the JADE src that do this and I executed the java method that I didn't remember now.
Unfortunately it's happening in a few linux machines. In windows I didn't see it happens.
What I did to solve this problem was to edit the /etc/hosts file, like this:
Original file:
127.0.0.1 localhost
127.0.1.1 machine-name
Modified file:
127.0.0.1 localhost machine-name
127.0.1.1 machine-name
What I did was to put an alias of the machine-name on the loop-back ip address. This will bypass the bug.

GWT - Netbeans cant start dev mode

I have netbeans with the GWT4NB plugin installed. My code can compile and works with production mode. But when I try to launch the dev mode aka hosted mode in Netbeans the GWTShell window doesn't load. Getting this to work would be greatly useful for debugging. Here is my error in the console:
GWT4NB https://gwt4nb.dev.java.net
GWT installation directory: C:\Users\Guillaume\.netbeans\6.9\framework\gwt-2.1.0
init:
debug-connect-gwt-shell-hosted-15:
Unknown argument: -style
Google Web Toolkit 2.1.0
GWTShell [-noserver] [-port port-number | "auto"] [-whitelist whitelist-string] [-blacklist blacklist-string] [-logdir directory] [-logLevel level] [-gen dir] [-bindAddress host-name-or-address] [-codeServerPort port-number | "auto"] [-out dir] [url]
where
-noserver Prevents the embedded web server from running
-port Specifies the TCP port for the embedded web server (defaults to 8888)
-whitelist Allows the user to browse URLs that match the specified regexes (comma or space separated)
-blacklist Prevents the user browsing URLs that match the specified regexes (comma or space separated)
-logdir Logs to a file in the given directory, as well as graphically
-logLevel The level of logging detail: ERROR, WARN, INFO, TRACE, DEBUG, SPAM, or ALL
-gen Debugging: causes normally-transient generated types to be saved in the specified directory
-bindAddress Specifies the bind address for the code server and web server (defaults to 127.0.0.1)
-codeServerPort Specifies the TCP port for the code server (defaults to 9997)
-out The directory to write output files into (defaults to current)
and
url Automatically launches the specified URL
Java Result: -1
init:
The problem seems to be the unknown -style argument. I tried changing this argument in build-gwt.xml under the gwt 2.0 section, no changes. Why isnt gwt 2.1 not in the xml config file also?
I have the same issue and fix it manually on every restart by setting the gwt version as '2.0' even if I am actually on 2.2.
The problem is caused by the fact that the GWT4NB does not undertand the version of GWT you are using and so tries with GWT 1.5, that is pretty different from modern ones.

Unable to deploy in Netbeans 6.7.1 and Glassfish v2.1.1

I am trying to deploy a simple WebService in Netbeans 6.7.1 and Glassfish v2.1.1 and am getting the following error. I am using GlassfishESBv2.2 and windows 7 machine. I have tried googling and implemented things as shown in
http://forums.netbeans.org/topic10055-0-asc-0.html . Still unable to deploy. Though the message says that application server is not started, from the Server tab , I am able to see a message which indicates Glassfish has started.Also , doing a netstat after trying to deploy returns this, which means that Glassfish is running.
C:>netstat -an | findstr "4848"
TCP 0.0.0.0:4848 0.0.0.0:0 LISTENING
I have been trying real hard to get this resolved. Any help is highly appreciated.
Error Message :
The Sun Java System Application Server could not start.
More information about the cause is in the Server log file.
Possible reasons include:
- IDE timeout: refresh the server node to see if it's running now.
- Port conflicts. (use netstat -a to detect possible port numbers already used by the operating system.)
- Incorrect server configuration (domain.xml to be corrected manually)
- Corrupted Deployed Applications preventing the server to start.(This can be seen in the server.log file. In this case, domain.xml needs to be modified).
- Invalid installation location.
C:\Users\xyz\Documents\NetBeansProjects\HWebService\nbproject\build-impl.xml:564: Deployment error:
The Sun Java System Application Server could not start.
More information about the cause is in the Server log file.
Possible reasons include:
- IDE timeout: refresh the server node to see if it's running now.
- Port conflicts. (use netstat -a to detect possible port numbers already used by the operating system.)
- Incorrect server configuration (domain.xml to be corrected manually)
- Corrupted Deployed Applications preventing the server to start.(This can be seen in the server.log file. In this case, domain.xml needs to be modified).
- Invalid installation location.
See the server log for details.
BUILD FAILED (total time: 29 seconds)
I've described the solution please visit here...
http://forums.netbeans.org/post-65058.html

Categories