15 Replies - 1125 Views - Last Post: 24 August 2016 - 06:47 AM
#1
Java enviroment variables
Posted 22 August 2016 - 01:02 PM
I can't understand what it's wrong i did all the step from the book.
My link The main source after compile and the eror
My link the package with the class and after compile
It must show on the cm after compile:
"Suntem in ClasaUnu"
"Suntem in ClasaDoi'
enviroment variables that i entroduce are:
user variables for Admin:
classpath:->C:\Program Files\Java\jre\lib\rt.jar;.
path:->C:\Program Files\Java\jdk\bin;.
System variables
CLASSPATH :->C:\Program Files\Java\jdk;C:\Program Files\Java\jre;.
Path :-> C:\WINDOWS;C:\WINDOWS\SYSTEM;C:\Program Files\Java\jdk\bin;C:\Program Files\Java\jre\bin
I search a lto and i didn't find if somebody want you can enter in my PC with team viewer.Please help me somebody with this error.Thanks for everything and sorry for my bad english.
Replies To: Java enviroment variables
#2
Re: Java enviroment variables
Posted 22 August 2016 - 03:18 PM
java AplicatieUnu
#3
Re: Java enviroment variables
Posted 22 August 2016 - 06:14 PM
I don't see what version of Windows you are using.
#4
Re: Java enviroment variables
Posted 22 August 2016 - 07:29 PM
It is better to use the java command's option: -cp
#5
Re: Java enviroment variables
Posted 23 August 2016 - 01:24 AM
Quote
Dead right. I was going to come on to that later. The classpath is redundant in its current form anyway, as well as being wrong
#6
Re: Java enviroment variables
Posted 23 August 2016 - 06:36 AM
Microsoft Windows [Version 6.1.7601]
Copyright © 2009 Microsoft Corporation. All rights reserved.
C:\Users\Admin\Desktop>cd JAVA PROGRAMS
C:\Users\Admin\Desktop\JAVA PROGRAMS>java AplicatieUnu
Aplicatie independenta
C:\Users\Admin\Desktop\JAVA PROGRAMS>javac -cp C:\Temp TestPachet.java
C:\Users\Admin\Desktop\JAVA PROGRAMS>java -cp C:\Temp TestPachet
Error: Could not find or load main class TestPachet
C:\Users\Admin\Desktop\JAVA PROGRAMS>
SO now it run the program but still when i compile test pachet didn't work should i delete all varyables from system?
MY CODE FOR TEST PACHET is
TestPachet.java code:>
import pachet.exemplu.*;
public class TestPachet{
public static void main(String[] args)
{
ClasaUnu cu=new ClasaUnu();
ClasaDoi cad=new ClasaDoi();
}
}
THe package with the two class
ClasaUnu.java location C:\Temp\pachet\exemplu code :>package pachet.exemplu;
public class ClasaUnu{
public ClasaUnu(){
System.out.println("Suntem in ClasaUnu");
}
}
COde for ClasaDoi.java location C:\Temp\pachet\exemplu code >
package pachet.exemplu;
public class ClasaDoi{
public ClasaDoi(){
System.out.println("Suntem in ClasaDoi");
}
}
This post has been edited by no2pencil: 23 August 2016 - 06:39 AM
Reason for edit:: Added Code Tags
#7
Re: Java enviroment variables
Posted 23 August 2016 - 07:06 AM
Try removing all package statements from the source code. Put all the source code in the same folder. Don't use the classpath with the javac and java commands.
The default classpath of the current folder should work.
Make sure the classpath environment variable is not set.
#8
Re: Java enviroment variables
Posted 23 August 2016 - 07:30 AM
So to delete CLASSPATH? And a question in the Path program where i put jdk/bin shall i put also jre?
#9
Re: Java enviroment variables
Posted 23 August 2016 - 07:37 AM
The path to the JDK's bin folder could be on the PATH environment variable so that you would not need to specify the full path to the javac.exe file when compiling. The path to the java.exe file should be set when the JRE is installed.
To compile:
javac TestPachet.java
To execute:
java TestPache
This post has been edited by NormR: 23 August 2016 - 07:38 AM
#10
Re: Java enviroment variables
Posted 23 August 2016 - 07:43 AM
#11
Re: Java enviroment variables
Posted 23 August 2016 - 07:47 AM
For the javac command, the classpath given by -cp is used to find classes that the file you want to compile needs.
For the java command, the classpath given by -cp is used to find all classes, including the one you are using as your entrypoint (the one with main).
So, in your case, you need to add . to the classpath:
java -cp .;C:\Temp TestPachet
This tells the JVM to also look in the current directory for classes, which in this case means your TestPachet one.
It is i ran and it work ...
#12
Re: Java enviroment variables
Posted 23 August 2016 - 08:09 AM
Quote
java -cp .;C:\Temp TestPachet
This tells the JVM to also look in the current directory for classes, which in this case means your TestPachet one.
Actually that class is not in the current directory. It's in a different directory - the one given by the second path on the classpath. So it will work with just that path on the classpath
The default (unless otherwise specified with javac -d ) is to compile into the same directory as the source
This post has been edited by g00se: 23 August 2016 - 08:09 AM
Reason for edit:: Clarification
#13
Re: Java enviroment variables
Posted 23 August 2016 - 08:19 AM
#14
Re: Java enviroment variables
Posted 23 August 2016 - 08:21 AM
#15
Re: Java enviroment variables
Posted 24 August 2016 - 06:18 AM

New Topic/Question
Reply


MultiQuote




|