Cannon Find Symbols Error - java

So I'm trying to run
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_73
javac com/darkblade12/enchantplus/*.java
jar cvf program.jar -C com/darkblade12/enchantplus
in command prompt as I'm not fluent in any language or Eclipse, but I get a cannot find symbols error for many of the items "compiled", I originally just tried to recompile a .jar in Java7 rather than Java8 because I had the source code and needed it in the format for Java7, so any help with either would be great.

Your question is not very clear, but, I guess you only want to compile your classes.
The value of JAVA_HOME variable has blanks in it. You might want to put it in quotes or use the windows shortened path names, like shown here How can I find the short path of a Windows directory/file?.

You are missing a source file, or possibly an external library your program depends on. If you find Configuration.java, you can add it to your enchantplus folder, maker sure to give it the same package name as the one in IndependantConfigurationSection.java and it should compile. If it is a .class file packaged in a .jar file,you need to add that jar to your classpath using
javac -cp {path-to-class-or-jar} com/darkblade12/enchantplus/*.java

Related

Setting Classpath but Java program(using Apache external jar) doesnt run on CMD Line

So I followed a couple of tutorials and I am basically trying to run a java program on cmd line with an External Jar. I know that there are plenty of questions about this, BUT after trying the code suggested I get two errors.\
Its a simple program called "HelloJar.java" and it utilized Apache Commons Lang String Utils.
Error I see (As you can see I set the classpath and run it.):
Works fine in Eclipse though:
Folder Structure (In jars is the jar necessary and in Src is the project I need):
Here is the .jar file that I import for StringUtils:
What does the cannot find symbol mean?
-----------------------After Rajesh's Answer------------------------------------
Problem here is, jar's not set in classpath and results in compilation errors:
As per path shared, command to compile should be :
cd C:\Users\Controlled\Documents\Eclipse_Projects\HelloWorld\src
javac -cp .;C:\Users\Controlled\Documents\Eclipse_Projects\HelloWorld\jars\* HelloJar.java
Command to run java program with above path:
java -cp .;C:\Users\Controlled\Documents\Eclipse_Projects\HelloWorld\jars\* HelloJar
What does the cannot find symbol mean?
That means, compiler is unable to find the specified path in the classpath. So, that means, when you are trying to run your jar from command line, your library which has
org.apache.commons.lang.StringUtils
is not found. So, in order to fix that, please check if the library is included in your jar or if you have that in classpath and specifying the correct classpath.
Although you did set your classpath to the correct folder, windows fle path separation is different from a Unix Box.
javac -cp ".;./jars/org.apache.commons.lang.StringUtils.jar/" HelloJar.java
java -cp ".;./jars/org.apache.commons.lang.StringUtils.jar/" HelloJar
Another Java distinction is that the classpath is the compile-time path. It is not the same as the execution-time path.

Creating a .h file using javah, getting error "Could not find class file for NativeDemo"

I have researched several examples similar to this issue but i have yet to find one that is the solution to my problem. I am simply trying to do my first program using Native methods. I don't have the program stored in a hiearchy of packages because i tried to keep it as simple as possible for my first example. Here is how everything is stored:
I Have one class called NativeDemo. It is stored in C:/JavaFiles/demo/. I compiled the program and the .class file is stored in this same folder. When I try to invoke the javah command on this program it tells me the class file can't be found. Can you please tell me what I am doing wrong?
My javah command is stored in my JDK and is stored as follows: C:/jdk1.0.7_04/bin/
On the command line from the command prompt I type:
C:\JavaFiles\demo>C:\jdk1.7.0_04\bin\javah -jni NativeDemo
also tried C:\JavaFiles\demo>C:\jdk1.7.0_04\bin\javah.exe -jni NativeDemo
When I do this it tells me the class file can't be found. This is the same path used when compiled and it found the file, compiled, and created the .class file with no issues.
Please help. Thanks.
You probably need to supply a -classpath parameter on the command-line to javah to set the classpath. (The -classpath parameter for javah behaves the same as it does for other Java tools; e.g. java, javac, javap and so on. If you don't understand classpaths, read this page and this page.)
As the solution was never added I thought I'd contribute the solution I found to this problem. It wasn't really a solution as such as it was 100% user error!.
In what sounds like a similar situation I wanted to create a quick small project to demonstrate the use of JNI. As this was designed to be a simple exercise I didn't bother with an IDE and simply used vi to write the code and javac to compile it.
e.g
myclass.java (fully qualified class name is mypackage.myclass)
javac myclass.java
The above command outputs myclass.class to the current directory. I now have myclass.java & myclass.class in my current working directory.
Running javah mypackage.myclass results in the error described.
The problem here is my use of javac, I wrote the compiled class to the current directory, javah however is looking for it at "/mypackage/myclass.class".
Silly little problem with a silly little answer but I was quite annoyed at wasting 15 minutes on this today so hopefully I can save someone else the same pain (and yes I know I should have spotted it sooner and may have had I not just had an entertaining few hours finding System.load discrepancies between hotspot and gnuj java implementations, so sadly I wasn't exactly trusting my tools :( !! ).
You have to use fully qualified name for the class.
The syntax for javah is javah [options] classes. classes are specified with their fully qualified names. So, in your case if ur package is demo then, the command would be,
C:\JavaFiles\demo>C:\jdk1.7.0_04\bin\javah -classpath . demo.NativeDemo
Classpath is . because, as you mentioned you have .class file in the current directory. And -jni option is not needed, cuz its default.
in android studio 1.5 I had same problem and run above commands but nothing , I explored the app module build folder and there wasn't classes folder in intermediates folder so before run commands make the project, you can do this by Build>Make Project or shortcut key Ctrl+F9, then run above commands
I solved this problem with the following command used in the directory of the eclipse project:
javah -classpath [PROJECT_DIR\bin\classes] class.name

Multiple jars in classpath not working

I have seen several very similar questions on stackoverflow, but haven't come across anything that exactly matches my problem. I have a folder with several .java files, and another folder with two .jar files. I need to include both the jar files while using javac so that the entire project gets compiled at one go:
$: javac -classpath .:~/myjardir/*.jar ~/myprojectdir/*.java
But if I do this, only the first jar is recognized, and everything that depends on the second jar throws an error. Surprisingly, if I compile each program separately,
$: javac -classpath .:~/myjardir/oneofthejars.jar ~/myprojectdir/file1.java
then everything works fine. I have also compiled the project separately in Eclipse just to test the code and the jars. It is only when I try to use both the jars with -classpath in command line that I get the errors. Wildcard entries are supposed to work in JDK6, so I am at a loss here.
The class path wildcards don't work like they do in the Unix shells. The * means everything named *.jar in the directory. So you don't need to do *.jar but just *. The following should do what you want:
$: javac -classpath .:~/myjardir/* ~/myprojectdir/*.java
See Understanding class path wildcards in the Java SE 6 documentation.
see the SO answer here but here's the relevant paragraph from the Java documentation:
Class path entries can contain the basename wildcard character *, which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For example, the class path entry foo/** specifies all JAR files in the directory named foo. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory.
if you want multiple things in a classpath, you have to separate them by the classpath separator as far as I know. So ./lib:/lib/mylib would be a valid classpath on a unix system, I think the equivalent would be .\lib;\lib\mylib on a windows system. You don't have to specify every file, just the directories.

Where do java packages live on a linux system? Package org.json does not exist Error using javac [duplicate]

This question already has answers here:
What is a classpath and how do I set it?
(10 answers)
Closed last year.
I am trying to compile a library I wrote, using javac and I am getting the error: package org.json does not exist. My program includes org.json.JSONArray and org.json.JSONException.
I have this package installed on my computer because I have successfully compiled android apps that import org.json libraries. I'm pretty sure all I have to do is specify a -classpath but I have been unable to find where these files live on my system (ubuntu 10.10 64-bit sun-java6).
Having been unable to find these on my own system I downloaded the org.json files from here, but I was unable to compile them individually because they were co-dependent on each other.
So I have a couple questions:
Does anyone know where the org.json
package lives from android sdk
install?
Where might I find a tutorial
explaining these basic concepts
regarding compiling, and javac.
Whatever external jars you need to compile with should be on the classpath when you compile. The most non-invasive way to do this is do add these items to the javac command line such as
javac -classpath /path/to/json.jar;. -g YourClass.java
or more likely if you use an IDE, add these jars to your referenced jars of the project in your IDE.
It usually isn't a good idea to pollute the global $CLASSPATH variable, as this then gets pulled in for everything you do with java, which may cause unintended conflicts.
Wherever you like. What you need to do is examine your CLASSPATH variable, and make sure it includes the directory with your library.
Here's the first thing:
$ echo $CLASSPATH
and you'll see your classpath as it is.
Now you need to find the jar file containing the org.json; consult the documentation, but it may be something as simple as json.jar. On most LINUX systems you can then just run
$ locate json.jar
And you'll get a path name for the jarfile. Make sure that path is part of your CLASSPATH and you'll be in fat city.
Oh, and the "Getting started" tutorials at Sun Oracle are the easiest place to start.
Actually, having looked at the files, they may not be packaged as a jar file. In that case, you want to put them into your sources starting at some top directory (src in this example.)
/src
/org/json/ ... put the json files here
... put your files here
and when you compile, they'll all be included, which will resolve all the dependencies.
Again, the place to look for first steps is that tutorial.
use "java" command instead of "javac"

How to set environment variables for javac to be able to find imported packages?

I am not a java developer. I just want to run a java application (which can be downloaded from:
http://code.google.com/p/k-shortest-paths/downloads/list
, under this name: KShortestPaths_Java_v2.1.zip)
While trying to compile test\edu\asu\emit\qyan\test\YenTopKShortestPathsAlgTest.java
I get "package ... does not exist" and "symbol ... does not exist" which I know are related to path setting. Can you please tell me how I should set environment variables and from which directory compile and run that java file?
(My operating system is Windows XP and I have saved the application in C:\KSh)
Edit:
I resolved the problem with compiling. Now, I have a CLASS file: YenTopKShortestPathsAlgTest. However, when I try to run it with java, I get this error: "could not find the main class... program will exist"
which I guess is again related to the paths other jar files are located. Could you please kindly give me a hint?
You need to point the classpath to the name of the .jar files, and/or the name of the directory containing your class files e.g.
CLASSPATH=c:\dir\myjar.jar;c:\classes
so you list the .jars required and the directories involved, separated by semicolons. You can either set the CLASSPATH environment variable, or use the above directly with javac thus:
javac -cp c:\dir\myjar.jar;c:\classes {source files}
The zip file contains a .classpath and a .project file. These files are used by the eclipse java IDE.
Perhaps the most easy way would be to download eclipse and import the project there.
If you want to do it by hand, try
javac -sourcepath src;test test\edu\asu\emit\qyan\test\YenTopKShortestPathsAlgTest.java
from your directory C:\KSh.
EDIT:
Download junit.jar and add it to the classpath with
javac -classpath junit.jar -sourcepath....

Categories

Resources