I'm trying the sourcecode from jLDADMM which is GibbsSamplingLDA.java, but i cannot compile it because i get this following error:
package utility doesn't exist
maybe any of you ever experience the same problem? or maybe anyone know what is package utility and how to use it?
any help will be appreciated.
did you try with eclipse, This might works in eclipse. Wont compile on command line – says imported package does not exist:
Have two classes in two different packages (no inheritance)
class A SpecialDelivery – PKG = com.mgm2.specialdelivery
– Class B (UrgentMessage) has main() imports com.mgm2.specialdelivery.SpecialDelivery
c:\ src\com\mgm2 – has both specialdelivery and urgentmessage package paths -compile SpecialDelivery.java OK
Try to compile UrgentMessage from directory with both specialdelivery and urgentmessa pat h names so they are visible and get package specialdelivery does not exist.
To compile UrgentMessage.java use command
c:\src\com\mgm2 javac urgentmessage/UrgentMessage.java then it doesn’t reconize specialdelviery package even though I am compiling from the directory with both of them there.
Related
My problem is the following:
I am sort of new to programming and I wanted to include the guava.jar file I found on the internet (to use the ImmutableList.copyof()-method). I also have additional packages that I want to include (I wrote a few classes that handles stuff that's relevant for the project).
I implemented the following structure:
Location of the Main-Method that imports the AdditionalClass:
src/com/chess/engine/Main.java
The location of the AdditionalClass-method that imports the guava-jar :
src/com/chess/engine/board/MyAdditionalClass.java
If I compile my project from the "src"-directory via javac -cp com/guava.jar com/chess/engine/Main.java and I get the following error-message:
com/chess/engine/Main.java:3: error: package com.chess.engine.board does not exist
import com.chess.engine.board.*;
^
I think that the problem is that I set the classpath to the guava.jar file and that's why the compiler suddenly doesn't find the AdditionalClass anymore, but I don't know how to change.
If I don't include (...) -cd com/guava.jar (...) and compile by using java com/chess/engine/Main.java the AdditionalClass will be recognized by the compiler but I get a bunch of new errors because the compiler can't find the guava.jar and therefore has no idea what to do with the "ImmutableList.copyOf()" method I implemented.
Trying to compile a multi file package. Needing to compile via: javac mainfile.java while also compiling all the other (about 4 other .java files) at the same time through the one file? I have tried using statements like extend and import package.* Any help would be appreciated.
I have used different compiling methods and arguments but trying to do it just by only inserting javac mainfile.java and java mainfile
Summary: Trying to compile multiple java files at once, through java compiling a single file.
My current code for the main file:
package mypackage;
import mypackage.*;
public class mainfile{
public static void main(String[] args) {
Myfile.main(args) //run main from other file
}
}
Edit: Sorry for the lack of information, when compiling, the compiler returns:
MainFile.java:15: error: cannot find symbol
Myfile.main(args);
^
symbol: variable Myfile
location: class mainfile
1 error
javac as a tool does not do what you want. But, that's why other tools exist.
What you're asking for boils down to 'I want a build system'. The vast majority of java projects use maven or gradle.
It would seem like this works fine:
javac -sourcepath src src/mainfile.java
but you'd be deceived. That will merely compile all source files that are directly referenced by the code in mainfile.java, but there are many other ways to refer to code, such as SPI, reflection, XML config files. The vast majority of java projects will end up using some construct that ends up 'breaking' the -sourcepath "trick" sooner rather than later, which is presumably why all java projects use a build system instead of relying on -sourcepath.
Note that all source files act as if they have:
import java.lang.*;
import yourownpackage.*;
at the top, whether you write this out or not. And, import is java-ese for 'alias'. import foo.bar.Baz; means: Whenever 'Baz' appears in this file as a type, assume I meant to write 'foo.bar.Baz', and that is all: import foo.bar.Baz does not run any code that is in the Baz class whatsoever. If you don't use Baz, then the class file produced doesn't mention Baz at all. This will also not cause javac to then compile your entire directory.
I have a Stack.java file stored in
C:\Users\Aaditya\Documents\Github\Data Structures\com\stack\Stack.java
In the declaration of the file, I have given this
package com.stack;
So, now I have a Parantheses.java file stored in
C:\Users\Aaditya\Documents\Github\Data Structures\Parantheses\Parantheses.java
And now when I have the below code in this file, and subsequently I compile it,
import com.stack.*;
I get the following error
C:\Users\Aaditya\Documents\GitHub\Data Structures\Parantheses>javac *.java
Parantheses.java:1: error: package com.stack does not exist
import com.stack.*;
^
Can anyone sort this error out for me.
PS:
When I put all the java files in one folder and then compile them (without the 'import' and 'package' thing), I dont get any error. Program runs succesfully.
Thanks. :)
Try using -sourcepath while using javac which will allow you to include files from different location.
Links :
http://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html
http://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html#CBHHCGFB
On the other hand better way to manage dependencies is maven.
I have just written a Java multi-threaded program in Eclipse. It compiled fine and works like a charm.
However, as this is coursework we are required to ensure that it compiles in the command line using 'javac' otherwise we score ZERO!
So, some classes compile others don't. The error I'm getting is the following ( they are all similar just with different class names, this is one example)
GateRunnable.java:7: cannot find symbol
symbol : class Station
location: class package.name.here.GateRunnable
public GateRunnable(Station st) {
^
Is this a javac issue? Any help appreciated.
Your compile -classpath and/or -sourcepath is incomplete. The compiler doesn't know where to find class Station. Here is a related question that describes how to set the classpath to include all the classes you want.
To solve the problem I was having, it was simply necessary to compile all classes by using the following command:
javac *.java
which compiles all java files in the directory.
have you compiled every .java file in your folder/packages? if not, then do so. Eclipse usually does that for you, but within the terminal it's you taking the responsibility of compiling every part of the code.
I'm about porting a linux tool to windows. The tool works fine on linux system, but now on windows I get this "cannot find symbol" error.
I have this little main class:
package foo;
import foo.bar;
public class Main {
public static void main(String[] args) throws Exception {
bar.getInstance();
}
}
and the error appears now, while doing javac Main.java:
import foo.bar: cannot find symbol
^
symbol: class bar
location: package foo
Main.java and bar.java are in the same directory.
what am I missing?
For one thing, bar should be called Bar to be idiomatic...
Ideally, you should compile from the directory above Main.java, like this:
javac -d out foo/Main.java foo/Bar.java
That will create a directory called "out" containing another directory "foo", which will contain Main.class and Bar.class. So from the parent directory again, you could run:
java -cp out foo.Main
The source locations don't have to match the package structure. You could just call javac from the directory containing Main.java and Bar.java like this:
javac -cp out Main.java Bar.java
(And then run it in the same way as before) However, it's generally a much better idea to structure your source code according to packages.
You may well find it easier to use an IDE (Eclipse or NetBeans, for example) which will handle all the compilation etc for you. If you do want to build a real project from the command line, you should probably look into using a full build system such as Ant or Maven.
(Note that you'd get the same error on Linux as on Windows, if you tried to compile in the same way.)
If any of you have worked on a kotlin project and then working on a complete Java project without the support of kotlin in gradle, and you put a class in kotlin into the Java project and try to import that Kotlin class, you will get this import issue. Not with reference to the exact question, but someone may find it helpful.
Example : trying to import SomeClass.kt in MainActivity.java will throw this error.
I think you need to compile properly the class bar before attempting to compile foo, this is, generate the class file in the proper package structure.