Deployment Concepts: Packaging JAR Dependencies, When & Why

后端 未结 2 475
别那么骄傲
别那么骄傲 2021-02-10 04:08

So I\'m relatively new to Java EE and I am having a tough time understanding when, where and why Java deployment files are packaged with their dependencies.

Say I build

2条回答
  •  孤城傲影
    2021-02-10 04:22

    JAR files are a way to package togher complex java application. Jar application are easy to move between diffrent machines and operating system.

    I think the right way to use Jars is not tu put everything (every dependencies) into a single jar.

    For example if your application uses a jar libryra (for example jdbc) to access a database you should not put the jdbc jar into your jar.

    You had better to build a jar file with only your .class file.

    Of course your code needs the jdbc jar to work properly. Here comes to explain how the virtual machine searches for extarnal classes:

    -it first searches in the directories that contain the classes that come standard with J2SE (the path depends on your installation)

    -it searches in the directories specified by the classpath (a classpath is either an environment variable or an option of the java command)

    for example:

    java -jar -c /your/path/ yourApp.jar

    will run your application and will search th classes your application refers to in the directory /your/path/ so if you have external jars you can put them in that directory.

    For detailed documentation: http://download.oracle.com/javase/tutorial/deployment/jar/index.html

提交回复
热议问题