You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by bing <ni...@hotmail.com> on 2012/02/02 04:57:39 UTC
Fail to compile Java code (trying to use SolrJ with Solr)
Hi, all,
I am trying to coding Java so that use SolrJ to access Solr, but failed in
the first attempt. I have some experience in Solr, but I am a newbie of
SolrJ. The following are the description of what I set, what I did, and what
I got. I will be grateful if anyone can bring out some suggestions and point
out my mistakes.
What I have:
Following are the necessary tools installed
1. Java 1.6.0_26
2. apache-tomcat-6.0.32
3. apache-solr-3.5.0
4. apache-solr-3.5.0-src
5. apache-maven-2.2.1
6. apache-ant-1.8.2
What I Set:
1. Classpath c:\apache-solr-3.5.0\apache-solr-3.5.0\dist
Following are the jars might be used and also consisted in the directory
indicated in the classpath:
apache-solr-solrj-3.5.0.jar
solrj-lib/commons-httpclient-3.1.jar
solrj-lib/commons-codec-1.5.jar
2. Pom.xml in C:\apache-solr-3.5.0-src\apache-solr-3.5.0\
Adding the following dependency:
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>3.5.0</version>
</dependency>
What I Did:
1. Try to compile a MySolrJTest.java.
Following is the sc, simple enough.
import org.apache.solr.client.solrj.SolrServer;
class MySolrjTest
{
public void query(String q)
{
CommonsHttpSolrServer server = null;
try
{
server = new
CommonsHttpSolrServer("http://localhost:8983/solr/");
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
MySolrjTest solrj = new MySolrjTest();
solrj.query(args[0]);
}
}
What I Get:
After I compile the code using the following command, errors arouse:
C:\apache-solr-3.5.0-src>javac MySolrjTest.java
MySolrjTest.java:1: package org.apache.solr.client.solrj does not exist
import org.apache.solr.client.solrj.SolrServer;
^
MySolrjTest.java:7: cannot find symbol
symbol : class CommonsHttpSolrServer
location: class MySolrjTest
CommonsHttpSolrServer server = null;
^
MySolrjTest.java:11: cannot find symbol
symbol : class CommonsHttpSolrServer
location: class MySolrjTest
server = new
CommonsHttpSolrServer("http://localhost:8983/solr/");
^
3 errors
Best
Bing
--
View this message in context: http://lucene.472066.n3.nabble.com/Fail-to-compile-Java-code-trying-to-use-SolrJ-with-Solr-tp3708902p3708902.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Fail to compile Java code (trying to use SolrJ with Solr)
Posted by Mark Miller <ma...@gmail.com>.
Java 6 supports classpath wildcards as well - so you can also do dist/*
On Feb 24, 2012, at 3:33 AM, bing wrote:
> Hi, Dmitry
>
> Thank you. It solved my problem.
>
> Best Regards,
> Bing
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Fail-to-compile-Java-code-trying-to-use-SolrJ-with-Solr-tp3708902p3772017.html
> Sent from the Solr - User mailing list archive at Nabble.com.
- Mark Miller
lucidimagination.com
Re: Fail to compile Java code (trying to use SolrJ with Solr)
Posted by bing <JS...@hotmail.com>.
Hi, Dmitry
Thank you. It solved my problem.
Best Regards,
Bing
--
View this message in context: http://lucene.472066.n3.nabble.com/Fail-to-compile-Java-code-trying-to-use-SolrJ-with-Solr-tp3708902p3772017.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Fail to compile Java code (trying to use SolrJ with Solr)
Posted by Dmitry Kan <dm...@gmail.com>.
High bing,
If you compile your project with solrj jars, you should just make sure they
are explicitly listed in your classpath, not only the directory that
contains them.
You could start with a clean (not maven) java project in NetBeans, create
your class and add the jar dependencies via: right click project node ->
Properties -> Libraries -> Add JAR/Folder
Add the solrj related jars and try to compile.
Dmitry
On Thu, Feb 2, 2012 at 6:19 AM, bing <ni...@hotmail.com> wrote:
> Hi, all,
>
> Following the previous topic, if I abandon my own code and try to build a
> project with the original package apache-solr-3.5.0-src, I failed again.
> Following are the description of some technical details, and I hope someone
> can help to point out my mistakes.
>
> What I Have
> Besides the tools mentioned above, I install the following tool:
> NetBeans 7 IDE
>
> What I Set
> 2. Pom.xml in C:\apache-solr-3.5.0-src\apache-solr-3.5.0\
> Adding the following dependency:
> <dependency>
> <groupId>org.apache.solr</groupId>
> <artifactId>solr-solrj</artifactId>
> <version>3.5.0</version>
> </dependency>
>
>
> What I Did:
> 2. Open the project by loading the original package apache-solr-3.5.0-src,
> and try to build it in NetBeans.
>
> What I Get:
> 2. Following are part of the messages shown in the output :
>
> ------------------------------------------------------------------------
> BUILD FAILURE
> ------------------------------------------------------------------------
> Total time: 5:39.460s
> Finished at: Thu Feb 02 11:00:45 CST 2012
> Final Memory: 28M/129M
> ------------------------------------------------------------------------
> Failed to execute goal
> org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on
> project lucene-core: There are test failures.
>
> Please refer to
> C:\apache-solr-3.5.0-src\apache-solr-3.5.0\lucene\build\surefire-reports
> for
> the individual test results.
> -> [Help 1]
>
> To see the full stack trace of the errors, re-run Maven with the -e switch.
> Re-run Maven using the -X switch to enable full debug logging.
>
> For more information about the errors and possible solutions, please read
> the following articles:
> [Help 1]
> http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
>
> After correcting the problems, you can resume the build with the command
> mvn <goals> -rf :lucene-core
> 'cmd' is not recognized as an internal or external command,
> operable program or batch file.
>
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Fail-to-compile-Java-code-trying-to-use-SolrJ-with-Solr-tp3708902p3708923.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
--
Regards,
Dmitry Kan
Re: Fail to compile Java code (trying to use SolrJ with Solr)
Posted by bing <ni...@hotmail.com>.
Hi, all,
Following the previous topic, if I abandon my own code and try to build a
project with the original package apache-solr-3.5.0-src, I failed again.
Following are the description of some technical details, and I hope someone
can help to point out my mistakes.
What I Have
Besides the tools mentioned above, I install the following tool:
NetBeans 7 IDE
What I Set
2. Pom.xml in C:\apache-solr-3.5.0-src\apache-solr-3.5.0\
Adding the following dependency:
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>3.5.0</version>
</dependency>
What I Did:
2. Open the project by loading the original package apache-solr-3.5.0-src,
and try to build it in NetBeans.
What I Get:
2. Following are part of the messages shown in the output :
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 5:39.460s
Finished at: Thu Feb 02 11:00:45 CST 2012
Final Memory: 28M/129M
------------------------------------------------------------------------
Failed to execute goal
org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on
project lucene-core: There are test failures.
Please refer to
C:\apache-solr-3.5.0-src\apache-solr-3.5.0\lucene\build\surefire-reports for
the individual test results.
-> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read
the following articles:
[Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
After correcting the problems, you can resume the build with the command
mvn <goals> -rf :lucene-core
'cmd' is not recognized as an internal or external command,
operable program or batch file.
--
View this message in context: http://lucene.472066.n3.nabble.com/Fail-to-compile-Java-code-trying-to-use-SolrJ-with-Solr-tp3708902p3708923.html
Sent from the Solr - User mailing list archive at Nabble.com.