Wildfly 10 Can I set -Dspring.profiles.active in standalone.conf.bat? - java

Edit: I've tried adding set "JAVA_OPTS=%JAVA_OPTS% -Dspring.profiles.active=test" inside standalone.conf.bat and this hasn't worked. It's as if it's being ignored.
Is it possible to set -Dspring.profiles.active=testlike one might if calling
java -Dspring.profiles.active=test -jar build/libs/weather-0.0.1-SNAPSHOT.jar
as a line in standalone.conf.bat? If not, what is the reason?
I've tried this (as well as in domain.conf.bat and appclient.conf.bat) and it seems to be completely ignored (I killed the java process and restarted the wildfly service to have the war redeployed). This is running on Windows 10.
Edit: it works perfectly fine when doing it from IntelliJ and running it in debug. I just want to be able to reproduce this on wildfly.

I discovered the problem and it relates to specific changes to other .bat files made by other people who worked on this project within the "standalone" directory. There was some strange interference with how %JAVA_OPTS% was being set (and overwritten). Even though server.log logged (multiple times that -Dspring.profiles.active=test was set, it wasn't "sticking".
I resolved this by doing a dive into all the places the VM args were messed with in the .bats in standalone, using recursive file search in Notepad++. The takeaway for anyone else is that, if running on windows, you should be able to set -Dspring.profiles.active=test (or whatever your arg is) in standalone.conf (and nowhere else), and that should be sufficient to carry-over into the wildfly java.exe process.

Related

Ansible issue when trying to execute java command from playbook

I'm in the middle of automating some processes in a VM, we are currently using java 17 and have updated out jettys to jetty-11. Since in jetty-11 both home and base are separate it's important to initialize the jetty-base folder. I need to do it from ansible
I worked out a solution in local shell but trying that in ansible it's not working
- name: "Run initialization command"
shell: "nohup java -jar '{{ jetty_home }}'/start.jar jetty.base='{{ jetty_install_dir }}' --add-module=server,http,deploy,annotations,logging-jetty,jsp &"
There are no obvious errors when I run the playbook, just
TASK [jetty-distribution : initialize jetty-base] **************************************************************************************************************************
changed: [****************************] (cutting the vm name off)
Is there any solutions to this issue ? Thanks in advance
You most definately should be using 2 separate directories.
(repeated here for others that see this question in the future)
The jetty.home directory.
This is for the jetty distribution (or the more modern jetty-home tarball/zip).
The jetty.home directory is sacred, don't edit/change/remove/add/modify ANYTHING in this directory. You don't need to, for any possible configuration you can come up with (trust me).
The jetty.base directory.
This is the directory for your configuration, or instance of Jetty.
Make sure this directory does not nest inside/outside of the jetty.home directory, you'll just make your life needless complicated when it's time to upgrade (or even downgrade) your Jetty version.
Next, when it comes to initialization, turn off nuhup, that just hides any errors you might have during initialization. The --add-module command is terminal anyway and will do what it needs and then exit, it's not a daemon and keeps running. If you don't want to see the output, at least redirect it to an output file you can interrogate if there's issues.
Don't put it in the background either (the & at the end), the exit code will be useful to you if an error occurs.
aka
java -jar /path/to/jetty-home/start.jar \
jetty.home=/path/to/jetty-home \
jetty.base=/path/to/my-jetty-base \
--add-module=http,deploy,annotations,logging-jetty,jsp \
2>&1 > /path/to/my-jetty-base/jetty-init.log
Keep in mind that some modules, when added, require user interaction (to accept licenses). This can be handled in scripts by using the --approve-all-licenses option on start.jar.
Lastly, are you sure ansible supports the "Jakarta Big Bang" namespace changes that Jetty 11 implements?
See past answer on this: https://stackoverflow.com/a/66368511/775715
If ansible has updated to Jakarta EE 9, then go ahead and use Jetty 11, if they haven't, then stick with Jetty 10 (which is on Jakarta EE 8) until such time that ansible catches up with the rest of the world.

glassfish in IntelliJ is started with wrong encoding

I have set up my glassfish project according to this guide: https://www.jetbrains.com/help/idea/creating-and-running-your-first-restful-web-service.html
The run configurations are created automatically and as far as I can see they use glassfish's startup-script.
However, upon startup I can see that these commands are executed:
C:\path\glassfish5\glassfish\bin\asadmin.bat start-domain domain1
"C:\path\Java\jdk1.8.0_171\bin\java.exe" -Dfile.encoding=windows-1252 -classpath "..."
Somewhere, somehow, a Dfile.encoding parameter got added. I tried setting this exact parameter to "UFT-8" instead in the launch configurations VM-Options, but the resulting commands still look exactly like above, no mention of my UTF-8.
I tried searching where this parameter is set or how to change it or anything regarding this, but I found absolutely nothing.
Does anyone know how I can make IntelliJ/glassfish startup with UTF-8 encoding instead? As mentioned above, setting VM options in the run-configuration had no effect.

Installing Elasticsearch 5.0.2 on Windows 8 - \config\jvm.options "was unexpected at this time"

I'm new to Stack Overflow (though a long time lurker).
I'm struggling to install elasticsearch on my laptop. It's windows 8, I've just updated java to Java 8 and I've set the new path using set JAVA_HOME.
However, whenever I try to run the elasticsearch.bat file on the command line, I get this error:
\elasticsearch-5.0.2\bin\..\config\jvm.options was unexpected at this time
Any help would be greatly appreciated on this matter
I've also tried to setup the ElasticSearch on my Windows 2016 R2 Datacenter (64-bit). Let me share some of my experiences on how to solve this.
Setting up JAVA_HOME
Ensure that you have JDK/JRE installed. You can download it here.
Set the JAVA_HOME environment variable. To do this, open the Start menu and type in "path".
Then click on Environment Variables. If you don't have JAVA_HOME variable set yet, click New.
The JAVA_HOME variable should only lead up to the JDK/JRE directory, not including /bin.
C:\Progra~1\Java\jdk1.8.0_112
Progra~1 corresponds to Program Files. If you use Program Files (x86), change Progra~1 to Progra~2
Restart your computer. Once your computer is restarted, open up CMD and type in echo %JAVA_HOME%. The output should be
C:\Progra~1\Java\jdk1.8.0_112
If you get the following output, your JAVA_HOME is setup correctly.
Running ElasticSearch
The first time I tried to run ElasticSearch, I get the following output.
The odd directory I pointed out here gave me a hint that the batch file might be reading from the wrong directory. So what I did was tinker around with the batch file a bit. Open elasticsearch.bat using any text editor.
Scroll all the way to the end, somewhere above the last lines you'll see something similar to the following.
Remove the highlighted line, save the file and try running the batch file again via command prompt.
It works in my case.
Once you have this, open up your browser and navigate to localhost:9200.
I think that's it?
Your problem is most likely caused by parentheses in the path to where you unzipped and are running Elasticsearch from. The related issue in the Elasticsearch repository is #24712 which will be fixed with Elasticsearch 5.4.1.
Be aware that by applying Nicholas Lie's "fix" you are telling Elasticsearch to effectively ignore all settings in config/jvm.options. While this may help you to start Elasticsearch in this specific case, it will only start with default JVM options which might lead to surprising behavior down the road.

Why won't the VisualVM Profiler profile my application?

I've created a simple 1 file java application that iterates through a loop, calls some functions, allocates some memory, adds some numbers, etc. I run that application via eclipse's Run As->Java Application.
The running application shows up in Java VisualVM under Local.
I double click on that application and go to the Profiler tab.
The default settings are:
Start profiling from classes: my.main.package.**
Do not profile classes: java.*, javax.*,
sun.*, sunw.*, com.sun.*
I click on CPU. The CPU and Memory buttons gray out. Nothing happens.
The Status says profiling inactive.
When my application terminates the Status says application terminated.
What am I doing wrong here? Are there some settings I need to tweak? Do I need to set a VM flag when I launch my application?
I had the same issue after java 1.7.0_45 update. I had to delete the following folder:
C:\users\'username'\AppData\Local\Temp\hsperfdata_'username'
After doing so, everything works like a charm.
I'd guess the issue relates to the application being started from within Eclipse, this is because JVisualVM expects to find data in the java.io.tmpdir directory (usually C:\Users\[your username]\AppData\Local\Temp\hsperfdata_[your username] on a Windows system).
I assume rather than in the normal location where JPS, JVisualVM etc. expects it, Eclipse puts the data in it's own temp folder?
If so, try invoking JVisualVM using jvisualvm -J-Djava.io.tmpdir=[Eclipse's temp directory] to explicitly tell it where that data is.
If you can't find the hsperfdata_$USER folder, try just running your application outside Eclipse in the usual command line Java way.
Also note that there was a bug affecting the temp folder (case sensitivity) introduced around 1.6.0_23, so maybe you'd benefit by updating to a more recent Java 6 (or 7) build?
Mikaveli, Kuba and Somaiah Kumbera have provided great solutions. Just adding what I have done to make things work.
I first checked the location C:\users\'username'\AppData\Local\Temp\hsperfdata_'username' There was no file named with the process ID of my program running inside eclipse.
I simply stopped the program and added the following parameter to the Run Configurations of the program (Run Configurations -> Arguments -> VM Arguments)
-Djava.io.tmpdir=C:\users\'username'\AppData\Local\Temp\hsperfdata_'username'
I started the program again. Still could not profile it. But now I have a file created for the process at the given temp directory.
Then, a simple restart of VisualVM did the trick.
I had the same issue, but with the following symptoms:
I started jetty, with the work directory in
C:\Users\t852124\AppData\Local\Temp
Jetty was creating the hsperfdata_ directory but not setting a processID in it
So when I started visualVM, it could not get any java process info.
I solved this by starting jetty with the -Djava.io.tmpdir=C:/temp/java option.
Now when I started jetty, the process ID was created as a file in the hsperfdata_ directory.
So when I started visualVM, it was able to see my local java process
I had the same problem and running VisualVM with elevated privileges (admin rights) solved the issue.
On Linux with VisualVM 1.3.3 I have to remove local settings of application in ~/.visualvm/1.3.3/ to enable CPU Profiler and CPU Sampler.
Also note that /usr/bin/jvisualvm contains hardcoded path to OpenJDK (set with jdkhome variable), which seems to cause a lot of issues, comparing to running to Oracle JDK 1.7.
Also note that if your application is using a recent non-Oracle JVM, you may need to download the "bleeding edge" VisualVM from github.
For example, the VisualVM bundled with JDK 1.8.0.111 doesn't seem to work with the IBM 1.8 JVM. Possibly the IBM JVM was simply released after the Oracle 1.8 JVM, so including the necessary changes wasn't possible at that time.

How do I increase memory on Tomcat 7 when running as a Windows Service?

I am trying to run Tomcat 7 as a Windows Service (XP and Windows 7).
I see places to set the -Xmx and -Xms jvm args in catalina.bat, but I'm not sure how to do it when using $CATALINA_HOME/bin/service.bat install service-name. I looked around but the best I could find was that I needed to update windows registry key, though I'm not sure which one to edit.
I'm hoping there's an easier way, is there?
Update: I'm not using the windows installer mainly because I'm running multiple instances of tomcat on the same machine but with different ports (for reasons I'd rather not go into here). If I can use the installer with multiple instances using different ports, then I'd like to know how, but regardless, is it possible to do increase the memory on a tomcat windows service without the UI tools that come with the installer?
Assuming that you've downloaded and installed Tomcat as Windows Service Installer exe file from the Tomcat homepage, then check the Apache feather icon in the systray (or when absent, run Monitor Tomcat from the start menu). Doubleclick the feather icon and go to the Java tab. There you can configure the memory.
Restart the service to let the changes take effect.
The answer to my own question is, I think, to use tomcat7.exe:
cd $CATALINA_HOME
.\bin\service.bat install tomcat
.\bin\tomcat7.exe //US//tomcat7 --JvmMs=512 --JvmMx=1024 --JvmSs=1024
Also, you can launch the UI tool mentioned by BalusC without the system tray or using the installer with tomcat7w.exe
.\bin\tomcat7w.exe //ES//tomcat
An additional note to this:
Setting the --JvmXX parameters (through the UI tool or the command line) may not be enough. You may also need to specify the JVM memory values explicitly. From the command line it may look like this:
bin\tomcat7w.exe //US//tomcat7 --JavaOptions=-Xmx=1024;-Xms=512;..
Be careful not to override the other JavaOption values. You can try updating bin\service.bat or use the UI tool and append the java options (separate each value with a new line).
//ES/tomcat -> This may not work if you have changed the service name during the installation.
Either run the command without any service name
.\bin\tomcat7w.exe //ES
or with exact service name
.\bin\tomcat7w.exe //ES/YourServiceName
According to catalina.sh customizations should always go into your own setenv.sh (or setenv.bat respectively) eg:
CATALINA_OPTS='-Xms512m -Xmx1024m'
My guess is that setenv.bat will also be called when starting a service.I might be wrong, though, since I'm not a windows user.
If you are running a custom named service, you should see two executables in your Tomcat/bin directory
In my case with Tomcat 8
08/14/2019 10:24 PM 116,648 Tomcat-Custom.exe
08/14/2019 10:24 PM 119,720 Tomcat-Customw.exe
2 File(s) 236,368 bytes
Running the "w" terminated executable will let you configure Xmx in the Java tab
For Tomcat 7 to increase memory :
Identify your service name, you will find it in the service properties, under the "Path to executable" at the end of the line
For me it is //RS//Tomcat70 so the name is Tomcat70
Then write as administrator :
tomcat7.exe //US//Tomcat70 --JvmOptions=-Xmx1024M

Categories

Resources