0

I have a NetBeans java project.

This project (src folder) is composed of 6 .java files. The project also uses an external library library.jar and variouus jar files from apache commons (log,configurations etc..)

All java files (when compiled) are used by an external class.

Netbeans generate a build xml files.

<?xml version="1.0" encoding="UTF-8"?>
<project name="CityVisit" default="default" basedir=".">
    <description>Builds, tests, and runs the project CityVisit.</description>
    <import file="nbproject/build-impl.xml"/>

</project>

It refears to nbproject/build-impl.xml but inside of that file there is no reference to library.jar neither to other jars.

My problem is that if I try to compile with javac *.java it doesn't compiles and just print a long list of errors (probably because it can't find the external libraries).

Most of errors are like:

 **can't find symbol <name> **

where is the name of a class/object incluided in one of the externals jar libraries.

How should I do? My goal is to be able to compile my code in another machine WITHOUT using an IDE like Eclipse,Netbeans etc..

As far as I understood the solution is to make a build file and deploy it using ant but practically how should I do?

Thank you in advance for any hint. Regards

dragonmnl
  • 14,578
  • 33
  • 84
  • 129

4 Answers4

1

Using javac -cp , you can tell the compiler where to look for external jars :

javac -cp /lib/123.jar:/lib/abc.jar yourMainClass.java

Note how I'm giving the path to the jar, not just the name (unless they're in the same folder as your own code.

Once it's compiled, to run :

java -cp .:/lib/123.jar:/lib/abc.jar yourMainClass
YYZ
  • 749
  • 4
  • 8
  • 18
  • but is there not a "general way"? I mean: giving a directory where all jars are. Moreover the resulting .class files are used by other classes and should be run without any additional parameters – dragonmnl Jun 18 '12 at 10:56
1

The preffered way is to use Maven to define your dependencies and build your project. More information is available @ http://maven.apache.org/

Samarth Bhargava
  • 4,196
  • 3
  • 17
  • 16
  • Thank you. How should I convert my Netbeans java project in a maven project? (Netbeans has a "new Mavel project" but I can't understand what to do) – dragonmnl Jun 18 '12 at 11:26
  • Check this: http://stackoverflow.com/questions/5495213/converting-a-netbeans-project-to-a-maven-enabled-project – Samarth Bhargava Jun 18 '12 at 12:13
  • I just saw the link. It seems ok (I'll try later). Just a question: when I have a Mavel project what do I have to do to compile the project in an another computer? – dragonmnl Jun 18 '12 at 12:28
  • ensure maven is installed on the other computer and then run mvn clean:install – Samarth Bhargava Jun 19 '12 at 01:37
  • In this end I solved exporting build file from Eclipse and using it with ant. I accept your answer for your effort.thank you! – dragonmnl Jun 19 '12 at 16:07
0

Covert your project into Maven project by creating new Java Maven project copy-paste your files into maven source folder then compile.

-1

Please use double quotes (") & semi-colon (;) around the list of libraries.

  • For more than one libraries separate the libraries with semi-colons:

    javac -cp "/lib/lib1.jar;/lib/lib2.jar" yourMainClass.java
    
  • For only one library:

    javac -cp "/lib/lib1.jar" yourMainClass.java
    
ElGavilan
  • 6,610
  • 16
  • 27
  • 36