Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to compile java with external libraries in notepad++?

I'm using Notepad++ to learn Java. I have it set it up to compile and run Java from the Run menu, only that I have been coding small exercises without external libraries, I know I have to use -classpath to tell the compiler what library to use, but I was wondering if there is any way to tell the compiler to "use" the libraries in the lib directory of my current project.

Thanks.

like image 767
Eduardo Rascon Avatar asked Jul 28 '10 19:07

Eduardo Rascon


People also ask

Can you compile Java program in notepad?

Note: We are considering that Java is properly installed and the path is properly set in your system. Step 1: Open the notepad by pressing the Windows Key + R, type notepad and press enter key, or click on the Ok button. It opens the notepad. Step 2: Write a Java program that you want to compile and run.

How do I compile a Java library?

Open a command prompt and navigate to the compile-packages-in-java directory. Then type in the command to compile the Person source and hit Enter . Notice that you provided the path of the Java file. This path corresponds to the package name.

Can Notepad ++ compile Java?

Go to plugins and open Execute NppExec Script from NppExec . Select Java_Run and click ok to run the Java file in the console; see the output below. The Java program is successfully compiled in Notepad++. Now, you can run Java programs in Notepad++.


2 Answers

Turns out that you can put any jar file into the ext folder (C:\Program Files\java\jdk1.6.0_21\jre\lib\ext and C:\Program Files\java\jre6\lib\ext) and java will automatically considered it part of the classpath, check it out: ext directory: Java Glossary

Dirty but it does what I need.

like image 109
Eduardo Rascon Avatar answered Oct 12 '22 10:10

Eduardo Rascon


It is only possible with an IDE (Netbeans, Eclipse, etc.).

In command line, you have to precise jar by jar the dependencies in the -classpath option.

Note : "-classpath directory" exists. It will add to your classpath the classes and the files (conf properties for example) of this directory, but it will not magically add the jar contents in the classpath.

If you are good at shell programming, you can develop a java launcher that will take one (or several) directory in parameter and create the program launch command for you.

Another method is to create once an environment variable (containing your classpath). You won't have to type the command line each time, but only "java(c) -cp $CLASSPATH MyProgram"

like image 22
Benoit Courtine Avatar answered Oct 12 '22 11:10

Benoit Courtine