Compiling the Examples - System Variables wrong set?

User 67a2de9478

21-02-2007 11:55:27

Hi!





When I'm trying to compile the code examples e.g. in MarvinBeans, I always get the failure message :





SimpleConverter.java:11: package chemaxon.formats does not exist


import chemaxon.formats.*;


^


SimpleConverter.java:12: package chemaxon.struc does not exist


import chemaxon.struc.*;


^


SimpleConverter.java:27: cannot find symbol


symbol : class MolImporter


location: class SimpleConverter


MolImporter importer = new MolImporter(args[0]);


^


SimpleConverter.java:27: cannot find symbol


symbol : class MolImporter


location: class SimpleConverter


MolImporter importer = new MolImporter(args[0]);


^


SimpleConverter.java:28: cannot find symbol


symbol : class Molecule


location: class SimpleConverter


Molecule mol = importer.read();


^


5 errors





Like in the installation guide, I set the system variable JCHEMHOME but, nevertheless, the Java-Compiler seems not to find the right packages. Did I miss to set an environment variable and if to "where" ?





Sorry, I'm Java newby and don't know what variables to set for the compiler to use.





Sebastian

User 67a2de9478

21-02-2007 13:20:56

Allright, found!





Sorry for the disturbance!





S.

ChemAxon 9c0afc9aaf

21-02-2007 13:24:41

Hi,





As I was just finishing my answer, I post it regardless, as it may still contain some useful information for either you or others.





JCHEMHOME is not an input of the Java compiler (it is used by jchem batch files).





The Java compiler (javac) and the Java Virtual Machine (java) finds all classes by the system CLASSPATH environment variable.


This can be overridden via the "-classpath" command-line option.





Understanding the classpath and package concept may be a bit confusing first, but you will see it's very logical.





Please let me recommend a nice Java book (I've also learned Java from this) that is free to download (the printed version can also be purchased):





Title: Thinking In Java





Web site: http://bruceeckel.com/





Back to the original topic:





You should include either jchem.jar OR MarvinBeans.jar into the compilation classpath.


You should not include both, as jchem.jar also contains the classes in MarvinBeans.jar, and this could lead to versions problems.





If you are compiling in command line with javac, probably the easiest is to place one of the jar files into the system CLASSPATH environment variable.





Best regards,





Szilard

User 67a2de9478

21-02-2007 13:47:21

Hi,





if I set a CLASSPATH-variable to the jchem.jar, I can compile, but when running the programm I get the error message:





Exception in thread "main" java.lang.NoClassDefFoundError: SimpleConverter





But if I use no CLASSPATH-variable but take the JChem\lib Folder to the PATH-variable, it works well. Is it possible, that if a CLASSPATH-variable is defined it and solely it is used by Java and a search for classes is only run in the folder defined in the CLASSPATH and everything else is ignored?





Best regards,


Sebastian

ChemAxon 9c0afc9aaf

21-02-2007 14:08:54

Quote:
if I set a CLASSPATH-variable to the jchem.jar, I can compile, but when running the programm I get the error message:





Exception in thread "main" java.lang.NoClassDefFoundError: SimpleConverter
Java always only sees the classes that are present in the CLASSPATH, nothing else.


Obviously it should also see the newly compiled example (SimpleConverter.class).





The usual practice is to also put the current directory (".") into the CLASSPATH, so you can always use the actual directory as a root of the package hierarchy.


Quote:
But if I use no CLASSPATH-variable
According to the documentation of Sun:





If neither CLASSPATH or -classpath is specified, the user class path consists of the current directory






( http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/javac.html#options )





In short: a missing CLASSPATH is equivalent to "." .
Quote:



but take the JChem\lib Folder to the PATH-variable
This makes no sense. Again: PATH has nothing to do with CLASSPATH.








Please also read the relevant part in the book I recommended, probably the explanation there is more detailed and better understandable than mine.





Best regards,





Szilard

User 67a2de9478

21-02-2007 14:25:26

Hi,


allright, I missed the "." in the CLASSPATH for the current folder. No wonder that the class file wasn't found.


Thank you very much!


Sebastian