So there's a folder /usr/share/stuff
in the root directory
in stuff there are a bunch of java files with package org.name
definitions at the top
I am running javac test.java
where test.java
is in a subdomain
I added /usr/share/stuff
to my class path.
and at the top of test.java
I add import org.name
But I get a package does not exist
error...why?
Add a Java transformation in a mapping. Add the jars in the Java Transformation under Java Code > Settings > Add Classpath to use classes from c:\sample\Myjar. jar jar file. Add the import statement that corresponds to the class file in the jar.
somethingElse the compiler assumes you are doing a packageName. classname . In this case you were intending to access out of the System class, but you could very well be trying to access a package called system that is not present (in the classpath for instance). So it is a guess from a compiler.
Navigate to “Java » Build Path » User Libraries” then on the left-hand side click on the “New” button, enter the file name and then click on the OK button. Step 4: After that, you need to click the “Add External JARs” button to add the jar file.
Verify that the scope of the library (in the project structure window) is Compile . If set to a scope of Provided it will cause the behavior you describe. If you have a dependency under a maven profile, make sure you select the correct profile in the maven tree "Profiles", when you compile the project.
Are they in the right subdirectories?
If you put /usr/share/stuff
on the class path, files defined with package org.name
should be in /usr/share/stuff/org/name
.
EDIT: If you don't already know this, you should probably read this doc about understanding classpath.
EDIT 2: Sorry, I hadn't realised you were talking of Java source files in /usr/share/stuff
. Not only they need to be in the appropriate sub-directory, but you need to compile them. The .java
files don't need to be on the classpath, but on the source path. (The generated .class
files need to be on the classpath.)
You might get away with compiling them if they're not under the right directory structure, but they should be, or it will generate warnings at least. The generated class files will be in the right subdirectories (wherever you've specified -d
if you have).
You should use something like javac -sourcepath .:/usr/share/stuff test.java
, assuming you've put the .java
files that were under /usr/share/stuff
under /usr/share/stuff/org/name
(or whatever is appropriate according to their package names).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With