0

I would like to build my Java project from command line via a single command or external script, not using Eclipse, but just with the JDK. My project has 6 .jar libraries and 6 .java source files. If I need to compile each first, I can do that. I don't want to use ANT or MAVEN. Just plain .sh for now.

There's probably an answer somewhere how to build with libraries and multiple classes, but most search result show Eclipse, Ant, and Maven. There is how to compile each class, to create a .class file. In Eclipse, I even already have that in /bin, so I could just link those together (or could I just run the .class file?) somehow.

So, what command can I use to build a project with 6 .jar files and 6 .java files? I see this (Including jars in classpath on commandline (javac or apt)), but I also want to have separate build directory and am confused whether the class-path should be the build or source directory or both.

Community
  • 1
  • 1
user1122069
  • 1,767
  • 1
  • 24
  • 52
  • I understand your question in simply, you have src directory and few jar files associated with it. You want to create a runnable jar file from command prompt. Is it correct? – Pasupathi Rajamanickam Oct 27 '15 at 06:34
  • 1
    What's wrong with ant or maven? Do you know that eclipse can ["generate"](http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-71.htm) an ant script for you? –  Oct 27 '15 at 06:42
  • "am confused whether the class-path should be the build or source directory or both" **class**path so path for ".class" (i.e. build dir) –  Oct 27 '15 at 06:44
  • This post may help you. http://stackoverflow.com/questions/9597437/how-can-i-make-jar-in-linux – Sachin Mhetre Oct 27 '15 at 06:45
  • Also search on internet. It should not be that much tough... – Sachin Mhetre Oct 27 '15 at 06:48
  • @RC They're just the worst systems ever! See https://johlrogge.wordpress.com/2010/12/14/why-i-dont-like-maven/ – user1122069 Oct 27 '15 at 17:58
  • http://c2.com/cgi/wiki?AntVsMake – user1122069 Oct 27 '15 at 17:59
  • You should probably keep it real, but anyway do as it pleases you. –  Oct 27 '15 at 21:29
  • @Pasupathi Yes. Look at the comments on the answer below if you can help with it. – user1122069 Oct 28 '15 at 16:01
  • @RC. To keep it real, I took your post as sarcasm. Such a discussion detracts from the question and pollutes the comments box. I am learning one thing at a time. If you can find a good tutorial(s) on the usage of ANT or MAVEN, I would take a look at it, having solved this issue. I've already spent hours on that and no success. – user1122069 Nov 01 '15 at 22:34

1 Answers1

2

Use the javac compiler from the Java SE development kit to compile Java source files. You can use the existing Java ME Platform SDK project directory structure. Use the -bootclasspath option to tell the compiler to use the MIDP APIs, and use the -d option to tell the compiler where to put the compiled class files.

The following example demonstrates how you might compile a MIDP 2.0 application, taking source files from the src directory and placing the class files in the tmpclasses directory. Newlines have been added for clarity.

javac -target 1.3 -source 1.3 
   -bootclasspath ../../lib/cldc_10.jar;../../lib/midp2.0.jar
   -d tmpclasses
   src/*.java

For the complete guide on how to execute/build code from the command line, consider looking on the official java website: http://docs.oracle.com/javame/dev-tools/jme-sdk-3.0-mac/UserGuide-html/z400007747176.html

t.rader_
  • 36
  • 2
  • Answer edited to change bootclasspath to classpath and added note "classpath uses a semi-colon (;) on Windows and a (:) on Mac/Linux." May not be accepted as a review, but will accept this answer. – user1122069 Nov 01 '15 at 22:27
  • Use the -classpath option to tell the compiler where to find the jar files, and use the -d option to tell the compiler where to put the compiled class files. The following example demonstrates how you might compile an application, taking source files from the src directory and placing the class files in the tmpclasses directory. Newlines have been added for clarity. javac -target 1.8 -source 1.8 -classpath ../../lib/cldc_10.jar;../../lib/midp2.0.jar -d tmpclasses src/*.java Note: classpath uses a semi-colon (;) on Windows and a (:) on Mac/Linux. – user1122069 Nov 01 '15 at 22:37