[SOLVED] My new slackware - programming experience
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I started using Slackware in December of 2016, so I still consider myself as a Slack newbie. I came over from Gentoo. I got really really tired of trying to get help and always being told that I am not smart enough to be using Gentoo. It seems that unlike most Gentoo users, I do not know everything. I have been trying for the last two months to turn my back on the Gentoo way of thinking in order to learn the Slack way of thinking. I am wondering how a Slack user would do what I am currently attempting.
About twenty years ago I entered college and acquired an associate's degree in computer science. Shortly after I got my degree, I was declared disabled, so I never actually used my degree for a job of any sort. Mostly, I was a hobbyist programmer. Now, I find myself nearing forty years of age and not knowing how to do much of anything at all beyond dressing myself and basic hygiene.
Today, I am attempting to start learning Java. Slackware does not install Java by default. The tutorial I am using says to run javac/java. I don't have those. I have gcc. I created a directory called "Java" and tried the first program in the tutorial. I understand all the concepts in the program, and am using it as a test to make sure that my tools work correctly. I entered the following program:
Code:
michael@caitlyn java $ cat MyFirstJavaProgram.java
public class MyFirstJavaProgram
{
/*This is my first Java program (not really)
* This will print "Hello World" as the output (Duh!)
*/
public static void main (String [] args)
{
System.out.println("Hello world!");
}
}
I ran gcc.
Code:
michael@caitlyn java $ gcc MyFirstJavaProgram.java
no classpath specified
Then I googled and found that I needed to be running gcj instead.
Code:
michael@caitlyn java $ gcj MyFirstJavaProgram.java
/usr/lib64/gcc/x86_64-slackware-linux/5.4.0/../../../../lib64/crt1.o: In function `_start':
/glibc-tmp-121049354ebdd5d6a32918f2f5c54ab5/glibc-2.24/csu/../sysdeps/x86_64/start.S:110: undefined reference to `main'
collect2: error: ld returned 1 exit status
I am wondering: Should I attempt to install real java? Is there a Slack-ier way I should be looking at this problem?
NOTE: I thought that I remembered this particular error from my early days with Linux (early 2000s) and that it had something to do with naming the directory 'java', so I renamed it to 'java-homework', but the error about main not being defined still remains...
Hi
the information you need can be found here. In short, for licensing reasons Slackware can't distribute Java, but it is easy to install. To develop Java applications you need the JDK (developers' kit), which includes the JRE (runtime).
kjhambrick: I clicked your link, downloaded openjdk-8u121_b13-x86_64-1alien.txz and ran installpkg on it, but when I go back to my terminal tab that I was working through the tutorial in, and issued 'javac', it didn't work.
Code:
michael@caitlyn java-homework $ javac MyFirstJavaProgram.java
bash: javac: command not found
michael@caitlyn java-homework $ which javac
which: no javac in (/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib64/kde4/libexec:/usr/lib64/qt/bin:/usr/share/texmf/bin:/home/michael/.bin)
Distribution: Slackware64 15.0 (started with 13.37). Testing -current in a spare partition.
Posts: 928
Rep:
Quote:
Originally Posted by maschelsea
Code:
michael@caitlyn java-homework $ which javac
which: no javac in (/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib64/kde4/libexec:/usr/lib64/qt/bin:/usr/share/texmf/bin:/home/michael/.bin)
Any idea why?
Just maybe logout and login to put java in the PATH.
When jdk is installed, it adds a new script to /etc/profile.d/ that adds the java locations (in the openjdk you installed, it is called openjdk.sh). You can log out and re-login to have the script run automatically, or you could just run the script manually yourself.
Code:
/etc/profile.d/openjdk.sh
This will be run automatically every time you log in, so the only time you'd need to run it manually is right after your first installation, and only if you don't want to log out and then log back in
michael@caitlyn java-homework $ /etc/profile.d/openjdk.sh
michael@caitlyn java-homework $ javac MyFirstJavaProgram.java
bash: javac: command not found
michael@caitlyn java-homework $
Also, I have OpenJDK 1.8.0 Monitoring and Management Console and OpenJDK-1.8.0 Policy Manager on my Development menu in xfce now, but they don't seem to point to anything that exists (they error when I try to run them)
michael@caitlyn java-homework $ /etc/profile.d/openjdk.sh
michael@caitlyn java-homework $ javac MyFirstJavaProgram.java
bash: javac: command not found
michael@caitlyn java-homework $
Also, I have OpenJDK 1.8.0 Monitoring and Management Console and OpenJDK-1.8.0 Policy Manager on my Development menu in xfce now, but they don't seem to point to anything that exists (they error when I try to run them)
maschelsea --
bash didn't complain when you typed: /etc/profile.d/openjdk.sh
This means the file exists.
However, simply executing that login script doesn't affect your current bash session.
It needs to be 'sourced' into your environment so bash can find the java tools.
As others said, you'll need to log off and log on again, or this:
Code:
source /etc/profile.d/openjdk.sh
-or-
Code:
. /etc/profile.d/openjdk.sh # that is dot-then-space-then /etc/profile.d/openjdk.sh
Try again ?
HTH
p.s. I didn't see gezley's post #2 ( above ) but please check the link in his post -- lots of good info there, including a good explanation as to why javac does not work for you yet.
-- kjh
Last edited by kjhambrick; 01-30-2017 at 02:07 AM.
Reason: add p.s. to gezley's post
However, simply executing that login script doesn't affect your current bash session.
It needs to be 'sourced' into your environment so bash can find the java tools.
As others said, you'll need to log off and log on again, or this:
Code:
source /etc/profile.d/openjdk.sh
-or-
Code:
. /etc/profile.d/openjdk.sh # that is dot-then-space-then /etc/profile.d/openjdk.sh
Crap, good catch. I was thinking it needed to be sourced, but when I looked at it, it looked like it would just set the variables and export them. Guess I have more reading to do with bash on how variables carry over when executed vs sourced.
I thought all the source command did was executed the supplied script. I guess not. Is the '.' as in ". /etc/profile the same as 'source'?
After reading this source vs executing (running openjdk.sh without sourcing it) makes a lot more sense.
In short (probably so simplistic it may not be 100% accurate, but "good enough" ), source applies the commands to your current shell, where executing the script will apply them to a subshell, which is closed when the script closes.
And yes, source openjdk.sh and . openjdk.sh are the same thing.
Installing jdk on slackware/slackware64, via sbopkg
Installing jdk on slackware/slackware64, via sbopkg was fairly simple for me. Just another way to solve it, with jdk. It of course assumes you have sbopkg installed.
1) Acquire jdk source tarball.
a) Proceed to http://www.oracle.com/technetwork/ja...s-2133151.html
using your prefered web-browser.
b) Accept the Oracle Binary Code License Agreement for Java SE.
c) Download either, jdk*i586.tar.gz for slackware or, jdk*x64.tar.gz for slackware64.
2) Move the tarball to the sbopkg source directory.
a) Log in as root.
Code:
$ su -
b) Move tarball (assuming username:foo & web-browsers download directory:~/Downloads).
You may want to install NetBeans while you are at it. Slackbuilds has it.
Depending how much java you intend to do (I've been programming in Java since 2000), I'd recommend NetBeans or IntelliJ. I absolutely detest/hate the IntelliJ user interface. If you intend to do anything in Grails (which I don't recommend), IntelliJ handles grails/groovy code better than NetBeans by far.
If you intend to use Spring Boot (which I do recommend, since companies like that knowledge), then NetBeans is still OK but IntelliJ is better at resolving Spring Beans. (If you don't know what a Spring Bean is, don't worry about it.)
If it isn't Grails, I personally use NetBeans. If it is Grails, NetBeans is effectively useless; use IntelliJ in that case.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.