Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

my java is broken !

53 views
Skip to first unread message

bilsch

unread,
Apr 29, 2012, 8:13:14 AM4/29/12
to
I wrote a loop to read a 26000 character text file NVRAM.TXT into a
character array. It worked fine. The program is listed below. It has
only 24 lines. Today when I run it, it has weird errors referenced to
line numbers 2442, 2685 and 1620. When I click on those error messages
it shows lines in a completely different program - a program that I
never wrote for sure. I saved the file with a different name and it runs
fine with that name - no errors. The file name that has the problem is
Nvj5. That is the file selected and displayed when I click RUN FILE. It
is the file listed below. Even though it is selected and displayed when
I click RUN FILE my system is running some other huge file instead. Has
anyone ever heard of a problem like this?

import java.io.*;

public class Nvj5 {

public static void main(String[] args){

try {
FileInputStream file = new FileInputStream("NVRAM.TXT");
char[] nvchr = new char [30000];
int fin = 1;
int count = 1;
while (fin != -1) {
fin = file.read();
nvchr[count] = (char) fin;
System.out.print(nvchr[count]);
count++;
}
System.out.println("Bytes read : " + count);
file.close();
} catch (IOException e){
System.out.println("Could not read file");
}

}
}
Message has been deleted

bilsch

unread,
Apr 29, 2012, 8:36:32 AM4/29/12
to
On 04/29/2012 05:26 AM, Stefan Ram wrote:
> bilsch<kin...@comcast.net> writes:
>> I click RUN FILE my system is running some other huge file instead.
>
> Possibly, an exception was thrown from the standard library and
> the line number shows where in the standard library it did originate.
>
Do you think it could be due to a virus? I'm running Linux Ubuntu - the
linux heads all say there's no anti-virus programs for linux.

Roedy Green

unread,
Apr 29, 2012, 10:05:21 AM4/29/12
to
On Sun, 29 Apr 2012 05:36:32 -0700, bilsch <kin...@comcast.net>
wrote, quoted or indirectly quoted someone who said :

>Do you think it could be due to a virus? I'm running Linux Ubuntu - the
>linux heads all say there's no anti-virus programs for linux.

Viruses are blamed all the time for errors the user made and bugs in
the OS. When you are programming it is nearly always your own fault.

If you get a stack trace, look for the line in your own program not
ones in the standard library.

If you get a mysterious compiler error see
http://mindprod.com/jgloss/compilererrormessages.html

If you are seeking help, you need to list the program and the compiler
error message and indicate where in the program each error message is
pointing.

Try compiling without an IDE using just JavaC in case the problem is
misunderstanding how to use the IDE.
see http://mindprod.com/jgloss/javacexe.html
--
Roedy Green Canadian Mind Products
http://mindprod.com
Programmers love to create simplified replacements for HTML.
They forget that the simplest language is the one you
already know. They also forget that their simple little
markup language will bit by bit become even more convoluted
and complicated than HTML because of the unplanned way it grows.
.

Joshua Cranmer

unread,
Apr 29, 2012, 10:25:58 AM4/29/12
to
On 4/29/2012 7:13 AM, bilsch wrote:
> I wrote a loop to read a 26000 character text file NVRAM.TXT into a
> character array. It worked fine. The program is listed below. It has
> only 24 lines. Today when I run it, it has weird errors referenced to
> line numbers 2442, 2685 and 1620. When I click on those error messages
> it shows lines in a completely different program - a program that I
> never wrote for sure. I saved the file with a different name and it runs
> fine with that name - no errors. The file name that has the problem is
> Nvj5. That is the file selected and displayed when I click RUN FILE. It
> is the file listed below. Even though it is selected and displayed when
> I click RUN FILE my system is running some other huge file instead. Has
> anyone ever heard of a problem like this?

When you refuse to mention error messages, the answer becomes "I have no
clue."

It would also help to know what the command line is that is causing it.
It could be that your IDE is buggy, too (since it sounds like you rely
on a specific IDE feature).

--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth

bilsch

unread,
Apr 29, 2012, 6:21:47 PM4/29/12
to
I can't tell you the error messages now because I deleted the offending
file - so can't generate errors anymore. It seems the error messages
are irrelevant since they point to lines in some large unknown program.

Arved Sandstrom

unread,
Apr 29, 2012, 7:06:09 PM4/29/12
to
Your system is not "running" some other "file", not in the sense that
you think. Your Java source files are compiled into .class files, these
are loaded up into memory as required, and broadly speaking it's the
bytecodes in these class files that get executed ("run"). The first
application code to execute is the proper main() method in your main
class...like Nvj5.main(). Since you are using standard library code
also, like FileInputStream, code in those classes - and in the classes
that FileInputStream uses, and so on and so on - also gets executed.

That mysterious huge file is a standard library class that your code
needs to work. It's not irrelevant. A high percentage of the time when
you write buggy code the errors start in library code, not in your own
code. You need to look at the entire stack. You will notice that
somewhere in the stack are line references to your own code also.

You deleted and renamed *which* files exactly? Also, you have a class
Nvj5 but a corresponding source file "Nvj5.java". You'll find that
people understand you better if you differentiate between data files
(like NVRAM.TXT) and source files (like Nvj5.java).

Are you saying that you renamed class Nvj5 in source file Nvj5.java to
class Pwll12 in source file Pwll12.java, say, and ever since your
program has run like a charm? That seems highly unlikely. In fact that's
astronomically unlikely.

What IDE or programming text editor are you using? How many "main"
classes are currently available in your workspace? When you tried that
failing run did you see any console output at all?

AHS
--
A fly was very close to being called a "land," cause that's what they do
half the time.
-- Mitch Hedberg

bilsch

unread,
May 3, 2012, 6:03:40 PM5/3/12
to
I copied the source from the offending file then I deleted the entire
project folder - everything. Then I created a new project and a new
blank .java file and pasted the copied source in that new file. I used
new names for the new file and folder. Once I did that the source(in
the new file) ran without a glitch. I tested it several times over a
period of days and it always worked. NOW, TODAY THE NEW FILE HAS GOTTEN
THE SAME PROBLEM JUST LIKE THE OLD FILE I have the error information
pasted below along with the source, also below. The error lines are in a
different file than the one I am running - now named Nvr1.java..

> What IDE or programming text editor are you using? How many "main"
> classes are currently available in your workspace? When you tried that
> failing run did you see any console output at all?
>
I am using NetBeans to do exerything.

> AHS

THE ERROR INFORMATION:
run:
Exception in thread "main" java.lang.VerifyError: Constructor must call
super() or this() before return in method Nvr1.<init>()V at offset 0
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.getMethod0(Class.java:2685)
at java.lang.Class.getMethod(Class.java:1620)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:488)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:480)
Java Result: 1
BUILD SUCCESSFUL (total time: 4 seconds)


THE SOURCE:
import java.io.*;

public class Nvr1 {

public static void main(String[] args){

try {
FileInputStream file = new FileInputStream("NVRAM.TXT");
char[] nvchr = new char [30000];
int fin = 1;
int count = 1;
while (fin != -1) {
fin = file.read();
nvchr[count] = (char) fin;
System.out.print(nvchr[count]);
count++;
}
System.out.println("Bytes read : " + count);
file.close();
} catch (IOException e){
System.out.println("Could not read file");
}

}
}

TIA. Bill S.

Lew

unread,
May 3, 2012, 7:05:47 PM5/3/12
to
bilsch wrote:
> Arved Sandstrom wrote:
>>>> bilsch wrote:
>>>>> I wrote a loop to read a 26000 character text file NVRAM.TXT into a
>>>>> character array. It worked fine. The program is listed below. It has
>>>>> only 24 lines. Today when I run it, it has weird errors referenced to
>>>>> line numbers 2442, 2685 and 1620. When I click on those error messages
>>>>> it shows lines in a completely different program - a program that I
>>>>> never wrote for sure. I saved the file with a different name and it runs
>>>>> fine with that name - no errors. The file name that has the problem is
>>>>> Nvj5. That is the file selected and displayed when I click RUN FILE. It
>>>>> is the file listed below. Even though it is selected and displayed when
>>>>> I click RUN FILE my system is running some other huge file instead. Has
>>>>> anyone ever heard of a problem like this?
. . .
>> Your system is not "running" some other "file", not in the sense that
>> you think. Your Java source files are compiled into .class files, these
>> are loaded up into memory as required, and broadly speaking it's the
>> bytecodes in these class files that get executed ("run"). The first
>> application code to execute is the proper main() method in your main
>> class...like Nvj5.main(). Since you are using standard library code
>> also, like FileInputStream, code in those classes - and in the classes
>> that FileInputStream uses, and so on and so on - also gets executed.
>>
. . .
> I copied the source from the offending file then I deleted the entire
> project folder - everything. Then I created a new project and a new
> blank .java file and pasted the copied source in that new file. I used
> new names for the new file and folder. Once I did that the source(in
> the new file) ran without a glitch. I tested it several times over a
> period of days and it always worked. NOW, TODAY THE NEW FILE HAS GOTTEN
> THE SAME PROBLEM JUST LIKE THE OLD FILE I have the error information

What do you mean by "FILE", exactly?

Files don't execute in Java.

> pasted below along with the source, also below. The error lines are in a
> different file than the one I am running - now named Nvr1.java..

The error message clearly states, "method Nvr1.<init>()V". That is definitely in your class. It is, in fact, the initializer of your class.

How do you conclude otherwise?

> THE ERROR INFORMATION:
> run:
> Exception in thread "main" java.lang.VerifyError: Constructor must call
> super() or this() before return in method Nvr1.<init>()V at offset 0
> at java.lang.Class.getDeclaredMethods0(Native Method)
> at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
> at java.lang.Class.getMethod0(Class.java:2685)
> at java.lang.Class.getMethod(Class.java:1620)
> at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:488)
> at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:480)
> Java Result: 1
> BUILD SUCCESSFUL (total time: 4 seconds)
>
>
> THE SOURCE:
> import java.io.*;
>
> public class Nvr1 {
>
> public static void main(String[] args){
>
> try {
> FileInputStream file = new FileInputStream("NVRAM.TXT");
> char[] nvchr = new char [30000];
> int fin = 1;
> int count = 1;
> while (fin != -1) {
> fin = file.read();
> nvchr[count] = (char) fin;

Why aren't you using the first element of the array?

> System.out.print(nvchr[count]);
> count++;
> }

What happens if 'count' equals '30000'?

> System.out.println("Bytes read : " + count);
> file.close();
> } catch (IOException e){
> System.out.println("Could not read file");
> }
>
> }
> }

The problem, based on what we've seen here, might be in the way the command is invoked. It depends on being run from the correct directory with all the right libraries in its classpath. If those conditions don't hold, you could get weird results.

That said, the error message doesn't jibe well with what we're seeing. You don't call any constructors, so it's odd the error message refers to constructors.

What happens (i.e., copy and paste the output) when you run the program from the command line?

--
Lew

Arved Sandstrom

unread,
May 3, 2012, 7:44:39 PM5/3/12
to
On 12-05-03 08:05 PM, Lew wrote:
[ SNIP ]

> That said, the error message doesn't jibe well with what we're seeing. You don't call any constructors, so it's odd the error message refers to constructors.
[ SNIP ]

It doesn't jibe, no. OTOH, a search on the VerifyError message +
"NetBeans" does turn up indications that NB exhibits this error in
several situations. Often solved, just as with Eclipse in umpteen
circumstances, with the classic "Clean-Rebuild-Try Again-Curse-Repeat"
cycle.

I wouldn't rule out that there is NetBeans badness here. I figure most
of us have encountered situations where you open up an IDE on a project,
where the day before everything was OK, and now suddenly it's seriously
out of whack.

Your suggestion to have the OP try the build and run on the command line
is a great idea. I strongly second that.

bilsch

unread,
May 4, 2012, 1:38:02 AM5/4/12
to
On 05/03/2012 04:44 PM, Arved Sandstrom wrote:
> On 12-05-03 08:05 PM, Lew wrote:
> [ SNIP ]
>
>> That said, the error message doesn't jibe well with what we're seeing. You don't call any constructors, so it's odd the error message refers to constructors.
> [ SNIP ]
>
> It doesn't jibe, no. OTOH, a search on the VerifyError message +
> "NetBeans" does turn up indications that NB exhibits this error in
> several situations. Often solved, just as with Eclipse in umpteen
> circumstances, with the classic "Clean-Rebuild-Try Again-Curse-Repeat"
> cycle.
>
> I wouldn't rule out that there is NetBeans badness here. I figure most
> of us have encountered situations where you open up an IDE on a project,
> where the day before everything was OK, and now suddenly it's seriously
> out of whack.
>
> Your suggestion to have the OP try the build and run on the command line
> is a great idea. I strongly second that.
>
> AHS

Programs java and javac are in directory: /home/bilsch/jdk7/bin/
Offending program, Nvr1.java is in directory:

/home/bilsch/NetBeansProjects/NVRAM/src/

environment variable PATH is:

/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

However note that when I run; java Nvr1.class (or simply Nvr1) from my
home directory the output errors are in javanese, as follows:

bilsch@p4pwj:~/jdk7/bin$ java Nvr1
Exception in thread "main" java.lang.NoClassDefFoundError: Nvr1
Caused by: java.lang.ClassNotFoundException: Nvr1
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: Nvr1. Program will exit.
bilsch@p4pwj:~/jdk7/bin$ cd
bilsch@p4pwj:~$ java Nvr1.class
Exception in thread "main" java.lang.NoClassDefFoundError: Nvr1/class
Caused by: java.lang.ClassNotFoundException: Nvr1.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

Could not find the main class: Nvr1.class. Program will exit.

Therefore the command line is hooked up with the java directory -
regardless of the PATH.

When I change working directory to /home/bilsch/jdk7/bin/ and type in
the path and filename for the offending file I get the following output:

bilsch@p4pwj:~/jdk7/bin$ javac /NetBeansProjects/NVRAM/src/Nvr1

The program 'javac' can be found in the following packages:
* openjdk-6-jdk
* ecj
* gcj-4.4-jdk
* gcj-4.6-jdk
* gcj-4.5-jdk
* openjdk-7-jdk
Try: sudo apt-get install <selected package>
bilsch@p4pwj:~/jdk7/bin$
bilsch@p4pwj:~/jdk7/bin$

Ubuntu can't find javac even though I ran it from the directory where
javac resides. It can't find it from the home directory either.

THE SHORT ANSWER IS I CAN'T COMPILE OR RUN JAVA FROM MY LINUX COMMAND
LINE. I can't answer your question of what the output is when running
command line. Also I have no idea why Linux won't do it. I'LL HAVE TO
WORK ON THAT.

I have to figure how to run from command line in linux. If I could run
using Windows command line and it worked that would be inconclusive ie.
taking Linux out of the equation. If I could run it in Windows command
line tonight and it worked OK that wouldn't mean it would still work 4
days from now?

This could be a Linux glitch rather than Java.

Thanks for listening. Bill S.

Lew

unread,
May 4, 2012, 9:43:39 AM5/4/12
to
Huh?

Besides that I'm not sure what you mean by "the command line is hooked up with the java directory", there is no reason to associate the PATH envar with the error you show, which is simply due to the fact that you did not specify the classpath correctly. Or at all. And tried to run the Java program from a directory such that the default classpath does not include it.


> When I change working directory to /home/bilsch/jdk7/bin/ and type in
> the path and filename for the offending file I get the following output:
>
> bilsch@p4pwj:~/jdk7/bin$ javac /NetBeansProjects/NVRAM/src/Nvr1
>
> The program 'javac' can be found in the following packages:
> * openjdk-6-jdk
> * ecj
> * gcj-4.4-jdk
> * gcj-4.6-jdk
> * gcj-4.5-jdk
> * openjdk-7-jdk
> Try: sudo apt-get install <selected package>
> bilsch@p4pwj:~/jdk7/bin$
> bilsch@p4pwj:~/jdk7/bin$
>
> Ubuntu can't find javac even though I ran it from the directory where
> javac resides. It can't find it from the home directory either.
>
> THE SHORT ANSWER IS I CAN'T COMPILE OR RUN JAVA FROM MY LINUX COMMAND
> LINE. I can't answer your question of what the output is when running

Shh.

> command line. Also I have no idea why Linux won't do it. I'LL HAVE TO
> WORK ON THAT.

Shh.

You showed us the output. Why do you say you can't answer the question that you just answered?

> I have to figure how to run from command line in linux. If I could run

You could try reading the documentation for the "java" command.

Try this:

$ java -cp ${directory_where_the_class_file_is} Nvr1

> using Windows command line and it worked that would be inconclusive ie.
> taking Linux out of the equation. If I could run it in Windows command
> line tonight and it worked OK that wouldn't mean it would still work 4
> days from now?

If you were to specify the command line correctly, it would work right now, in Linux.

> This could be a Linux glitch rather than Java.

No, it's operator error.

Neither Linux nor Java is at fault.

You need to read the documentation for the commands you're using, is all.

Had you done so, you'd've known up front that "java Nvr1.class" is wrong always, and why your attempt to run "java Nvr1" without a matching classpath failed.

Which it would do in the same way in Windows for the same reason.

RTFM.

--
Lew

Andreas Leitgeb

unread,
May 4, 2012, 10:07:13 AM5/4/12
to
bilsch <kin...@comcast.net> wrote:
> environment variable PATH is:
> /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

> bilsch@p4pwj:~/jdk7/bin$ java Nvr1

You don't have "." or ~/jdk7/bin in your PATH. So it probably has
picked up some system-installed java from /usr/bin

Add the bin directory of your jdk7 to the beginning of your PATH,
and some of your obstacles might dissolve.

Anyway, your Nvr1.class file surely isn't in ~/jdk7/bin, so the
> Could not find the main class: Nvr1. Program will exit.
was to be expected.

> bilsch@p4pwj:~/jdk7/bin$ javac /NetBeansProjects/NVRAM/src/Nvr1
> The program 'javac' can be found in the following packages:

That's a shell-convenience, and it seems like you have a jre
installed system-wide, but not a jdk.

To actually use your priovate jdk7 installation, you have to
add it to your PATH (and before /usr/bin)

Your PATH probably should look like:
/home/bilsch/jdk7/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

(I'm speculating about your actual home-directory here)

Leif Roar Moldskred

unread,
May 4, 2012, 10:11:51 AM5/4/12
to
bilsch <kin...@comcast.net> wrote:

>
> Programs java and javac are in directory: /home/bilsch/jdk7/bin/
> Offending program, Nvr1.java is in directory:
>
> /home/bilsch/NetBeansProjects/NVRAM/src/
>
> environment variable PATH is:
>
> /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

And there's your problem -- your PATH does not contain the directory
your java and javac commands are found in, neither as an explicit
entry of /home/bilsch/jdk7/bin/ or implicitly through the current
directory .

> However note that when I run; java Nvr1.class (or simply Nvr1) from my
> home directory the output errors are in javanese, as follows:
>
> bilsch@p4pwj:~/jdk7/bin$ java Nvr1
> Exception in thread "main" java.lang.NoClassDefFoundError: Nvr1
> Caused by: java.lang.ClassNotFoundException: Nvr1

You're running a java command here, but not the one at
/home/bilsch/jdk7/bin/java -- you must have another java command in
your system somewhere. (Try the command "which java" to show where
the java command that's actually being run is.)

The solution is to add the directory /home/bilsch/jdk7/bin/ to the
front of your PATH. Write the following command on the command line:

export PATH=/home/bilsch/jdk7/bin/:$PATH

You should then be able to call javac, use that to create a .class
file and then use java to run the class file.

--
Leif Roar Moldskred

bilsch

unread,
May 4, 2012, 6:06:43 PM5/4/12
to
I added /home/bilsch/jdk7/bin to PATH and was able to both compile and
run program Nvr1 from the command line. Also, when I then go into
NetBeans and run the file it works without errors. HOWEVER, AFTER I RUN
IN NETBEANS MY PATH STATEMENT REVERTS TO THE ORIGINAL VERSION ie. the
/home/bilsch/jdk7/bin part has been removed. I even put the PATH change
in two different places in the PATH variable and both were removed. Does
anybody have a java IDE other than NetBeans ?

Also, a pain in the ass is I must change directory to where the source
file resides to compile. I must change directory to where the .class
file resides in order to run. These directories are different for every
project therefore it's not practical to automate with a script.

Bill S.


Martin Gregorie

unread,
May 4, 2012, 7:06:38 PM5/4/12
to
Look at where PATH is defined in the NetBeans configuration and change
that.

> Also, a pain in the ass is I must change directory to where the source
> file resides to compile. I must change directory to where the .class
> file resides in order to run. These directories are different for every
> project therefore it's not practical to automate with a script.
>
Either use Ant (write a build.xml file if you can't use the one that
NetBeans uses) and/or write a shell script to run the compile from the
correct directory.


--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |

Lew

unread,
May 4, 2012, 8:04:39 PM5/4/12
to
bilsch wrote:
> Also, a pain in the ass is I must change directory to where the source
> file resides to compile. I must change directory to where the .class
> file resides in order to run. These directories are different for every
> project therefore it's not practical to automate with a script.

That is totally untrue.

Both the compiler ("javac") and the runtime ("java") respect classpaths,
and the latter respects source paths. With those, you can compile and run
Java code from any directory regardless of your current directory.

Please, please, please, please, *please* RTFM!

Especially before you start ranting incorrectly about what is not possible.

Why did you ignore the earlier advice to do that?

--
Lew

Leif Roar Moldskred

unread,
May 4, 2012, 8:48:14 PM5/4/12
to
bilsch <kin...@comcast.net> wrote:

> I added /home/bilsch/jdk7/bin to PATH and was able to both compile and
> run program Nvr1 from the command line. Also, when I then go into
> NetBeans and run the file it works without errors. HOWEVER, AFTER I RUN
> IN NETBEANS MY PATH STATEMENT REVERTS TO THE ORIGINAL VERSION ie. the
> /home/bilsch/jdk7/bin part has been removed. I even put the PATH change
> in two different places in the PATH variable and both were removed. Does
> anybody have a java IDE other than NetBeans ?

This isn't a problem with NetBeans, but has to do with how environment
variables work. An "export" statement only sets an environment
variable for the current shell. To have the change stick, you need to
put the addition to PATH in a configuration file (most likely
~/.profile, but some linux distroes can be a little weird about it) so
that it will be set for every shell you open.

> Also, a pain in the ass is I must change directory to where the source
> file resides to compile. I must change directory to where the .class
> file resides in order to run.

You don't have to do either of these. I suggest you follow Lew's
suggestion and read the documentation for the java and javac commands.

> These directories are different for every
> project therefore it's not practical to automate with a script.

You don't want to automate it with a script anyway -- you'll want to
automate it with a java build tool like ant or maven, but I recommend
that you spend some time just compiling and running things from the
command line first, to learn the basics properly.

--
Leif Roar Moldskred

Martin Gregorie

unread,
May 5, 2012, 11:02:36 AM5/5/12
to
On Fri, 04 May 2012 19:48:14 -0500, Leif Roar Moldskred wrote:

> This isn't a problem with NetBeans, but has to do with how environment
> variables work. An "export" statement only sets an environment variable
> for the current shell. To have the change stick, you need to put the
> addition to PATH in a configuration file (most likely ~/.profile, but
> some linux distroes can be a little weird about it) so that it will be
> set for every shell you open.
>
In the Redhat family of distros you can make this sort of change by
putting a script in /etc/profile.d

Scripts in profile.d are run after /etc/profile so I have one called
java.sh which sets all my Java-related environment variables, e.g.
JAVA_HOME, ANT_HOME and uses the pathmunge shell function to add /usr/
java/sdk/bin and /usr/java/ant/bin to $PATH

I make a lot of use symlinks: /usr/java is a symlink to /home/java so my
Java set-up will survive a system reinstall. /home is in a separate
partition that isn't reformatted during an install.

Inside the /home/java directory, jdk is a symlink to the current Java SDK
install and ant is a symlink to the current Ant install. This means that
the contents of /etc/profile.d/java.sh doesn't change when I install a
new version of the JDK: I merely switch the sdk symlink at the same time
as I unpack the download.

>> Also, a pain in the ass is I must change directory to where the source
>> file resides to compile. I must change directory to where the .class
>> file resides in order to run.
>
> You don't have to do either of these. I suggest you follow Lew's
> suggestion and read the documentation for the java and javac commands.
>
Seconded.

>> These directories are different for every
>> project therefore it's not practical to automate with a script.
>
If you take the time to set your system up appropriately everything will
'just work'.

bilsch

unread,
May 5, 2012, 6:03:37 PM5/5/12
to
I can't find any place where path is defined in NetBeans. They told me
two ways to change PATH outside of NetBeans. I did that.
>
>> Also, a pain in the ass is I must change directory to where the source
>> file resides to compile. I must change directory to where the .class
>> file resides in order to run. These directories are different for every
>> project therefore it's not practical to automate with a script.
>>
> Either use Ant (write a build.xml file if you can't use the one that
> NetBeans uses) and/or write a shell script to run the compile from the
> correct directory.

I have an ANT directory and a tab for it in NetBeans but I dont know if
it is installed. Same goes for Maven. I tried starting it on the
command line ant there it says to install it.
>
>

bilsch

unread,
May 5, 2012, 6:04:42 PM5/5/12
to
On 05/04/2012 04:06 PM, Martin Gregorie wrote:
I'm not too handy with shell programming.

bilsch

unread,
May 5, 2012, 6:26:51 PM5/5/12
to
On 05/05/2012 08:02 AM, Martin Gregorie wrote:
> On Fri, 04 May 2012 19:48:14 -0500, Leif Roar Moldskred wrote:
>
>> This isn't a problem with NetBeans, but has to do with how environment
>> variables work. An "export" statement only sets an environment variable
>> for the current shell. To have the change stick, you need to put the
>> addition to PATH in a configuration file (most likely ~/.profile, but
>> some linux distroes can be a little weird about it) so that it will be
>> set for every shell you open.
>>
> In the Redhat family of distros you can make this sort of change by
> putting a script in /etc/profile.d
>
> Scripts in profile.d are run after /etc/profile so I have one called
> java.sh which sets all my Java-related environment variables, e.g.
> JAVA_HOME, ANT_HOME and uses the pathmunge shell function to add /usr/
> java/sdk/bin and /usr/java/ant/bin to $PATH
>
> I make a lot of use symlinks: /usr/java is a symlink to /home/java so my
> Java set-up will survive a system reinstall. /home is in a separate
> partition that isn't reformatted during an install.
>
> Inside the /home/java directory, jdk is a symlink to the current Java SDK
> install and ant is a symlink to the current Ant install. This means that
> the contents of /etc/profile.d/java.sh doesn't change when I install a
> new version of the JDK: I merely switch the sdk symlink at the same time
> as I unpack the download.
>

It is interesting and I grasp the concepts but actually doing those
things myself is beyond me.

>>> Also, a pain in the ass is I must change directory to where the source
>>> file resides to compile. I must change directory to where the .class
>>> file resides in order to run.
>>
>> You don't have to do either of these. I suggest you follow Lew's
>> suggestion and read the documentation for the java and javac commands.
>>
> Seconded.
>
I can't find any documentation for command line java and javac.

bilsch

unread,
May 5, 2012, 6:30:59 PM5/5/12
to
On 05/04/2012 05:04 PM, Lew wrote:
> bilsch wrote:
>> Also, a pain in the ass is I must change directory to where the source
>> file resides to compile. I must change directory to where the .class
>> file resides in order to run. These directories are different for every
>> project therefore it's not practical to automate with a script.
>
> That is totally untrue.
>
> Both the compiler ("javac") and the runtime ("java") respect classpaths,
> and the latter respects source paths. With those, you can compile and run
> Java code from any directory regardless of your current directory.

Would you care to elaborate on this or give me a link where I can read
about it?
>
> Please, please, please, please, *please* RTFM!

I don't have the FM

Martin Gregorie

unread,
May 5, 2012, 6:57:41 PM5/5/12
to
On Sat, 05 May 2012 15:26:51 -0700, bilsch wrote:

> It is interesting and I grasp the concepts but actually doing those
> things myself is beyond me.
>
Learn to use the command line and teach yourself the basics of writing
shell scripts. Without these basic skills you're essentially crippling
yourself.

If you understand any non-UNIX OS, get a copy of "Linux in a Nutshell".
If don't know any OS at a reasonable depth, i.e you're not a power user,
you need a less terse book. I hear that 'Linux for Dummies' is OK but
haven't used it myself because I started using UNIX and UNIX clones in
the late '80s, so the way Linux works was just more of the same when I
started to use it.

>>>> Also, a pain in the ass is I must change directory to where the
>>>> source file resides to compile. I must change directory to where the
>>>> .class file resides in order to run.
>>>
>>> You don't have to do either of these. I suggest you follow Lew's
>>> suggestion and read the documentation for the java and javac commands.
>>>
>> Seconded.
>>
> I can't find any documentation for command line java and javac.
>
"java -?" or "man java" on the command line. Same for javac.
Or download and read the JDK documentation - this is a separate download
from the JDK or JRE packages. If you don't have it installed you should
do so.

markspace

unread,
May 5, 2012, 6:58:58 PM5/5/12
to
On 5/5/2012 3:30 PM, bilsch wrote:

> On 05/04/2012 05:04 PM, Lew wrote:
>> Both the compiler ("javac") and the runtime ("java") respect classpaths,
>>...


> Would you care to elaborate on this or give me a link where I can read
> about it?
...
>
> I don't have the FM


There's an old FAQ floating about the web titled "How to Ask Smart
Questions" or something like that. It also has some standard answers,
like STFW or "search the f'ing web." It's a standard answer because it
works. I typed "javac" into Google and the first thing it should me was
an Oracle page on how to use javac. It was and old 1.4 page, so I
searched for "javac 6" and got the most recent page.

P.S. Found it:

<http://www.catb.org/~esr/faqs/smart-questions.html>


Lew

unread,
May 6, 2012, 1:37:30 AM5/6/12
to
bilsch wrote:
> Lew wrote:
>>
>> Please, please, please, please, *please* RTFM!
>
> I don't have the FM

Really? That's what you're going with? Come on, this is a professional group.
You can do better than that.

Given that it's only a click away, that's on you.

You obviously have Internet access, because you are posting here.

Now go RTFM.

<http://lmgtfy.com/?q=Java+javac+command+reference>

--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

Lew

unread,
May 6, 2012, 1:41:30 AM5/6/12
to
bilsch wrote:
> I can't find any documentation for command line java and javac.

What steps have you taken to find it?

Please specify the queries you used, and to which search engines, and what
other web resources and literature you used.
0 new messages