I would like to execute a git pre-push hook from the IntelliJ IDEA.
Git pre-push hook can able to execute via a Terminal but not from the IntelliJ IDEA.
I have posted the Version Control console:
And Its saying JAVA_HOME is not set.
Used Versions
Java : 1.8.0_211
IntelliJ IDEA : IntelliJ IDEA 2019.2 EAP (Ultimate Edition), Build #IU-192.4787.16
Ubuntu : 18.04
Git : 2.17.1
Git pre-push hook script
source ~/.bash_profile
remote="$1"
url="$2"
echo “Running Tests”
pwd
./gradlew test
exit $?
I am not getting the where is a problem exactly and How can I solve this issue ?
The issue is that there is no JAVA_HOME variable defined in the environment the hook is run in. The environment is inherited from the parent process, so depending on how and when IntelliJ is started, its environemnt
The easiest way to fix the issue is to define JAVA_HOME in the hook itself (or maybe in .bash_profile), e.g. by adding export JAVA_HOME=<PATH to your Java Home> in it. This way variable will be set during hook execution and gradlew will not fail.
Related
I'm trying to create a maven project with VS Code but when I run the command it says :
'mvn' is not recognized as an internal or external command,operable program or batch file.
but mvn -version is running on command prompt
Environment varaible for User :
MAVEN_JOME : C:\apache-maven-3.6.1,
M2_HOME : C:\apache-maven-3.6.1,
JAVA_HOME : C:\Program Files\Java\jdk1.8.0_212\jre and
System Variables
path is set to C:\apache-maven-3.6.1\bin, C:\Program Files\Java\jdk1.8.0_212\bin for maven and java respectively.
The command I'm running to create the project is:
mvn archetype:generate -DgroupId=com.cs.test-project -DartifactId=test-project -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false The Reference to Command
And the VS Code Reference to Command
The same command is running in Command prompt and it created the project successfully on Desktop.
I fixed this problem by simply restarting VSCode as I had set my PATH variable while my VSCode was running so the changes were not reflected to the VSCode integrated terminal until I restarted it.
It's kindy counterintuitive as path has to be pointed to the actual mvn command, instead to a M2_PATH folder. Also once properly pointed, a new error will be shown if your environment is missing proper jdk within JAVA_HOME. The error is trown by maven. Maven plugin is kinda stupid as it will ignore your default JDK configured within settings.json (java.home or/and java.configuration.runtimes properties) and will happly NOT set java for maven. You have to configure it specificly for maven plugin as this:
"maven.executable.path": "c:\\apache-maven-3.8.1\\bin\\mvn",
"maven.terminal.customEnv": [{
"environmentVariable": "JAVA_HOME",
"value": "c:\\openjdk-1.8.0_232-redhat",
}]
Of course, both paths should be pointed to proper folders/files in your environment.
The way I fixed was by changing the exec path in Vs Code settings from CMD to Powershell.
Open
settings -> features -> terminal
Change the windows exec path from cmd to where you have PowerShell.
For example: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Windows exec setting
On Tuesday Oct. 25, 2022 while trying to solve the same problem, I went through all of these previous solutions for Windows and finally had to resort to the official installation docs:
Installing Apache Maven
Unzipped the download and located the bin directory and manually added that directory location to my: System Properties>Advanced>Environment Variables>'Path'
For good measure, restart the computer.
I am building my java project with bazel. I want to use environmental variable at build/run time. According to the documentation --action_env=APP_ENV=Development should work.
So i do bazel run myproject:app --action_env=APP_ENV=Development
But System.getenv("APP_ENV"); is null
In my intellij IDE I have the following. Neither --action_env=APP_ENV=Development nor --action_env APP_ENV=Development work
Did i get something wrong here?
You can use --run_under to add a prefix to the Bazel run command. This can be used in the IntelliJ Run/Debug configuration to set environment variables.
--run_under='export VAR1=FOO VAR2=BAR && '
Launch Intellij from a terminal so it has the environment variables that it needs during bazel sync (build) and bazel run.
On MacOS, use the open command to launch it.
$ export POSTGRES_USER=dev_user
$ open -a "IntelliJ IDEA CE"
$
Bazel will only pass variables to the build processes if you provide them on the command line:
$ bazel build --action_env=POSTGRES_USER //...
Or specify them in .bazelrc:
build --action_env=POSTGRES_USER
The current version of the Intellij bazel plugin allows you to specify a bazel binary. You can take advantage of this to add specific environment variables per run configuration.
Let's say you want to add the following to the runtime environment:
VAR1=VAL1
VAR2=VAL2
Then create a file called say bazel_custom with the following contents (replace /path/to/bazel with the correct path to bazel):
#!/usr/bin/env bash
export VAR1=VAL1
export VAR2=VAL2
/path/to/bazel "$#"
Save the file and mark it as executable:
chmod +x bazel_custom
Then edit your Intellij bazel run configuration and set the path to the task-specific bazel binary to /path/to/bazel_custom.
I am using Jenkins, and using a Github repo as Source Code.
In the Build section, I am executing this as a Windows Batch command:
set path=%path%;C:\Program Files\Java\jdk1.8.0_144\bin
cd \Users\harr\JenkinsServer\JenkinsTest\src
javac SimpleTest.java //Error is after this executes
java SimpleTest
I know it has something to do with classpath, but I am unsure how to solve this problem in jenkins.
Let me know if more information would be helpful.
Suppose you deploy the jekins server on linux platform, so you have to install the jdk, tomcat and so on, set the env path as well. Then you don't have to execute set path before every build.
you can create a script and copy the command into it, then when jenkins performs the build task, it can execute the script. Refer to the jenkins tutorial to learn about it.
I am trying to install JNetPcap and followed the instructions given at here. At step 12, I am unable to run the ant command and i see the error
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-6-sun/bin/java
As I am able to run Java classes from eclipse or from command line I don't think if it's a problem with JAVA_HOME.
echo $PATH shows
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/jvm/java-6-sun/bin
Kindly let me know if am missing something here.
thanks in advance
Neither running java from the command line or running eclipse will require JAVA_HOME to be set. However, the build procedure you are trying to use ant, and ant often does require JAVA_HOME to be set appropriately. (It actually depends on the version of ant that you are using. The use of JAVA_HOME is typically in the wrapper script for ant.)
Just set it.
JAVA_HOME should probably be set to /usr/lib/jvm/java-6-sun ... based on what you gave said PATH to.
However, it is also possible that the problem is that your PATH is incorrect. Or that you have (somehow) managed to get the owner/group/permissions on your Java install incorrect, such that the java command isn't executable.
Check that running java -version displays the installed Java version.
Repeat with /usr/lib/jvm/java-6-sun/bin/java -version.
Trying to setup jenkins but my builds fails with:
$ ant test
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
Build step 'Invoke Ant' marked build as failure
If I manually run "ant test" on the machine it works just fine and the JAVA_HOME is set to the exact same value. Any idea why it fails when jenkins try to run it ? Are there any more environment variabled involved ( I could not see any though ) ?
For others, I had to add the PATH /usr/bin/ to my PATH variable within Jenkins. (Find your correct path using which java).
Jenkins > Manage Jenkins > Configure System
Add an Environment Variable >>
e.g:
Name: PATH
Value: /usr/local/bin/:/usr/bin/
Screenshot
The problem was this, I had forgot to check the box "Restrict where this project can be run" in the project configuration. Thus the testing tried to execute on "master" where JAVA_HOME was not the same as expected on the build executor I intended to run it on. Thus where I tested and where it actually ran was different machines.
Set JAVA_HOME in your Jenkins system config in Jenkins 2.107.1.
open your jenkins, e.g. http://192.168.1.12:9090, then add /configure to the url,
that is http://192.168.1.12:9090/configure, then you can find like next:
For me the options above did not help, solved by creating a link to what's asked:
sudo ln -s ${actual_java_location} /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
actual_java_location can be read by this:
readlink -f $(which java)