I built an application in Netbeans 6.8 and made project.jar file. When I run it, it works only on my computer, but not on any other computer. However, when I made any simple application, that doesnt use any libraries, it works fine on any computer.
Is there any way, how to invoke some error message, where is the problem?
My project use R 2.9.2, so I install this version on other computer and set the System Path variable exactly same. Other libraries listed in lib directory are: AbsoluteLayout.jar,DatePicker-V0.99-2006.09.01.jar,jcommon-1.0.16.jar,jfreechart-1.0.13.jar,jmathplot.jar,JRI.jar,pdf-renderer-1.0.5.jar
Thank you
You don't get any message at all? What do "works" and "not works" look like?
You sound like another person who hasn't taken the time to learn how to do things by hand on the command line without an IDE. I'd recommend doing that. Open a command shell and type in the java -jar -cp ... foo.jar command to run your stuff. The messages you get back will be educational.
Note the -cp command line argument. That's how you add your JARs to the CLASSPATH properly.
I solved this problem as follows, maybe it will help someone.I add 2 paths in PATH system variable:
Start -> Control Panel -> System -> Advanced
Click on Environment Variables, under System Variables, find PATH, and click on it.
In the Edit windows, modify PATH by adding the location of the class to the value for PATH.
you must add both paths, to jri.dll and r.dll, in my case it were these:
C:/Program Files/R/R-2.9.2/bin/;C:/Program Files/R/R-2.9.2/library/rJava/jri/;
I have added these lines already, but with different different slash. So be careful, you must use it / not \ to define path!!!
Related
This question already has answers here:
Import javax.vecmath
(6 answers)
Closed 1 year ago.
Preamble: So this all started with just trying to use javax.vecmath.Vector2d. I didn't have javax.vecmath so I spent a bit of time trying to get it, found that I needed to download Java3D.
After a long time of trying to download Java3D for Java (version 16.0.2), I eventually got it together with the vecmath.jar file landing in /Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home/lib/ext. This got rid of the error: package javax.vecmath does not exist error message.
Then, I got the message
<JAVA_HOME>/lib/ext exists, extensions mechanism no longer supported; Use -classpath instead.
.Error: Could not create the Java Virtual Machine.
this also wasn't letting me use any java commands in shell.
A bit of research and I concluded the solution to be moving (via Finder select and drag) j3dutils.jar, vecmath.jar, and j3dcore.jar over to lib and just deleting the lib/ext directory. I have gotten rid of the <JAVA_HOME>/lib/ext exists problem but back to error: package javax.vecmath does not exist.
I don't even know what to do know. I just want to use javax.vecmath. Am I going about this the totally wrong way? How can I get this to work?
Okay, I figured it out.
How to use javax.vecmath in Mac OS(11.5.1) with Java(16.0.2)
I am giving a description that sort of includes why I do things, skip to the TLDR at the bottom if you just want an answer.
Step 1: Download the latest version of Java3D
This contains vecmath, along with j3dcore and j3dutils. It will download a .zip file. Unzip the file and it will expand into a new directory with another .zip file inside, j3d-jre.zip. Unzip j3d-jre.zip and it will expand into a directory lib. Inside lib will be a subdirectory, ext, with three .jar files inside: j3dcore.jar, j3dutils.jar, and vecmath.jar. You can put these literally anywhere, just make sure you keep track of their location (I put them in ~/Library/Java/Extensions, this location is on the hard drive and will need an admin password to do anything–use
sudo unzip /path/to/j3d-jre.zip
if you are doing things in shell). You CAN put the ext directory in JAVA_HOME/lib/ but after Java 6, this will cause a problem.
Step 2: Change CLASSPATH
Java has no idea how to find vecmath.jar so you have to specify it.
Option 1: Specify CLASSPATH with every shell command
The simplest version is using
javac -cp ".:/path/to/vecmath.jar:" MyMainProgram.java
to compile and
java -cp ".:/path/to/vecmath.jar:" MyMainProgram
to run the program (you can also replace -cp with -classpath and it will do the same thing)
This option won't ever destroy your CLASSPATH but you also have to include the -cp command every time you compile and run a program that imports javax.vecmath.
Option 2: Specify CLASSPATH with every new terminal window
A little more lasting than -cp, you can define CLASSPATH such that any changes will only take place in that terminal window. Use this form:
export CLASSPATH=".:/path/to/vecmath.jar:"
Now when you call
javac MyMainProgram.java
java MyMainProgram
Java will see that CLASSPATH is .:/path/to/vecmath.jar and everything will compile and run without adding the -cp command.
The main downside of this option is that if you update CLASSPATH again, you have to remember to add the previous CLASSPATH (which you can see at any time with echo $CLASSPATH)
Option 3: Permanently add CLASSPATH to terminal
Enter the following into terminal:
open ~/.bash_profile
this will open a window that may or may not have code in it. Regardless of any pre-existing code, scroll to the bottom and add
export CLASSPATH=".:/path/to/vecmath.jar:"
This option holds the CLASSPATH in all terminal windows forever or until you change it (using any method above).
TLDR
Download Java3D for macOS
Unzip java3d-1_5_1-macosx.zip and open the directory it creates
Unzip j3d-jre.zip and open the new directory /lib/ and the subdirectory /lib/ext/
Move vecmath.jar, j3dcore.jar, and j3dmath.jar to ~/Library/Java/Extensions (this requires an admin password) or any other location
Run the following line in terminal:
open ~/.bash_profile
Go to the bottom and add the following:
export CLASSPATH="/path/to/vecmath.jar:$CLASSPATH"
import javax.vecmath.* to any .java program you want
The jar file can go where you want, moving it to your project's lib folder is good. The real issue is you need your classpath to point to it.
Here is a full explanation.
If you are running from the command line you don't need to set the classpath variable, you can provide it in the java command. It would be something like this:
java -cp lib/vecmath.jar Example
This assumes that the program you are working on has been compiled into a class file named Example.class. If you main method is in a package you will need to fully qualify the classname so it might look like:
java -cp lib/vecmath.jar com.demo.Example
You can list multiple jar files on the classpath, separated by a colon (:).
You can also ask for help in the command line by invoking:
java -h
javac not working in windows command prompt
^I tried the suggestions on this post, and it was SLIGHTLY helpful, but not completely.
I opened up my command prompt and I typed in "javac" after putting in the path in my Environment Variables and it didn't work, at which point I googled it and found that thread.
I knew that I had closed and re-opened my cmd already, and that didn't work, so I skipped that bit and I saw the part telling me to make sure that javac.exe exists, which I verified with the "dir" command in the cmd. Afterwords, while in the "C:\Program Files\Java\jdk1.7.0_25\bin" folder on the command prompt, I typed in the next bit of advice, which was
for %i in (javac.exe) do #echo %~$PATH:i
After entering this into my command prompt, I got the message "ECHO is on". Upon seeing this, I typed in "javac" again and this time, it worked. So I decided to test this out by backing out of the directory and going to a folder in which I had a .java file saved and running it, but it again told me that
'javac' is not recognized as an internal or external command, operable program or batch file.
This was disappointing. I think it'll only work if I'm INSIDE the bin file on the command prompt, which is annoying because I'm not an administrator on this computer and it will be annoying to always have to get admin permission (from my parents) to code. They will also never give me the password. Can anyone help me? Thanks in advance! And sorry for the huge wall of text...
EDIT: Someone has asked what would the output of "echo %path%" be. It is this:
C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\
^Is it not supposed to say this?
EDIT 2: #brano88...I think I did? I right clicked computer, went to properties, went to advanced system settings, clicked Environment Variables and went to the top part and pressed "New..." There, I entered the Variable Name as Path and the Variable Value as the location of the bin folder. Is this incorrect? I followed a YouTube tutorial step by step while doing this.
This one: http://www.youtube.com/watch?v=Hl-zzrqQoSE
How to run .java files from CMD
go to your Computer -> C: -> Program Files -> Java -> jdk1.7.0_25-bin
copy the path (example: C:\Program Files (x86)\Java\jdk1.7.0_25\bin)
Go to Control Panel -> System and Security -> System-Advance System
Settings -> Advanced -> Environment Variables
open the Environment Variables screen and go to System Variables and look for "Path"
after finding the Path system variable, double click it or press edit button and in the Variable value you paste the path from java you just copied after the last values already existing there.
Note!
make sure you DO NOT enter any extra space in this field as it won't work;
make sure you have one semi-colon before pasting the path, example: Path :
...%ANT_HOME%\bin;C:\Program Files (x86)\Java\jdk1.7.0_25\bin
Note! If you previously tried to compile the .java file in a CMD, close that CMD
and open it again as the changes made will take effect only using a new instance of CMD
Go to the location of the file.java , example:E:\Projects , right-click by holding the Shift button pressed inside your folder and in the options from the window that just appeared select: Open command window here
Another solution is to normally open a CMD and change the directory using :
cd command until you reach your folder
After the CMD window opened, type: javac HelloWorld.java
Note! Make sure the class name written in your file.java is the same as the file name. Example your file name should be: HelloWorld.java and your class inside that file must also be:
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
Otherwise, it will not compile!
It is successful if no error message is displayed, if the path of the folder appears again in CMD and of course if the HelloWorld.class file appears now in the directory. To check that type the command dir which will show what contains your currect directory.
To finally run the file type in the CMD: java HelloWorld
Observe that no extension is needed when running the file(the file you run already has the .class extension)
This is how it worked for me! If something is not right, please inform me! Thanks!
For a beginner programmer that doesn't have admin rights on his/her computer, I'd recommend the Eclipse IDE.
Since you already have the JDK the only installation step needed requires no admin rights. From here you must download the "Eclipse Standard" option, and you will get a very large zip archive. You can extract it onto the desktop or my documents. Windows comes with a utility to do this via drag-and-drop right from the explorer or your machine may have another program such as WinRAR installed to do this.
You can then run eclipse.exe from the place where you extracted it by browsing to, and double-clicking this file.
The IDE is very powerful and self-explanatory. You can create projects, run, and debug code, and it's nice for beginners. It's truly worth the long wait in downloading it.
First, yes you did add JDK to PATH. But you didn't do that correctly. You already have these variables added to PATH: C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\
To add JDK put semicolon before you add it because you have multiple path's assigned to PATH variable. So it should be something like this:
C:\Windows\system32;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.7.0_25\bin
in my case, javac was not working just because while specifying the path to javac in the path variable I gave space after putting semicolon to the end of the previous entry
To use javac from command prompt without typing the full location each time you will need to add it to the path.
I am unsure if you can change it without admin privileges, But on windows 7 with admin you can go to start -> Right click My Computer -> Properties -> Advanced system settings -> Advanced -> Enviromental Variables
You can then find the system variable path and append to the end of it, the location of javac.
The exact location of javac will vary depending on what version of the JDK you have installed, During installation you will have been given the option to choose where it was installed.
EDIT: Also make sure you haven't opened cmd as administrator. Or perform the steps in that video on the administrator account.
Adding variables to the top part of the environmental variables menu, mean they only affect the current user. You should be able to do these on normal account if you have someone type in the administrator password.
Most of the time when i am learning something i am running java program from commandline.
now my problem is little complecated.
i am running Simple java program from command line. But i need CLASSPATH variable in environment variables. when i am adding CLASSPATH variable my program is giving me error.
The error is classNOtFoundException. Means when i am running program it will check .class file and it is going in my classpath variable and that is obvious it will not found and it will fire exception.
i am always working line this. this problem occurs after i have formatted my PC. but i am using same OS and same jdk as it was.
Any body have faced this type of issue?
it is not working with following Screen shot.
Working with following screen shot
Following is my desktop screen shot and all things are working with classpath and without classpath(Means i can run simple Program no matter if classpath is there or not.).
Try this,
1. Goto your JDK folder, and then go inside bin,
2. Copy the path
eg: C:\Program Files\Java\jdk1.7.0\bin
3. Paste this path in "PATH", NOT "CLASSPATH" .
4. Then i recommend giving the command "gpupdate /force" in cmd.
(I know it about updating policies, but that how it works for me....)
5. Then type the command "java -version" on cmd, if you get the jdk version in respose, you are good to go.
Try adding "." (current directory) to your system class path.
A better practice would be to create a batch file to set per-application environment variables and launch your program.
Please include the full text of the class not found exception and the system class path you have defined.
According to you your JDK is working properly (because u getting classNOtFoundException)
so defiantly the class which you want to run is not in class path
Lets try this..
java -cp /your/path ClassName
Other wise Lets take a look of this may its helps you.. PATH and CLASSPATH
I unsuccessfully attempted to install Groovy 1.8.6 (zip distribution) on a Win XP (sp3) machine yesterday and today (the error messages stated it was unable to find the groovyStarter then I received a lengthy stack trace...). Needless to say, it was a frustrating experience. So, I decided to use the Windows installer for version 1.8.5. Groovysh functions as it should but if I write a small Groovy script and place it in a file:
println "Hello Groovy Programmer!"
...no output is displayed. Using groovy -e "println 'Hello!'" has the exact same behavior.
Any ideas of what might cause this?
Thanks.
~Caitlin
I'm not sure what you mean by "installing" the binary ZIP distribution. You don't really install anything in the usual sense of the term... you just unzip the ZIP file wherever you like. On my Windows XP laptop, I unzipped its contents into C:\groovy-1.8.6\.
I have heard some people complain of problems when they unzip into a path that contains spaces (such as C:\Documents and Settings\YourUsername\Desktop)... so perhaps that could be your issue, if you unzipped to your Desktop or something.
Just unzip the ZIP file somewhere, and add it's /bin directory to your PATH. On a Windows XP machine:
Right-click "My Computer"
Select "Properties"
Go to the "Advanced" tab
Click the "Environment Variables" button
Edit the PATH variable, and add C:\groovy-1.8.6\bin (or whatever)
The Groovy installation instructions also suggest that you add a GROOVY_HOME variable (pointing to C:\groovy-1.8.6), and a JAVA_HOME variable pointing to the root directory of your Java JDK (not the JRE located inside of the JDK). However, to be honest, I only remember to add these two environment variables half the time when putting Groovy on a a new machine, and it's never caused me problems.
With the ZIP file unzipped, and its /bin directory in your PATH, you just open a command-prompt and type:
groovy <script name>
... or, to run the GUI interface:
groovyConsole
If by chance you saw those "groovyStarter" errors because you tried to run startGroovy, then use one of the two commands above instead. The "startGroovy.bat" command is an internal script intended for indirect use through the other scripts under /bin. It will throw a java.lang.ClassNotFoundException: org.codehaus.groovy.tools.GroovyStarter stacktrace if you call it directly... because it needs one of the other scripts to set some variable prior to calling it.
Good luck!
So I am trying to start with Java (as in, trying to get the dang thing to accept code). I download all the needed things (the SDK) from Java and such, but when it gets to the point where I have to do "javac" in Command Prompt to compile the notepad file, I just get the message saying that there is no command called "javac".
Anybody wanna share some insight?
To set the environment variable PATH: http://www.java.com/en/download/help/path.xml.
Also I recommend using an IDE such as netbeans or eclipse. They make it much easier when starting off in java, plus when getting into advanced projects with many classes, they help greatly.
You need to set the path to your java compiler for it to be found when you use the command prompt. This page explains how.
I would suggest setting the following environment variable:,
JAVA_HOME to point to the root of your java installation e.g. C:\Program Files\Java
than append the following to your PATH environment variable:
;%JAVA_HOME%\bin
than you will be able to use java and javac from the command line.
Also see this article from Microsoft on setting environment variables if your not familiar with it.
You need to add the Java bin directory (where javac.exe is located, assuming you're on Windows), to your system PATH.
Right click on "My Computer", go to Environment Variables, and add the bin directory where Java is installed to your PATH variable.
You will need to have the java bin directory on your path. So, on windows, if installed at c:\java, and bin is c:\java\bin (normally you have version number, jre vs sdk, etc), you will need to add that to your PATH environment variable. set PATH=c:\java\bin;%PATH% -- you could do this in a setlocal/endlocal block or set it permanatly for your machine.
Also, the JRE may not have javac -- you may need to dowload the SDK.
Starting with java by typing 'javac' at the command line satisfy my mother's definition of the phrase 'starting with' ... as in,
"Don't start with me, buddy."
You are likely to end up with a punch in the nose.
For your own sanity, pick one of Eclipse, or NetBeans, or IntelliJ, or the other popular IDEs, and start from there.