StandardAnalyzer does not exist - java

Based on this tutorial I tried to create my own basic Lucene search application. You can also use the given example directly, it has no bearing on my question.
So my file B.java begins with:
import org.apache.lucene.analysis.standard.StandardAnalyzer;
And although I have supplied the classpaths in javac,
javac -cp ~/lucene-4.10.2/core/lucene-core-4.10.2.jar
:~/lucene-4.10.2/analysis/common/lucene-analyzers-common-4.10.2.jar
B.java
I get errors like this:
B.java:1: error: package org.apache.lucene.analysis.standard does not exist
I use the plural because this also occurs for other packages where the .class is inside a given JAR (checked using unzip -l). I assume if I can find the solution for this, it should apply for the other cases as well... what am I missing out here?

OK, I seem to have found the answer.
For some reason, when including the ~ which expands to my $HOME directory, this makes javac unable to find the correct path:
javac -cp ~/lucene-4.10.2/core/lucene-core-4.10.2.jar
:~/lucene-4.10.2/analysis/common/lucene-analyzers-common-4.10.2.jar
B.java
I made a soft link to the directory instead:
$ ln -s ~/lucene-4.10.2/ lucenepath
Then using the symlink, it worked:
javac -cp lucenepath/core/lucene-core-4.10.2.jar
:lucenepath/analysis/common/lucene-analyzers-common-4.10.2.jar
B.java
Not sure why this is the case.

Related

Access another java file in a java file

I know this question has been asked and answered a number of times. But I somehow am not able to get this right. I have a package having the following structure
model/
InputDetails.java
RelationDetails.java
Now the file RelationDetails has the following structure:
package model;
public class RelationDetails {
....
}
And the file InputDetails has the following structure
package model;
public class InputDetails {
.....
}
Now I have compiled the RelationDetails.java file that creates a RelationDetails.class file in the same directory.
But when I try to compile the InputDetails.java file, It shows the error
Symbol not found
wherever RelationDetails has been used. Where am I going wrong??
I'd recommend using an IDE like Eclipse or IntelliJ IDEA. They will do the compiling for you. Or use Ant, Gradle or Maven to compile. I am a professional Java developer and I cannot remember the last time I used javac from the command line. There's no need for it.
If you insist on using javac directly, either compile both files together from the appropriate source folder (the directory above "model").:
javac "model/InputDetails.java" "model/RelationDetails.java"
Or, if you want to compile them separately:
javac -classpath . "model/InputDetails.java"
javac -classpath . "model/RelationDetails.java"
The -classpath . bit adds the current folder to the classpath for the javac executable, so it can find the previously compiled class and you won't get the 'Symbol not found' errors.
$ pwd
/tmp/model
$ ls
InputDetails.java RelationDetails.java
$ javac InputDetails.java RelationDetails.java
$ ls *.class
InputDetails.class RelationDetails.class
I am just tried in my eclipse nothing will be showing errors, better to user Eclipse or STS they will help you like this problems easily I think so..
compile with fully qualifier name.
javac model\YourClass.java

How to use javah

I've just wasted 2 hours trying to do something which I've already done twice before. I can't remember the exact procedure I used the previous two times, but it really shouldn't be giving me this much trouble:
I have a project folder called "BoardGUIv3". I want to produce a header file based on a class called "CANController", with the source located in "BoardGUIv3/src/model" and the class file in "BoardGUIv3/bin/model".
I've done exactly this thing before, but for some reason I can't seem to do this simple, one-line command again.
I'm pretty sure it's something along the lines of
javah -classpath <classpath> src/model/CANController
My classpath should just be the root directory, shouldn't it?
Here is the javah command usage:
{javahLocation} -o {outputFile} -classpath {classpath} {importName}
and it should be used like this for you class:
javah -o "CANController.h" -classpath "C:\pathToYourProjDir\BoardGUIv3\bin" model.CANController
Just correct the path to your classfile with the real path and the package structure if required.

On Java class path, clarification needed

In the following scenario:
APP_HOME=/Users/me/Documents/workspace/Mimer/bin
javac -cp $APP_HOME/lib/*.jar:: BCClient.java
Assuming $APP_HOME/lib contains all the jars needed
What would cause the following:
BCClient.java:35: package com.thoughtworks.xstream does not exist
..
It looks like files libraries needed by the .java are not found, except that when i do the following code fails with the same error
javac -cp "$APP_HOME/lib/xstream-1.2.1.jar;$APP_HOME/lib/xpp3_min-1.1.3.4.O.jar" BCClient.java
This should work with a compiler Java 6+. But if you execute this command from a shell that perform wildcard expansion, then you need to put the wildcards in quotes. More details can be found here.
/Library/Java/Home/bin/javac -cp "$APP_HOME/lib/*.jar:." BCClient.java

javac compilation - code in multiple folders

I have been sitting on it for a while and can't figure it out, although I think it's quite easy...
I have to compile the following program using javac (the program has one class and one testing class):
a class is in folder ./src/cplx/
a testing class is in folder ./test/cplx/
junit lib is in ./lib
and:
classes should be built to ./build/slasses
testing classes should be build to ./build/test
Please help me with writing a proper javac command to compile the code.
I used the suggested command end het the following error, it looks like test class doesn't see the class i have built?
amaltea:testowanie/zad1% javac -d ./build/classes ./src/cplx/*.java
amaltea:testowanie/zad1% javac -classpath ./lib/junit-4.8.2.jar -d ./build/test ./test/cplx/*.java
./test/cplx/ComplexTest.java:20: cannot find symbol
symbol : class Complex
location: class cplx.ComplexTest
Complex a = new Complex(1.1, 2.2);
^
./test/cplx/ComplexTest.java:20: cannot find symbol
symbol : class Complex
location: class cplx.ComplexTest
Complex a = new Complex(1.1, 2.2);
^
2 errors
amaltea:testowanie/zad1%
You can specify only one root destination directory with javac. If you want the root itself to be different you need to compile them separately.
javac -d ./build/classes ./src/cplx/*.java
javac -classpath ./lib/junit.jar -d ./build/test ./test/cplx/*.java
Although it's nice to start off using javac to grasp what is going on at a lower level and understand the language and tools before you begin using more advanced stuff, I think some Ant build script or an IDE like Eclipse or NetBeans would serve you better. At least if you just want a result rather than understanding all the details. You can always learn more about those later. Anyway, the official documentation should tell you what you need to know: http://download.oracle.com/javase/6/docs/technotes/tools/windows/javac.html
You have to specify one more thing in -classpath option..
it should be:
javac -classpath ./build/classes/:lib/junit-4.8.2.jar -d ./test/classes test/cplx/*.java
That's information where your Complex.class file is.

compiling java from the command line

I have a package called studentServer which contains two sub packages student and common.
The common folder has references to the student package and i would like to be able to compile this. How could i do this?
javac student\*.java - compiles the student package
but when i try something similar with the common package errors are thrown - I understand it's something to do with the classpath
javac -verbose -classpath "\student" common\*.java
But I couldn't get this working. Any help would be great.
http://pastebin.com/m2a2f5d5d - here's the output from the compiler
This is a bit vague, but I suspect the classpath for the student code is wrong. Try without the leading backslash.
If you have a directory structure
source/
studentServer/
student/
common/
classes/
And you're in the directory above source, then you want to set the source path to 'source' with the -sourcepath option. You probably also want to use the -d option to tell javac where to put the compiled classes, so they aren't all mixed up with the source:
java -d classes -sourcepath source source/studentServer/student/*.java source/studentServer/common/*.java
go like this
c:\>
use change directory command cd until you get the desired directory
(ex: c:\javaEx\proj1\)
now
cd javaEx go like this
c:\javaEx\proj1\javac *.java
now compilation done in all java files in the proj1 directory.

Categories

Resources