'javac' cannot be found problem - java

I have a Java application hosted on a remote tomcat instance that executes a bat file which contains the following line
javac filename.java
I receive the following error :-
'javac' is not recognized as an
internal or external command, operable
program or batch file.
I have set the path in the environmental variables. I tried running the same bat file on the machine, it works(which means there is nothing wrong with the path). But running it through the application gives the error. What might be the problem?

Setting the correct path in your environment does not fix the path in the environment of the running tomcat process. If you changed the path in the system settings, a tomcat restart (or system reboot) probably solves your problem.

Once you add %JAVA_HOME%\bin to the PATH var on the remote machine (assuming you have %JAVA_HOME% set there), you will need to run up a new cmd window for the new PATH to be available.

You should set the classpath for the user who is executing tomcat, not only for your login user.

If you have the JRE installed, and not the JDK, you'd be able to run Tomcat but there wouldn't be a javac.exe. Go to JAVA_HOME/bin and see if there's a javac.exe. If not, you have the JRE installed, and you'll have to go get the JDK.
Just curious - why is your Tomcat app calling javac.exe? Are you creating classes on the fly? If yes, why would you not be generating byte code using ASM instead?

Related

How to read Ubuntu environment variables into SpringBoot Program?

Here's what I do in SpringBoot on Windows to read an environment variable (location of log folder).
In Windows Server, I set a System environment variable for "LOG_HOME" with the value with the directory that SpringBoot should use to write logs.
In SpringBoot's application.properties, I have:
logging.file.name= ${LOG_HOME}/ws.log
Works great!
But in Ubuntu Linux 20.04, the same approach doesn't work for me at all.
When the WAR file tries to deploy on Ubuntu 20.04 using this similar technique:
(in .bashrc): export LOG_HOME = /home/ubuntu/logs
reboot (to reload the environment for sure)
I get this error in the Tomcat log when trying to deploy the WAR file:
java.lang.IllegalArgumentException: Could not resolve placeholder 'LOG_HOME' in value "${LOG_HOME}/ws.log"
So, it seems that Spring doesn't see the environment variable set in Ubuntu.
I wrote a simple Java program just to check the value of the environment variables and they were all created as expected including the LOG_HOME as shown in Linux "printenv".
If possible, I need a technique that will work on Ubuntu without changing the working SpringBoot implementation on Windows Server.
Thanks in advance for suggestions.
Instead of exporting in shell session like
export LOG_HOME = /home/ubuntu/logs
try this as -D VM argument in your starup command
eg:
java -cp=xxx mainclass -DLOG_HOME=/home/ubuntu/log
if you are using tomcat then :
VM args can be added catalina.sh file under CATALINA_OPTS.
For tomcat, add your environment variables to $TOMCAT_HOME/bin/setenv.sh where $TOMCAT_HOME is the directory of your tomcat installation.
The solution for me posted by the extremely helpful satyesht above, was to edit the Catalina.sh file and add the "-D" name-value pair option under CATALINA_OPTS. Thanks to all who posted. :)

How to configure Apache Tomcat on a Windows 8.1 installation?

I'm trying to install a 64bit Apache Tomcat distribution on a Windows 8.1 machine but the way in which I have set the environment variables seems to be incorrect.
The steps I have gone through in setting up are as follows:
Copy/Paste apache-tomcat-7.0.57 folder into Program Files (x86)
Set environment variables in the environment variables gui.
Set TOMCAT_HOME to the location of the Tomcat folder: C:\Program Files (x86)\apache-tomcat-7.0.57
Set CATALINA_HOME to the location of the Tomcat folder also: C:\Program Files (x86)\apache-tomcat-7.0.57
But when I execute %TOMCAT_HOME%\bin\startup to check it has been installed correctly I get the following error in my CMD:
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
I found a related question on SO and it gave me the following fix but that http://goo.gl/aNmxGM but that threw another error below:
files was unexpected at this time
I gathered from this that there is a problem in the way I'm setting up the environment variables or possibly the placement of the Tomcat folder. Does anyone have any advice on a fix for this issue?
I think that what you really need is to put it between "" as your path contains space
"%TOMCAT_HOME%\bin\startup"
or
"%TOMCAT_HOME%"\bin\startup
I hope this could help!
Use
"%CATALINA_HOME%"\bin\startup
in the command prompt if you have set the environment variables correctly. I have tried it and it has worked well.

java.exe is not recognized as an internal or external command

I have already read some posts but I cant solve my problem yet.
I am working on a remote desktop and windows server 2008. In the shared disk E: I put some batch file. This batch files call a new batch file from server which runs java script. And now I am taking the this message.
java.exe is not recognized as an internal or external command, operable program or batch file.
I try to set the environment like :
First setup the JRE7 to disk E
Second create new user variable which name is JAVA_HOME and which path is my JRE path E:\Tool\BatFiles
But I am still taking this error. Where should I do wrong ?
Setting JAVA_HOME is a good step, and with it you should be able to run Java as follows
%JAVA_HOME%/java myProgram arg0
If you don't want to include %JAVA_HOME in your command, you will have to include it in your PATH. Windows checks it's PATH for bin scripts every time a command is called. A typical Java installation does this for you.
You can edit your PATH to include ;%JAVA_HOME% at the end. Restart your command prompt for changes to take effect.
Edit 1
Be careful when editting your PATH however! Windows depends on it to function in many aspects. You can expect explorer to stop working. Make sure before altering your PATH variable, that you back it up somewhere. Just in case.

Java settings, classpath and environment variables

I'm not sure if it is best practice but I add MySQL-connector jar to the extensions directory of my Java install directory to I can easily connect to MySQL databases.
I also set environment variables to point to various directories so that I can develop on different machines and only define environment variables locally and code doesn't have to be modified for file paths.
In either case of the above I find that unless I reboot my computer java does not recogise either. What happens during a reboot to Java? Is some config file updates by a java process? Can you update this without having to reboot?
To test this I have created a new environment variable on both Mac (adding to .MacOS/environment.plist), Linux (Ubuntu 12.04) and windows 7 (via control panel). I then used System.getenv("TestVar"); which returns null. Running set from the command line shows it exists though. After a reboot System.getenv("TestVar"); returns the expected value.
Ultimately your goal is to include jar files in CLASSPATH . its up to you how include jars in classpath but this is not good practice to put jars inside extensions directory . While running your program modify CLASSPATH value .
java -cp jar1:jar2:jar3:dir1:. HelloWorld
java -classpathjar1:jar2:jar3:dir1:. HelloWorld
As far as setting environment variables goes the on Ubuntu a log out is required
https://superuser.com/questions/339617/how-to-reload-etc-environment-without-rebooting

How to start jboss 7.1.1 server and deploy project in jboss 7.1.1

I use JBoss 7 server so I downloaded JBoss 7.1.1 version and unzip this zip file.
Then I go to bin folder and double click on standalone.bat but new cmd window open and close within 2 -3 sec.
If I run it using cmd, I get:
E:\jboss-as-7.1.1.Final\bin>standalone.bat
Calling "E:\jboss-as-7.1.1.Final\bin\standalone.conf.bat"
then it stops.
So the JBoss server does not start.
How can I run JBoss server and deploy projects in it on Window 7?
Give JAVA_HOME environment variable in your System Properties Environment Variables likes this;
C:\Program Files\Java\jdk1.7
Give JBOSS_HOME environment variable in your System Properties Environment Variables likes this;
E:\jboss-as-7.1.1.Final
Could you try by putting your Java outside "Program Files". Sometimes commands fail because of the space in the path. Like your JAVA_HOME path is set to "C:\Program Files\Java" and hence it might be failing.
Please try to put Java folder directly under C:\ and set the JAVA_HOME variable (without bin) and also JBOSS_HOME variable in similar way (without bin).
Have you tried right clicking "cmd" and "Run as administrator"? Then cd to the folder and run it there...
or right click the bat file and "Run as administrator"?
I think usually starting server required administrator rights in Windows 7.
It solved. Changing the java_home to c:\java\jdk1.6.0_23 and setting java_home environment variable to that route
You need to add both JBOSS_HOME AND JAVA_HOME as explained above.

Categories

Resources