Have to create a package defined by me, containing some of the classes, and I recall that package in a file .java created of the program AntlrWorks in which i did the import. Package named "com.project.redfox" . I compiled the code with the command: "javac Test.java provaParser.java provaLexer.java" but I get the error that not exist the package.
In the grammar have added :
grammar prova;
#hader{
import com.project.redfox;
}
....something......
I created the package "com.project.redfox" within of the project redfox developed in NetBeans, therefore the directory com/project/redfox is in the directory redfox.
how can I solve this problem?
To formally answer your question: javac can't find the package com.wikirates which you are probably using in com.project.redfox.
Note that I assumed redfox is a class. If it's a package, you need to import all classes from it like this: import com.project.redfox.*; instead of import com.project.redfox; (assuming that there are classes in com.project.redfox...).
Related
I'm having a bit of trouble with compiling a Java RMI assignment in packages with the command line interface on Windows 10 (can't use Eclipse or any other IDE). I need to compile and run two .java files - RemoteBankServer.java, and RemoteBankClient.java. Both of these files use other .java classes (Bank.java, RemoteBankImpl.java, RemoteBank.java, Account.java and subclasses of Account.java).
Previously, with all of my files in one folder, I could easily compile and run my server and client with two command line windows, with:
javac RemoteBankServer.java
java RemoteBankServer
and the same for RemoteBankClient.
Now that I've tested that my code works fine, I need to organize them into java packages, following this structure:
- package name: edu.btp400.w2017.client
class name: RemoteBankClient
- package name: edu.bt400.w2017.server
class names: RemoteBankImpl, RemoteBankServer
- package name: edu.btp400.w2017.common
class name: RemoteBank (and all other classes, like Bank, Account, etc.)
I've created those folders (edu/btp400/w2017/) and have placed the appropriate classes in each folder, but I can't get it to compile. For now, I have these two lines at the top of each .java file:
package edu.btp400.w2017.server; //or .common or .client
import edu.btp400.w2017.*;
But I'm still getting compilation errors when trying to compile RemoteBankServer.java (in the server folder), such as this (which is weird, because RemoteBankImpl is in the same folder and RemoteBankServer:
RemoteBankServer.java:40: error: cannot find symbol
RemoteBankImpl b1 = new RemoteBankImpl();
^
symbol: class RemoteBankImpl
location: class RemoteBankServer
as well as similar errors saying that Account and other classes cannot be found. I've looked at various posts on how to compile with Java packages using the command line interface, but I haven't gotten it working. Any help would be greatly appreciated. Sorry for the long post.
Edit: this is the command I used to compile above (after storing the files in various packages):
I tried this in the folder containing edu, and got 27 compilation errors:
javac -cp . edu/btp400/w2017/server/RemoteBankServer.java
and this inside the server folder, and got 15 compilation errors:
javac RemoteBankServer.java
Edit: Thanks to user EJP, I found out that I needed to include the subfolders in my import statements: instead of just import edu.btp400.w2017.*; I needed to do:
import edu.btp400.w2017.common.*;
import edu.btp400.w2017.server.*;
import edu.btp400.w2017.client.*;
import edu.btp400.w2017.*;
That doesn't import all the classes in the subpackages indicated by *. The asterisk only refers to classes.
You need to import all the packages individually.
I have just started learning java, so struggling in very basics. The problem i am facing currently is "cannot find symbol : class Ques". I have resolved this issue when i was accessing package from parent directory through CLASSPATH export. Now problem is i am trying to access sub-directory from sub-driectroy like this:
family.of.adam(has)/
father.java
WifeOne(sub-direc)/wifeone.java,ChildFromWifeOne.java
WifeTwo(sub-direc)/wifetwo.java,ChildFromWifeTwo.java
Now what i am trying to do is from wifetwo.java i am accessing wifeone.java. I have tried importing (wifeone)like this:
import family.of.adam.WifeOne.*;
import WifeOne.*;
In both cases it failed to import and same error occured which i mentioned above.
I have also tried solution provided in this Question but this effects classpath of WifeOne this is what i think because when i -cp method it starts showing errors related to wifeone.
I am using normal texteditor, compiling through terminal and using mac. Kindly brief me what mistake i am doing.
Assume src is your base folder(place you compile and run the program).
src/family/of/adam/FirstWife.java
if so you need to define the package startmetn the fist line of the FirstWife.java file.
package family.of.adam;
Then,If the second java file in the,
src/Main.java
In Main.java file you need to define the import statement for user the FirstWife.java class.
import family.of.adam.FirstWife;
I am working on a program that needs to import a jar that has classes both in the default package (root of the jar) and in packages.
So far I have this code and it works so i can import the ones in default but it fails when trying to import ones on packages.
import sys
import os
sys.path.append(os.getcwd() + "/versions/1.7.2.jar")
If I run import a (a is a class as this is a Obfuscated jar.)
it imports but if I run import net.minecraft.server.MinecraftServer it does not work it says No Module named net.
Which I know the class and all packages around it is there so any help?
The problem is that Jython does not correctly find the code.
The source code is based on files like a.class wich you can import but not net.minecraft.server.MinecraftServer.
I am trying to call a python method in java, similar functionality as Unresolved import org.python / working with jython and java?
However, I am using ant to compile and run my files. using import org.python.util will give me this error
package org.python.util does not exist
I can see that python.org.util exists in jython-2.5.0.jar.
So, here is the class path I have in my build.xml ant file:
classpath="${java.class.path}:./jgrapht/lib/jgrapht-jdk1.5.jar:\
./jgrapht/lib/jgraph.jar:./jgraphx/lib/jgraphx.jar:\
./jython/lib/jython-2.5.0.jar:./colt/lib/colt.jar:."
and I also I added the path to jython jar files to my class path. i.e. looks like echo $path gives me all the required paths. Is there anything missing here that I am not aware of?
Try this to make all classes in the package available:
import org.python.util.*;
Or this to include a particular class:
import org.python.util.TemplateAntTask;
EDIT: Also, looks like there is an extra slash after jython-2.5.0.jar in your classpath.
I am in a sub domain subdomain.site.com and there is a java package higher up in the root directory at /usr/share/sphinx/api/java.
The typical thing to do to import this package would be to write
import sphinx.api.java;
However when I just do that, I get a package does not exist error.
What's the solution to this? Some sort of path definition?
(Im on Linux CentOS)
That isn't a package, that is a directory structure. I seriously doubt that is a actual package definition. If a class is there, it probably is in the default package which in the newer JDKs can't be imported.
you're missing the semi-colon at the end of the line:
import sphinx.api.java;