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.
Related
I configure launch.json to launch Java debugger and working successfully. After a short while, I see error ERROR: transport error 202: recv error: Connection reset by peer. I did google it, and it was suggested to change the debug argument from:
-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:52252
to:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:52252
The debug arguments above are auto generated by vscode. How I can change it? I didn't find a way to configure such argument. The only option is to configure a task to run the command, and configure a debug option to run the task to launch the debugger and attached to that debugger session.
I am checking if there is a way to change the part to server=y as it is much easier.
Stack Overflow seems to have these answers. I never tested them myself though.
How to set java vmargs in vscode at workspace level
vsCode java.test.config vmArgs not working
Thanks to your mention, there is an article with a lot of details to configure a launch request with a preLaunchTask task configuration at https://github.com/microsoft/vscode-java-debug/blob/388c842bcc854a9e2f7f1e8fc5aa9520cb7fecf6/Configuration.md#attach-to-a-debuggee
If it helps, one of the SO questions, and a comment here, has a link to the VSCode configuration reference, https://code.visualstudio.com/docs/java/java-debugging#_attach . There you can see the attach request options.
My understanding of the attach vs launch is that
launch runs your App, and then automatically attaches a debugger to it.
attach is used only in cases where you have an already running JVM, lets say on some remote server, and you want to debug it.
How are you running starting your JVM? My guess would be that if you are starting the JVM from terminal, then put the server=y option there. If you want the VSCode to run the JVM, which I assume is the case, then the launch request is what you want.
i'm very new to this world.. so forgive me for silly explanations.
I've installed maven and all the setting is done. Also i created a maven.sh
Content:
# Apache Maven Environment Variables
# MAVEN_HOME for Maven 1 - M2_HOME for Maven 2
export JAVA_HOME=/usr/lib/jvm/java-11
export M2_HOME=/opt/apache-maven
export MAVEN_HOME=/opt/apache-maven
export PATH=${M2_HOME}/bin:${PATH}
At this point everything is working as expected, but every time i close the terminal it seems to forget some settings..
I have to open the terminal and execute the following commands to make it work again:
~$ cd /etc/profile.d
~$ source maven.sh
I don't know if it is just the way to use maven or i'm missing something, but it's kind of annoying writting the same commands every single time i want to execute maven.. so i would appreciate if you can explain me a way to automate it.
Some extra information:
OS : Ubuntu 20.0.4
JDK : 11
Not first time creating JAVA_HOME variable
After executing those commands above, it shows the correct JAVA_HOME, but it's forgotten after closing the terminal and shows the wrong JAVA_HOME again
Let me tell you guys, this is my first question on stackoverflow, so i will understand if you want to correct me about my manners and my bad english (it's not my mother tongue, i have to get used to it)
Thank you in advance!
I can think of a couple of ways you could resolve this problem given your situation, which is not maven-specific but rather terminal-specific --
Add a reference to your maven.sh script to your profile so that it runs when you start a terminal session. This can typically be accomplished by creating (or adding to) the .bash_profile file in your home directory. You could either add the contents of your maven.sh script to that file, or add source /etc/profile.d/maven.sh to it. From that point forward when you start a terminal session, the script gets run automatically and your variables are set correctly. See https://joshstaiger.org/archives/2005/07/bash_profile_vs.html or the bash man page for some more details about the login shell
If you've already done the first step and it didn't work, consider checking to see if those environment variables are being set in another place (check ~/.bashrc, ~/.bash_profile, and anywhere your particular shell distribution / OS checks for startup scripts
Lastly, I recommend using SDKMan! to manage maven installs without these headaches -- but your mileage may vary. It handles keeping track of the environment variables, java version, &c and allows multiple Java/Maven versions to be installed and managed. https://sdkman.io
Sources:
https://joshstaiger.org/archives/2005/07/bash_profile_vs.html
https://linux.die.net/man/1/bash
https://sdkman.io
You can add these properties to individual user settings file. This file will be available in home directory
vi $HOME/.bash_profile
So everytime, you login to terminal, all these settings will be executed.
I solved the problem by doing a logout and login in Ubuntu
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.
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.
I'm trying to get my Apache Lucene demo to work and I'm down to setting the classpath in this tutorial http://lucene.apache.org/java/2_3_2/demo.html
I've hunted the web and these wer the 2 solutions I found to set CLASSPATH:
CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar
and
setenv CLASSPATH ${CLASSPATH}:/Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar
The second one brings up a error
-bash: setenv: command not found
The first one seemed to accept ok but wen i tried the next step in the tutorial i got an error. The next step was to run the following:
Phil-hunters-MacBook:webapps philhunter$ java org.apache.lucene.demo.IndexFiles /Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/src
which gave me the error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/lucene/demo/IndexFiles
This leads me to believe my CLASSPATHS didnt set correctly. Would I be right in assuming this? I have tried other tutorials and demos and see to get this same error quite a bit. Im new to Lucene and relatively new to mac and Unix shell scripting. Anyone know if I am setting the CLASSPATH correctly and if thats the cause of the errors?
in the terminal type
$ vim ~/.bash_profile
edit the file and add one line:
export CLASSPATH=${CLASSPATH}:/usr/local/lucene-3.6.2/lucene-core-3.6.2.jar:/usr/local/lucene-3.6.2/contrib/demo/lucene-demo-3.6.2.jar;
make sure to change the path of yours.
In your way you lose to add lucene-demo-3.0.3.jar in your classpath.
When you set an environment variable like CLASSPATH then by default it only applies to the current process (i.e. the shell process itself) - it isn't available to the java process you launch in the next line. In order to make it available to other processes you need to "export" the variable. In this case you can use something like:
export CLASSPATH=${CLASSPATH}:/Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar
This basically says "set the CLASSPATH variable to its current value plus the location of the lucene jar, and make the new variable available to any processes launched from this shell".
However, with java the usual way of setting the classpath is to do it as part of the java command itself, using the -classpath or -cp options. In your case it would look something like:
Phil-hunters-MacBook:webapps philhunter$ java -cp /Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/lucene-core-3.0.3.jar org.apache.lucene.demo.IndexFiles /Users/philhunter/Desktop/COM562\ Project/lucene-3.0.3/src
As an aside, the error you see when using the setenv line is because setenv is the command used in the C shell to set environment variables, but the default Mac shell (and the shell you're using) is bash which doesn't recognise setenv and lets you know it doesn't recognise it with the error message: -bash: setenv: command not found.
i create a .bash_profile file in my home directory and do things like
export GRAILS_HOME=/usr/share/grails
...
export PATH=${GRAILS_HOME}/bin:${GROOVY_HOME}/bin:/usr/local/mysql-5.1.45-osx10.6-x86_64/bin:${PATH}
you can work of that to set the classpath -- these examples show how to declare an environment variable and how to use the variable in other variables.