2

I have exported my Eclipse Java project in Ubuntu, with all the .java and .class files in place.

The project is composed as follows:

- src
   - package1
        - file1.java
        ...
        - fileN.java
   ...
   - packageM
        - fileM.java
        ...
        - fileN.java

To run the program, I use the following command:

java -Djava.library.path="/path/to/opencv/lib" -cp lib/*:src package.to.main.class.MainClass 

Now, I have changed just a line in a class (which is not the MainClass), and I would like to recompile and run everything. However, when trying with javac in the following way:

javac path/to/main/class/MainClass.java

I obtain millions of errors since:

  • libraries are not found
  • other Java files are not linked

Some examples:

src/it/polimi/tweetcrawlingpipeline/pipeline/TweetCrawlingPipeline.java:7:    error: package org.opencv.core does not exist
import org.opencv.core.Core;
                  ^
  symbol:   class SVMSample
  location: class TweetCrawlingPipeline
  src/it/polimi/tweetcrawlingpipeline/pipeline/TweetCrawlingPipeline.java:158: error: cannot find symbol
   public GenericClassifier<SVMSample> getTextClassifier() {
               ^

How can I fix these problems?

Thanks.

5
  • Can you provide a sample of the errors? Commented Apr 14, 2015 at 12:55
  • You need to specify in your classpath (with -cp) where the compiler can find these library jars and other files. Commented Apr 14, 2015 at 12:56
  • I added some error samples. @OriLentz may you provide an example? Commented Apr 14, 2015 at 12:58
  • Yeah, redirect it to where you current .class files are. For example: javac -cp path/to/your/project/;path/to/your/to/libraries path/to/main/class/MainClass.java Commented Apr 14, 2015 at 13:01
  • Isn't this procedure going to replace those .class files? Commented Apr 14, 2015 at 13:02

1 Answer 1

3

This might not be the answer you want, but it rapidly gets to be painful to compile at the command line with just javac. Unless you put your command and classpath into a shell script, it can get fiddly.

If at all possible, I would recommend using something like ant, gradle, or even maven. Well maven can be overkill, but ant is a reasonable start.

Sign up to request clarification or add additional context in comments.

2 Comments

I cannot use maven due to compatibility problems with OpenCV. How can I generate an ANT file?
So ant is just a program, that may even be there already ('which ant') or just 'sudo apt-get -u install ant'. The build file is usually named build.xml, and there should be lots of documentation on the web about how to set it up. For just compiling a bunch of classes it is fairly straightforward.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.