How to combine several cans into one?

I read so many articles / explanations about this and spent too many hours, but everything is either too broad or specific.

This question really only applies to the Applet I made. It contains one class and requires 2 other Jar libraries. I included them in projects (several projects because I tried this in Netbeans and Eclipse ... it's easy to recreate a project of one class). The fact is that my HTML / web project should not deal with or reference more than one Jar. This is not a complicated applet / project at all.

I originally did this on Netbeans. It has the main package, and after adding 2 Jars they are placed in the "Libraries" area ("resources" folder). After creating it, Netbeans creates a Jar for my one package / class, and then puts the other two libraries in the "lib" directory next to it. I would like them to be in one distributed bank. Of the many things I looked at, I tried putting the following in build.xml:

<target name="YourBigJar" depends="-post-jar"> <jar destfile="dist/BigJar.jar"> <zipfileset src="dist/cxapplet.jar"/> <zipfileset src="resources/dpotapi.jar"/> <zipfileset src="resources/dpotjni.jar"/> </jar> </target> 

But it does not produce anything. I got this from NetBeans - deploying in just one bank . I don’t know / understand how to use build.xml, so I won’t be surprised if something goes wrong (obviously), but I do not have error / warning messages.

When I did this in Eclipse, it effectively merges them, but when I use Jar in my actual web project, it says that it cannot find classes from the other 2 jars. I would not understand how to fix it, but is it a class problem? In Eclipse, I create a new directory called "lib" and put the Jars in it. Then I right-click the project, go to the "Java Build Path" and add the Jars, also checking them on the "Order and Export" tab. From everything that I read, I right-clicked the project, select "Export", select "Jar", uncheck the ".classpath" and ".project" files, just check "Export generated class and resource files", and then allow it to generate a manifest file. As I said, this generates one Jar, but its contents are my package, and then the "lib" directory, in which there are two other Jars. There is a manifest, but it is quite empty and does not refer to any files (not sure if this is important). When I put this in my web application, it says that the applet cannot find other classes.

It just seems simple - one package / class, two external Jars ... merge into one Jar when it is created for distribution as an applet. Any ideas?

UPDATE:

Ever since we started using Maven, someone has learned to use the Maven plugin. So, we finished creating a new project to host the applet (since it was used for several projects) and used it in our pom.xml , at the end:

 <build> <resources> <resource> <directory>${basedir}/applet</directory> <excludes> <exclude>codesignstore</exclude> </excludes> </resource> <resource> <directory>${basedir}/src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.2-beta-5</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <finalName>cxapplet</finalName> <archive> <index>true</index> <manifest> <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest> </archive> <appendAssemblyId>false</appendAssemblyId> </configuration> <executions> <execution> <id>make-my-applet-jar</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jarsigner-plugin</artifactId> <version>1.2</version> <executions> <execution> <id>sign</id> <goals> <goal>sign</goal> </goals> </execution> </executions> <configuration> <keystore>${basedir}/applet/codesignstore</keystore> <alias>codesigncert</alias> <storepass>HIDDEN</storepass> <keypass>HIDDEN</keypass> </configuration> </plugin> </plugins> </build> 

And it was nice because it allowed us to use our code signing certificate to automatically sign it.

+8
java eclipse jar applet netbeans
source share
2 answers

First of all, let me say that there really is no reason to combine banks - you can deploy the applet using your class file (not in the bank) and its individual dependent jars.

However, if you feel that you have to make one big jar of your class and all its dependencies, then you can do it.

You cannot put jar files in another jar file, however - jar files do not work this way. What you need is for all the contents of all the jar files that you need to extract, and then pinned again in one jar.

If you are going to do this, I would suggest using the Maven tool to create. After you customize your assembly using Maven, you can customize the Maven Assembly Plugin to create one large jar for you.

I know that Eclipse supports Maven, and I assume that NetBeans also does.

+4
source share

From the base of your bin directory, why not try:

 jar.exe -cvf cxapplet.jar * 

Put your external jar files in the appropriate place in your bin and manually assemble your class files with external jar files.

Alternatively, see this thread , which may provide you with additional information.

-one
source share

All Articles