Change the project dependencies folder (lib)

3

When compiling my project in Netbeans , the files are generated in this way:

./dist
./dist/meuProjeto.jar
./dist/readme.txt
./dist/lib
./dist/lib/dependencia1.jar
./dist/lib/dependencia2.jar

And I want it to be generated without the lib folder, like this:

./dist
./dist/meuProjeto.jar
./dist/readme.txt
./dist/dependencia1.jar
./dist/dependencia2.jar

I know you have to change the build.xml , but I did not find anything that talked about how to change the target of .jar dependent.

    
asked by anonymous 01.04.2015 / 16:06

2 answers

0

To achieve the desired result I had to make two adjustments.

1st In the file meuProjeto\nbproject\build-impl.xml I adjusted the line:

<globmapper from="*" to="lib/*"/>

To:

<globmapper from="*" to="*"/>

This line is intended to define the path from where the .jar pendents are, relative to the .jar being executed. This path is generated by this script and stays in manifest.mf which is saved within% comp_con%.

2nd In the file .jar I added the lines:

<target name="-post-jar">
    <echo message="Copiando as bibliotecas dependentes para o mesmo diretório do jar"/>
    <copy todir="${dist.dir}">
        <fileset dir="${dist.dir}\lib"/>
    </copy>
    <delete dir="${dist.dir}\lib"/>
</target>

PS: Remembering that this solution is extremely dependent on the IDE used, in this case NetBeans.

    
06.04.2015 / 14:47
2

I think you're looking to do something like "Big Jar" by packing all dependencies into a single .jar file

For this you should use the "Ant".

In Netbeans, open the build.xml file and leave the project tag as below substituting the name of the desired jar:

<project name="NOME_DO_SEU_JAR" default="default" basedir=".">
<description>DESCRICAO_DO_SEU_PROJETO</description>
<import file="nbproject/build-impl.xml"/>

    <target name="-post-jar">  


    <property name="store.jar.name" value="NOME_DO_SEU_JAR"/>  

    <property name="store.dir" value="store"/>  
    <property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>  

    <echo message="Packaging ${store.jar.name} into a single JAR at ${store.jar}"/>  

    <delete dir="${store.dir}"/>  
    <mkdir dir="${store.dir}"/>  

    <jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">  
        <zipgroupfileset dir="dist" includes="*.jar"/>  
        <zipgroupfileset dir="dist/lib" includes="*.jar"/>  

        <manifest>  
            <attribute name="Main-Class" value="${main.class}"/>                  
        </manifest>  
    </jar>  

    <zip destfile="${store.jar}">  
        <zipfileset src="${store.dir}/temp_final.jar"  
        excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>  
    </zip>  

    <delete file="${store.dir}/temp_final.jar"/>  

</target> 

    
01.04.2015 / 17:21