Portable Java Installation - java

I'm trying to make Java work with some commands in a .bat file without installation. I have the Java folder that is installed in C:\Program Files when you normally install Java and Init.bat which does this:
set JAVA_HOME="C:\Users\mega\Desktop\DISK\Apps\Java"
set PATH=%PATH%;C:\Users\mega\Desktop\DISK\Apps\Java\bin
assoc .jar=jarfile
ftype jarfile="C:\Users\mega\Desktop\DISK\Apps\Java\bin\javaw.exe" "%1"
It should set the 2 environment variables and associating the variables, first of all, they don't set the variables, I do not know why but I am sure that I can fix it after this topic, but even then, I set them manually and when I try to open a .jar file it doesn't work.
So the Java is in 1 folder and it should function like if a Java were to be installed normally, but it doesn't, any help is good since I can't figure it out.

Related

What is batch file and what is the real time use of batch file?

I am new to java, Now i am learning. So i googled sample java websites. for example i downloaded source code for online reservation system.
In that code,it have install.bat and start.bat file. May i know what is the use of this file?
Can anyone explain me? Thanks in advance.
You can find out what theese files do by taking a look inside. .bat files are written in plain text. Each line contain one or several commands that can be interpreted and executed by cmd.exe. This kind of files aren't only used for java but for lots of purposes. In your case they are used to launch a java program. In contrast to e.g. C++ Java won't give you an .exe file that you can start by doubleclicking on it. It compiles your code into a .jar file. In order to launch this file you must call the Java virtual machine and tell it to start your jar file (there are some more parameters which you don't have to care about while you are just starting with Java).
However, it will take a while till you'll have to deal with BATCH files. By now you should use your IDE (I would recomend Eclipse) which allows you to start your progrgam without taking care of how to do it. You just hit the "Play"-Button and get your result.
They're nothing to do with Java per se.
They're Windows batch scripts, and from the names, it looks as though one of them is there to install the application on your machine, and one is there to start the application up.
Java is cross-platform, which is a strength for the most part, but it does mean that sometimes applications need a little bit of boilerplate code for starting the application on different platforms. So sometimes you will see Java applications that have a Windows batch file or similar for starting on Windows, and a shell script for starting on Linux, and so on.
Batch files with the extension .bat have nothing to do with Java. They are Windows-specific shell scripts, introduced with MS-DOS in 1981.
A set of multiple commands called as a batch file. Say you are been assigned to compile a set of classes, create jar file and execute. This can be done with a simple batch file like this:
activity1.bat
REM set java home path
set JAVA_HOME=C:\Program Files\java\jdk1.7.0
REM set path
set PATH=C:\Program Files\java\jdk1.7.0\bin
REM set class path
SET CLASSPATH=..
REM compile class files
javac -cp %CLASSPATH% %CUR_DIR%*.java
REM create a jar file
jar cfm new.jar Manifest.txt *.*
REM execute
java -cp %CLASSPATH%;new.jar MainClass.java
PAUSE
Note: REM meant for comments.

Why won't my batch files run since I changed a Windows "Environment Variable"?

I had a couple of batch files to help me with minor tasks (one killed a running Skype process and the other deleted a file before running an executable). Both were only one or two lines of simple code.
To run a program called Kernow I was told I needed to add a Windows environment variable called "Path" and set it to point to a Java folder (C:\Program Files (x86)\Java\jre7\bin) - the program wouldn't run until I had done this giving a Java error.
I already had an environment variable called path which pointed to a long file path so instead of adding a variable I simply updated that one.
Now neither of the batch files that were working fine before will work. Both will run with no errors but not produce results.
I have very little knowledge of how batch files work with Windows. Can I set another environment variable called Path that will enable me to run my batch files and run Kernow??
You probably messed up with adding the folder to your path.
Your path should look like this:
C:\Folder1;C:\Folder2
When you add Java, you need to append it and add a semicolon, like this:
C:\Folder1;C:\Folder2;C:\Program Files (x86)\Java\jre7\bin
You may have missed the semicolon or completely overwritten the path.
An easy command to do this, as mentioned by #unclemeat in the comments:
set path=%path%;C:\Program Files (x86)\Java\jre7\bin

javac not recognized as an internal or external command

What are the path variable supposed to be to ensure "javac" will work? Should it be in both system and user variables and should the "\bin" part be included?
I have a Program Files and Program Files(x86) and the JDK is in both. Which one should i use? Eclipse is working perfectly, it's only when using command line that I get this. Anyone?
Eclipse comes with its own Java compiler, it doesn't have to use an external one.
You should find the bin directory under whichever JDK you want to use and then add it to the path (I prefer the user path but, since I only ever run as one user, I'm not sure what the difference is).
And make sure it's the JDK, not just the JRE.
For example, mine is in c:\program files\java\jdk1.6.0_17\bin (32-bit WinXP).
One final thing, if you're changing the environment variables in the control panel, that won't affect cmd windows that are already open. You'll need to open up a new one to get the new environment settings (trap for wary players).

Starting with Java

So I am trying to start with Java (as in, trying to get the dang thing to accept code). I download all the needed things (the SDK) from Java and such, but when it gets to the point where I have to do "javac" in Command Prompt to compile the notepad file, I just get the message saying that there is no command called "javac".
Anybody wanna share some insight?
To set the environment variable PATH: http://www.java.com/en/download/help/path.xml.
Also I recommend using an IDE such as netbeans or eclipse. They make it much easier when starting off in java, plus when getting into advanced projects with many classes, they help greatly.
You need to set the path to your java compiler for it to be found when you use the command prompt. This page explains how.
I would suggest setting the following environment variable:,
JAVA_HOME to point to the root of your java installation e.g. C:\Program Files\Java
than append the following to your PATH environment variable:
;%JAVA_HOME%\bin
than you will be able to use java and javac from the command line.
Also see this article from Microsoft on setting environment variables if your not familiar with it.
You need to add the Java bin directory (where javac.exe is located, assuming you're on Windows), to your system PATH.
Right click on "My Computer", go to Environment Variables, and add the bin directory where Java is installed to your PATH variable.
You will need to have the java bin directory on your path. So, on windows, if installed at c:\java, and bin is c:\java\bin (normally you have version number, jre vs sdk, etc), you will need to add that to your PATH environment variable. set PATH=c:\java\bin;%PATH% -- you could do this in a setlocal/endlocal block or set it permanatly for your machine.
Also, the JRE may not have javac -- you may need to dowload the SDK.
Starting with java by typing 'javac' at the command line satisfy my mother's definition of the phrase 'starting with' ... as in,
"Don't start with me, buddy."
You are likely to end up with a punch in the nose.
For your own sanity, pick one of Eclipse, or NetBeans, or IntelliJ, or the other popular IDEs, and start from there.

no output when .jar is executed

I built an application in Netbeans 6.8 and made project.jar file. When I run it, it works only on my computer, but not on any other computer. However, when I made any simple application, that doesnt use any libraries, it works fine on any computer.
Is there any way, how to invoke some error message, where is the problem?
My project use R 2.9.2, so I install this version on other computer and set the System Path variable exactly same. Other libraries listed in lib directory are: AbsoluteLayout.jar,DatePicker-V0.99-2006.09.01.jar,jcommon-1.0.16.jar,jfreechart-1.0.13.jar,jmathplot.jar,JRI.jar,pdf-renderer-1.0.5.jar
Thank you
You don't get any message at all? What do "works" and "not works" look like?
You sound like another person who hasn't taken the time to learn how to do things by hand on the command line without an IDE. I'd recommend doing that. Open a command shell and type in the java -jar -cp ... foo.jar command to run your stuff. The messages you get back will be educational.
Note the -cp command line argument. That's how you add your JARs to the CLASSPATH properly.
I solved this problem as follows, maybe it will help someone.I add 2 paths in PATH system variable:
Start -> Control Panel -> System -> Advanced
Click on Environment Variables, under System Variables, find PATH, and click on it.
In the Edit windows, modify PATH by adding the location of the class to the value for PATH.
you must add both paths, to jri.dll and r.dll, in my case it were these:
C:/Program Files/R/R-2.9.2/bin/;C:/Program Files/R/R-2.9.2/library/rJava/jri/;
I have added these lines already, but with different different slash. So be careful, you must use it / not \ to define path!!!

Categories