Java enviroment variables

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1125 Views - Last Post: 24 August 2016 - 06:47 AM Rate Topic: -----

#1 George123a   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-August 16

Java enviroment variables

Posted 22 August 2016 - 01:02 PM

Hi.Before i 'm sorry if i will make mistake i dont speak very good english.One week ago i bought a book.Java from 0 to expert.First time i stay a lot for enviroment variables.After i did i tried some simple code and it's work.Now i tried to make a package with 2 class.When i compile with javac it's work but after i got one error.And i saw after the other programs that was good in one time now doesnt want to work anymore.

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.

Is This A Good Question/Topic? 0
  • +

Replies To: Java enviroment variables

#2 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: Java enviroment variables

Posted 22 August 2016 - 03:18 PM

For one thing, you're attempting to run in the wrong way. Should be

java AplicatieUnu

Was This Post Helpful? 0
  • +
  • -

#3 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: Java enviroment variables

Posted 22 August 2016 - 06:14 PM

** renamed title to be more descriptive of issue than 'help with this' **

I don't see what version of Windows you are using.
Was This Post Helpful? 0
  • +
  • -

#4 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 870
  • View blog
  • Posts: 6,695
  • Joined: 25-December 13

Re: Java enviroment variables

Posted 22 August 2016 - 07:29 PM

A lot of people don't think the classpath environment variable should be set. Especially into the JDK or JRE folders.
It is better to use the java command's option: -cp
Was This Post Helpful? 0
  • +
  • -

#5 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: Java enviroment variables

Posted 23 August 2016 - 01:24 AM

Quote

A lot of people don't think the classpath environment variable should be set. Especially into the JDK or JRE folders.

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
Was This Post Helpful? 0
  • +
  • -

#6 George123a   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-August 16

Re: Java enviroment variables

Posted 23 August 2016 - 06:36 AM

Hi sorry because i was late.
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

Was This Post Helpful? 0
  • +
  • -

#7 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 870
  • View blog
  • Posts: 6,695
  • Joined: 25-December 13

Re: Java enviroment variables

Posted 23 August 2016 - 07:06 AM

Using packages and classpath can be confusing for beginners.
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.
Was This Post Helpful? 0
  • +
  • -

#8 George123a   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-August 16

Re: Java enviroment variables

Posted 23 August 2016 - 07:30 AM

Hi somebody help me i must put java -cp .;C:\Temp TestPachet
So to delete CLASSPATH? And a question in the Path program where i put jdk/bin shall i put also jre?
Was This Post Helpful? 0
  • +
  • -

#9 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 870
  • View blog
  • Posts: 6,695
  • Joined: 25-December 13

Re: Java enviroment variables

Posted 23 August 2016 - 07:37 AM

Yes, delete the classpath environment variable.
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

Was This Post Helpful? 0
  • +
  • -

#10 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: Java enviroment variables

Posted 23 August 2016 - 07:43 AM

View PostGeorge123a, on 23 August 2016 - 10:30 AM, said:

Hi somebody help me i must put java -cp .;C:\Temp TestPachet

What is -cp .;? That doesn't look like valid syntax.
Was This Post Helpful? 0
  • +
  • -

#11 George123a   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-August 16

Re: Java enviroment variables

Posted 23 August 2016 - 07:47 AM

That guy said OK, this comes down to classpaths.

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 ...
Was This Post Helpful? 0
  • +
  • -

#12 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: Java enviroment variables

Posted 23 August 2016 - 08:09 AM

Quote

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.


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

Was This Post Helpful? 0
  • +
  • -

#13 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: Java enviroment variables

Posted 23 August 2016 - 08:19 AM

Why load the ClassPath environment variable, if you are going to dynamically pass it in the command each time you compile?
Was This Post Helpful? 0
  • +
  • -

#14 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3744
  • View blog
  • Posts: 17,121
  • Joined: 20-September 08

Re: Java enviroment variables

Posted 23 August 2016 - 08:21 AM

My advice too: don't used a fixed classpath
Was This Post Helpful? 0
  • +
  • -

#15 George123a   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 22-August 16

Re: Java enviroment variables

Posted 24 August 2016 - 06:18 AM

I delete Classpath i put only path with the destination form bin jdk and jre is good?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2