开发者

How can I get the project name in java?

Is there an easier way t开发者_高级运维o get the project name rather than parsing the path to the execution directory? JavaSE-1.6


Ah OK. I'm working with Eclipse. There it's called project name and it's the string of the folder which contains the whole application.

Firstly, this is an IDE-specific concept. Java (in general) has no concept of a project.

Second, it is probably not a good idea to make a program depend on the name of the Eclipse project. That will cause problems if you ever try to run your program independently of Eclipse and the build environment.


If you are making use of a jar archive file for your application and ant builds you can do the following;

  1. You can have the ant build file set a value (Project-name) in the MANIFEST.MF file, excample;

    <manifest file="${basedir}\resources\jar\META-INF\MANIFEST.MF">
        <attribute name="Manifest-Version" value="1.0" />
        <attribute name="Version" value="${release.version}" />
        <attribute name="Company" value="S1" />
        <attribute name="Project" value="<project_name>" />
        <attribute name="Java-Version" value="1.5" />
    </manifest>
</target>

<target name="dist_jar" depends="create_manifest">
    <delete file="${basedir}\build\jar\${jar.name}" />

    <!--Create the JAR for the build-->

    <jar jarfile="${basedir}\resources\jar\${jar.name}" 
        manifest="${basedir}\resources\jar\META-INF\MANIFEST.MF" 
        basedir="${jar.classes}" />
</target>
  1. Read the Project name from the MANIFEST.MF. See Read Manifest from Java code.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜