开发者

is there any diff between run a java program with jar or with a package unpacked?

is there any diff between run a java program with jar or with a package unpacked? now i meet a Weird pr开发者_JAVA百科obem. i have a search program.when i run it with a jar,it's ok. when i run it just with package unpacked to jar ,then the gc log is a


There is no difference from JVM perspective. JVM knows to load classes from file system or from zip file transparently.

I do not exactly understand which GC log is this but I strongly believe that if you have any difference in running your java program from jar or from unpacked classpath it may be caused by

  • differences in real classpath
  • problems to access specific path in file system (that cause differences in real classpath)
  • differences in options you are passing to JVM (-D and -X options)
  • probably other differences in environment. for example probably you did your first run and user A and second as user B. Or probably you changed working directory.

And another option is if the program you are trying to run deals programmatically (on application layer) with its own classpath. I saw program that assumes that it must be executed from jar named like mycompany.jar. Otherwise it did not work.


To expand slightly on the answer from AlexR; There is no difference from the JVM point of view, however there can be difference from a resource point of view.

That is:

java -cp test.jar com.company.test

and

unzip -d test test.jar
java -cp test com.company.test

Can produce different results in certain very specific circumstances. The only one that I can think of off the top of my head is to when reading a ZIP file resource. The standard resource reader that retrieves a resource from a JAR file, cannot be then passed to ZipFileReader, whereas a resource passed in from a file on disk can be.

That said, given the differences that you are seeing, this is unlikely to be your problem, and the course is almost certainly one of:

  • different command line arguments, either directly or via an environment variable
  • different classpaths. Note that java -jar test.jar and java -cp test.jar com.company.test are not the same thing, and could have different classpaths.

Look at AlexR's answer for other suggestions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜