How to compile java with external libraries in notepad++?
Asked Answered
C

3

5

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.

Cinnamon answered 28/7, 2010 at 19:8 Comment(2)
If you're at the point where you're referencing external libraries, I would recommend you move on to a full-fledged IDE such as Eclipse. It might be possible to do this with Notepad++ plugins, but I am not aware of how to do it.Globigerina
Thank you, but I think i'll stay with np++, I'm still a beginner and I like think I'll be able to learn more this way.Cinnamon
C
6

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.

Cinnamon answered 2/8, 2010 at 18:18 Comment(0)
E
1

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"

Elo answered 28/7, 2010 at 19:13 Comment(1)
Thanks for the reply, I try to do things this way.Cinnamon
G
0

I use the plugin "NppExec" in Notepad++ and I use this script

cd $(CURRENT_DIRECTORY) javac -cp C:\Coding\JAVA\jlablib.jar;. $(FILE_NAME) java -cp C:\Coding\JAVA\jlablib.jar;. $(NAME_PART)

for executing the Java class which C:\Coding\JAVA\jlablib.jar is my .jar file directory.

Globulin answered 3/2, 2022 at 17:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.