I'm having some trouble running an example from Bruce Eckel's Thinking in Java 3. Specifically, when I type
ant build
from the code root directory, as instructed on the website, I am able to compile all examples up to chapter 14 (directory c14), which is normal because I haven't installed a couple of libraries required to build the targets of chapter 14. However, when I cd to the directory corresponding to chapter 3 (c03) and invoke javac on the Assignment.java file, I get the following:
jason#debian-laptop:~/code/tij3/code/c03$ javac Assignment.java
Assignment.java:5: package com.bruceeckel.simpletest does not exist
...
where "..." refers to other compile-time errors which I get because of the compiler's inability to find the package com.bruceeckel.simpletest package.
My classpath, as you will note, includes the home code directory of TIJ3:
jason#debian-laptop:~/code/tij3/code/c03$ echo $CLASSPATH
.:..:/home/jason/code/tij3/code/
So I'm guessing that the directory tree nested in that directory should be well seen by the java compiler. After all, ant runs well. For the record, my Java version is 1.6.0_26:
jason#debian-laptop:~/code/tij3/code/c03$ java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) Client VM (build 20.1-b02, mixed mode, sharing)
Any help with this would be immensely appreciated. Thank you,
Related
I am trying to use Princeton Course specific Java Compiler (javac-algs4) on my windows machine and am seeing this error:
$ javac-algs4
warning: [path] bad path element "/usr/local/lift/lib/algs4.jar": no such file or directory
javac: no source files
This is related to Princeton Algorithms 1 Course. I followed the instructions on installing IntelliJ Idea from https://lift.cs.princeton.edu/java/windows/ and other steps to configure CLASSPATH.
javac and java work ok on HelloWorld programs, but I am expecting javac-algs4 to work for programs that use Course specific libraries.
It seems to me like a Unix Path may be hidden in the JAR file that I`m using in the CLASSPATH, and that may be breaking things for me. (Notice the /usr/local... directory in my error)
What steps could I take to troubleshoot and resolve the error?
Other Version Info:
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
Javac Version: javac 10.0.2
I am trying to encrypt a database password for my Java EE Application in the terminal. according to this tutorial
The steps are as follows:
Change directory to your domain’s bin folder (For Eg. cd WLS_home\user_projects\domains\mydomain\bin)
Use setDomainEnv.cmd/sh script to setup the environment
Run java weblogic.security.Encrypt which will prompt for the password and will print the encrypted value in stdout.
However, when I execute 'java weblogic.security.Encrypt', I am presented with the following:
Error: Could not find or load main class weblogic.security.Encrypt
I am developing my project in Eclipse and have configured my Weblogic-12.1.3 server in Eclipse. I am not sure why this error is happening, but I expect its because my java version is 1.8, and maybe it expects me to use java 1.6 which I think comes with Weblogic installation.
java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
You must type
cd WLS_home/user_projects/domains/mydomain/bin/
. ./setDomainEnv.sh
You must use two separate dots, that should do the trick!
I am using Java 8 with WebLogic 12.1.3 on Linux. I had to add some classpath entries, but it worked like this:
java -cp /home/devuser/Oracle/Middleware/Oracle_Home/wlserver/modules/features/*:/home/devuser/Oracle/Middleware/Oracle_Home/wlserver/modules/* weblogic.security.Encrypt
I had the same issue when I set set enableHotswapFlag= to true. please leave this flag empty and try.
I'm trying to build the new Java bindings of Open MPI (v.openmpi-1.9a1r29661) on Macbook Pro running Mavericks (OSX 10.9). I have the JDK 7 installed:
^_^:examples demirelo $ java -version
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
I configured the OMPI with that command:
./configure --enable-mpi-java --with-platform=optimized --with-jdk-dir=/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home --prefix=/Users/demirelo/libs/openmpi
which is followed by the usual suspect:
make all install
When I tried to run the HelloWorld example, I received the following runtime error:
^_^:examples demirelo $ ../bin/mpijavac Hello.java
^_^:examples demirelo $ ../bin/mpirun -np 1 java Hello
JAVA BINDINGS FAILED TO LOAD REQUIRED LIBRARIES
-------------------------------------------------------
Primary job terminated normally, but 1 process returned
a non-zero exit code.. Per user-direction, the job has been aborted.
Moreover, the ~/.bash_profile has the correct path to the /lib folder.
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Users/demirelo/libs/openmpi/lib/
It's quite mysterious which libraries failed. Previously, I was able to build slightly older version (openmpi-1.9a1r28578) on Lion and still use it on Mavericks. This time I needed a freshly compiled OMPI but didn't work out. I'm wondering if anyone else had the same issue with Mavericks and was able to fix it.
This appears to be a bug in Open MPI that is comprised of at least two issues:
OMPI is hard-coded to try to dlopen libmpi.so, which is the wrong name on OS X (it should be libmpi.dylib).
Even after I fix that, I'm running into another Java error that I need to run by the Java programmers.
Apparently, we haven't tested the OMPI Java bindings on OS X in a long time. :-(
Such is the life of running against the SVN trunk. Sorry!
I started off with CentOS and OpenJDK 1.7
# java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
In order to run a specific application, I want to use Oracle's Java 1.6, provided from an RPM.
I copied the Oracle binary to a specific new directory:
# pwd
/oracleJava/jdk-6u45-linux-x64-rpm
I extracted the binary and it gave me the following files:
# ls
jdk-6u45-linux-amd64.rpm
sun-javadb-core-10.6.2-1.1.i386.rpm sun-javadb-javadoc-10.6.2-1.1.i386.rpm
sun-javadb-client-10.6.2-1.1.i386.rpm sun-javadb-demo-10.6.2-1.1.i386.rpm
sun-javadb-common-10.6.2-1.1.i386.rpm sun-javadb-docs-10.6.2-1.1.i386.rpm
I installed the RPM and the rpm utility believes that it installed properly:
rpm -q jdk
jdk-1.6.0_45-fcs.x86_64
# rpm -Uvh ./*.rpm
Preparing... ########################################### [100%]
package jdk-2000:1.6.0_45-fcs.x86_64 is already installed
# rpm -Uvh sun-javadb-*.rpm
[I omit the feedback because it generates a formatting error]
#
However, the Java version just shows 1.7
# java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
In other words, I was expecting the Oracle files to give me some new /java directory somewhere, with a new java executable that would return a different answer for "java -version"
I need that new directory so that I can set JAVA_HOME and use the 1.6 version of Java.
Helpful suggestions would be greatly appreciated. Thanks in advance.
The Oracle JDK RPMs are horrible.
They do not register with the alternatives system.
They do not Provide (in RPM terms) "java"
They have messed up their RPM 'version string' and rely on Epoch (...)
All versions of the JDK (i.e. 1.6 vs 1.7) have the same Epoch
In order to quickly remedy your problem you can run the following:
/usr/sbin/alternatives --install /usr/bin/java java /usr/java/default/bin/java 20000
It will register and prefer the Oracle java installation as an alternative. OpenJDK has weight 16000; here we register with 20000. Once you've run this command you can switch between java versions by using the (already mentioned) alternatives --config java command.
As for a less quick fix you can use my virtual java package. It's quite possibly not perfect (I'm open for improvements ;) ), but it Provides java (making my apache-tomcat package happy) and registers with the alternatives system. This virtual package simply depends on jdk...you can find it here: https://github.com/keystep/virtual-java-rpm
Run the following command to see if your JVM is getting listed.
sudo update-alternatives --config java
If your JVM gets listed select it.
The problem is that Oracle's RPMs are (wilfully IMO!) ignorant of the "alternatives" system.
Instead, they install stuff in a non-standard place (/usr/java) and then expect the user / system administrator to mess with the PATH variable ... by hand.
It is a nuisance!
So what has probably happened in your case is that your JDK / JRE has been installed in a subdirectory of /usr/java ... but since you haven't added the relevant bin subdirectory to the front of your PATH you are still picking up the OpenJDK tools via the java command name.
You can fix this after the fact by using "alternatives" to configure and then select the Oracle commands. But it is messy, especially if you want the JDK tools as well. (There are a lot of them!)
Please check that whether your JAVA_HOME points to JDK 6 using echo $JAVA_HOME. In order change your JAVA_VERSION to Java 6, you need to point to the Java development KIT 6. You also need to add the bin directory to the $PATH variable. Please ensure that JDK6 bin directory comes in the $PATH prior to other JDK bin,if any. You can check the version of your Java in the environment by command java -version.The other answer by learningloop is very perfect to switch between different Java configurations
Try to the following method
delete OpenJDK folder from
/usr/lib/jvm
I had same problem and got solution through this method
How to resolve this? I can compile it but I can't run it. I have different versions of javac and java. I'm trying to run my .java file on terminal. But it works in eclipse. I know that version affects this. How to upgrade javac? Will it affect my eclipse if I do so? Thanks. ;)
[clemjon#localhost ~]$ javac -version
javac 1.6.0_20
[clemjon#localhost ~]$ java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b06)
Java HotSpot(TM) Server VM (build 17.0-b16, mixed mode)
This is not an issue to do with different versions of javac and java. The problem here is that you are attempting to run a class file whose fully-qualified name (com.pl.casestudy.First) doesn't match the class name you passed to java (First). You would get the same error if you had the same versions of javac and java.
If you have a class whose name is com.pl.casestudy.First, Java will look for it in a file with name com/pl/casestudy/First.class (Windows users feel free to reverse the direction of the slashes.) So you will need to run your First class from the directory that contains the com subdirectory. I can see from the shell prompt in your stacktrace that you have a directory named casestudy, I'll assume that the com and pl parent directories also exist. Eclipse has probably created them for you.
Try cding out to the directory that contains com, compiling using
javac com/pl/casestudy/First.java
and running using
java com.pl.casestudy.First
Check which JRE eclipse is using:
Window->Preferences->Java->JREs
Right click the selected one and Edit.
The JRE home path should be there. Add that path to your path environment variable (instead of the one that is already there) and that should do the trick for you.
You can also set which JDK version you want Eclipse to compile to:
Window->Preferences->Java->Compiler
My best advice would be to keep track of all the installed JDK's and JRE's.
Choose the ones you want to use by default and add those to your JAVA_HOME and Path environment variables; Then setup your Eclipse to the same values using the steps above.
Then if for a particular project you need to use a specific JRE, right click on that project and then go to BuildPath->Libraries->JRE
Library->Edit and pick you JRE.
Disclaimer: I'm not on my dev machine right now so the names may be approximate. :)