trying to understand a package does not exist error - java

When I run javac on an ubuntu linux system I get a "package does not exist" error from the line
import org.voltdb.ProcInfo
From the answer below, I know that I need to add packages from "org/voltdb/ProcInfo" to my javac class path to resolve this error.
Java Package Does Not Exist Error
But when I search for the system for such a directory structure I don't find it.
prompt$cd /
prompt$sudo find / -type d -path 'org/voltdb/ProcInfo' //returns no output
I downloaded VoltDB community edition 3.5 and am trying to compile and run a voltdb project. It seems unlike that Volt's .tar does not include the necessary java libraries -- but that seems to be what is going on. Am I understanding what is happening correctly or am I missing something? I have only working knowledge of Java and Linux.

You need to add the VoltDB .jar file to the classpath

Related

Getting a package does not exist error when compiling Google Cloud libraries in terminal with Java

I have a java file under src/ that has the following import because I would like to use Google Cloud's translate API:
import com.google.cloud.translate.*;
I have my main method in Main.java. I have all the necessary .jar files stored in a folder called "Cloud" and in the terminal, I try to compile the code by running:
$ javac -cp "Cloud/*.jar" src/*.java
But I get the following error:
src/Main.java:4: error: package com.google.cloud.translate does not exist
import com.google.cloud.translate.*;
^
I'm not sure why since I imported all the dependencies and set the classpath. It all works when I run the program in the IDE Eclipse, but it doesn't when I try to compile it in the terminal. Any ideas why?
I will post my comment as an answer as it is too long for the comment section.
When checking the official documentation regarding the Translating API, it is stated before trying to use it to follow the Translation Quickstart Using Client Libraries for the set-up process, as it might help.
Additionally, I stumbled across this SO post indicating that the issue could lay on running the javac command outside of the src folder.
I hope this information helps.

Package does not exist when compiling

I´ve made a Java Project on Windows and now I want to use it under Linux.
Since I am working with Files, I "need" the org.apache.commons.io.FilenameUtils package. Under Windows I am working with IntelliJ, so it manages everything for me. I am sharing the Directory of the Project via VirtualBox shared folder. When I try to compile the Main class I get
error: package org.apache.commons.io does not exist
import org.apache.commons.io.FilenameUtils;
^
I already tried javac -classpath . Main.java but I just get the same Error.
To be honest I am completely lost from this Point on, althought I already googled the Problem for a bit. I run Debian and Java JDK 8
You need to have the Commons IO Jar in the classpath when compiling, for example:
javac -cp .:path_to_commons_io_jar Main.java

Javac simple package (JavaBib)

Dear Java Programmers,
JavaBib (http://code.google.com/p/javabib/) is a simple open source java package for which I would like to generate bytecode.
The source can also be obtained by version control via
svn checkout http://javabib.googlecode.com/svn/trunk/ javabib-read-only
Although it consists of only a few java files, I am not able to compile it using
javac *.java
I get
cannot find symbol
error messages for nearly all of the files.
The source files of the dom package all reside in one folder. Therefore, I think it should not be a problem with the classpath. I have tried different values for it nonetheless.
There are additional source files in other directories. I tried copying them all in one directory and run javac in this directory, but javac was complaining about the same imports.
Unfortunately, I have hardly any experience with java and can't fix the problem myself.
Therefore, I would be grateful for hints towards additional diagnostics in order to pin down the problem.
I use Ubuntu 12.04 as operating system and haven't set any classpath or sourcepath variable. At least javac seems to find imports like "java.util.list".
Thanks in advance for your help.

javac: package org.apache.derby.client.am does not exist

I'm trying to compile a java program that is using JavaDB/Derby. On the command line I can run
java org.apache.derby.tools.sysinfo
without errors, but the following line in several of the files causes the error in my question title:
import org.apache.derby.client.am.SqlException;
causes
package org.apache.derby.client.am does not exist
I've done a fresh installation of JavaDB, but I don't think that matters. I've compiled this project once before, and I KNOW I didn't have JavaDB installed. I just had a directory at the top level of the project folder called lib with all of derby's .jar files inside. And I'm pretty sure I didn't have to set any environment variables either.
How can I fix this error? If I need to provide any more information, I will be happy to do so.
I'm using Windows 7 and jdk1.7
Sounds like you have an issue with the JavaDB JARs not being on your classpath. Make sure you specify them using -cp or -classpath on your javac command.

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"

Categories

Resources