简体   繁体   English

Linux中的类路径限制

[英]Classpath limitation in Linux

We are executing standalone java program from shell script, having a comman script to mention classpath, path, etc..In this common script, we have added several classpaths now and number of character is more than 9000. It is working fine in the test env. 我们从shell脚本执行独立的java程序,有一个comman脚本提到类路径,路径等。在这个通用脚本中,我们现在添加了几个类路径,字符数超过9000.它在测试中工作正常ENV。 Will it cause any issue in Production? 它会在生产中引起任何问题吗? Any limitation is there in linux to set classpath? 在linux中设置classpath有什么限制吗? What is the max char for command line inputs... 命令行输入的最大字符数是多少...

No, there is no limitation. 不,没有限制。 In Windows there is (8191 characters), but not under Linux. 在Windows中有(8191个字符),但不在Linux下。 We work with the concept of classpath-files. 我们使用classpath-files的概念。 These file lists all the dependencies for the application, eg: 这些文件列出了应用程序的所有依赖项,例如:

...
libs/org/easymock/easymock/2.2/easymock-2.2.jar
libs/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar
libs/org/hibernate/hibernate-envers/4.1.0.Final/hibernate-envers-4.1.0.Final.jar
libs/com/google/inject/guice/3.0/guice-3.0.jar
...

and then we convert this into usable classpath and run the application as follows: 然后我们将其转换为可用的类路径并运行应用程序,如下所示:

#!/bin/bash

CLASSPATH_FILE=`ls -r1 ${APP-HOME}/classpaths/myapp*.classpath | head -n1`
CLASSPATH=$(cat $CLASSPATH_FILE | sed 's_^libs_ ${APP-HOME}/libs_' | tr -d '\n' | tr -d '\r' | sed 's_.jar/libs/_.jar:/libs/_g' | sed 's_.pom/libs/_.pom:/libs/_g')

java -d64 -cp $CLASSPATH com.blah.main.Main $@

We have never run into problems and these classpath entries gets pretty huge. 我们从未遇到过问题,这些类路径条目变得非常庞大。

EDIT: As a side note, you can use the maven dependency plugin to generate a list of dependencies. 编辑:作为旁注,您可以使用maven依赖项插件生成依赖项列表。

See this stackoverflow answer about maximum linux command line lengths. 请参阅有关最大linux命令行长度的stackoverflow答案

The maximum command line length will be roughly between 128KB and 2MB. 最大命令行长度大致在128KB到2MB之间。

The max size of any one argument is considerably smaller, though, and 9000 chars might be problematic. 但是,任何一个参数的最大大小都要小得多,并且9000个字符可能会有问题。

When you use in your Java program some classes from a jar file that is specified in the classpath variable, the JVM won't load that class until your running program will explicitly need that class (or if you load that class explicitly from your code - the same idea). 当您在Java程序中使用classpath变量中指定的jar文件中的某些类时, JVM将不会加载该类,直到您运行的程序明确需要该类(或者如果您从代码中明确加载该类 -同样的想法)。 The only problem that can appear when you have a very long classpath , is the time needed for classpath checking before the JVM find the right jar file. 当你有一个很长的classpath ,唯一可能出现的问题是在JVM找到正确的jar文件之前检查classpath所需的时间。 But that should not be a problem. 但那应该不是问题。 If your program behaves well in tests, you should not be worried about this. 如果你的程序在测试中表现良好,你不应该担心这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM