Java

Home

Compilation

Create jar (IntelliJ IDEA)

File | Project Structure | Artifacts then you should press alt+insert or click the plus icon and create new artifact choose --> jar --> From modules with dependencies.

Next goto Build | Build artifacts --> choose your artifact.

With libraries

For UNIX

If you have these 3 libraries :

You have to type this:

javac -cp ".:lib1.jar;lib2.jar;lib3.jar" sourcefile.jar
java -cp ".:lib1.jar;lib2.jar;lib3.jar" sourcefile.jar
javac -cp ".:lib1.jar:lib2.jar:lib3.jar" sourcefile.jar
java -cp ".:lib1.jar:lib2.jar:lib3.jar" sourcefile.jar

For Windows

You just have to replace : by ;.

javac -cp ".;lib1.jar;lib2.jar;lib3.jar" sourcefile.jar
java -cp ".;lib1.jar;lib2.jar;lib3.jar" sourcefile.jar

Example :

javac -cp ".;.\be\isims\coo\tp5\ex2\lib\libClock.jar" .\be\isims\coo\tp5\ex2\ClockTest.java
java -cp ".;.\be\isims\coo\tp5\ex2\lib\libClock.jar" be.isims.coo.tp5.ex2.ClockTest

Strings

Interpolation

If you're using Java 5 or higher, you can use String.format:

urlString += String.format("u1=%s;u2=%s;u3=%s;u4=%s;", u1, u2, u3, u4);

See Formatter for details.

Packages

To compile code from a package, for example be.heh.ex, you have to do:

javac be/heh/ex/*.java

And then, to run it you only have to do:

java be/heh/ex/Main

ToolKit © 2017
About