How do I properly export a .jar file with IntelliJ? - plugins

I get that I have to use the Build Artifact option, and include all of those module files, but whenever I build the artifact, the ONLY thing that is in the .jar is the manifest file. How do i get the rest of my program into the .jar?

You should click the '+' and add 'Module output' to jar file.

Related

Exclude Ivy Dependencies in WAR File

I use Eclipse and the Ivy plugin IvyDE.
I currently create a WAR file by using Eclipse's export to WAR functionality. I don't use an ANT build file - I let Eclipse handle that.
When I export to war, all the dependencies in the ivy.xml file get copied to the war file's bin directory. I want to exclude one (or more) of them. How do I do that?
What't the simplest way to accomplish this? If possible, I would like to avoid creating my own ANT build files and continue to use Eclipse's export tool and the IvyDE plugin.
For me the following did the trick:
copy the ivy.xml to e.g. ivy-nodeploy.xml
create/select the configurations you want to include in the deployment assembly in ivy.xml
create/select the configurations you don't want to include in the deployment assembly in ivy-nodeploy.xml
add a new ivy-library to the build path where you change the default ivy-filename to
ivy-nodeploy.xml
That way you still have all ivy managed libraries at compile time in your build path but only libraries configured in ivy.xml get included in the war file.
Right click on your project's ivy.xml, and choose "Add ivy library".
In the main tab are customization settings for the build configs, and it looks as though you can choose the conf you desire (i.e. set it to runtime). I war using Ant, so I've never tried it. I presume this will accomplish what you desire.

Copy file from sbt plugin to project folder

I'm writing an sbt plugin to help with deployment. It depends on sbt-native-packager. Principally it adds a deploy task. However, I also need it to copy a bash script run-class.sh into the /bin folder of the package.
How do I copy a file from the sbt plugin to my project? Presently my only idea is to add the file to src/main/resources/run-class.sh in the plugin and generate a file using sbt. Then I can supply a Universal mapping to put the file in the sbt-native-packager package.
Is there an easier way to get a file from the plugin into my sbt project?
You are on the right track with Generating files, specifically Generate resources. You can keep your original file either as a resource or String, but important thing is that the files are generated into resourceManaged in Compile, which is under target. This folder is typically skipped from version control.

How to deploy a JAR file with all required JAR files in Eclipse

Can someone please explain how do i compile an app to a JAR file that will include several other libraries?
I have included three JAR files that need to compile with application.
I have tried to go with "Export/Runable JAR File Export" as suggested, but the "Launch Configuration" dropdown is blank.
I tried Running the program and it runs fine, also if I check the "Run Configurations" all seem fine.
What am i missing?
I have downloade MAVEN plugin, converted the project to MAVEN project.
Then i included the POM.XML where i included all the dependencies and JAR signature.
The project is then exported as JAR file with MAVEN install command.

manifest.mf is overwritten by eclipse during jar export

I would like make an executable jar archive with eclipse.
So into my project I created file src/META-INF/MANIFEST.MF :
Manifest-Version: 1.0
Main-Class: MainClass
Class-Path: .
But when I export my java eclipse project eclipse warn me with following message:
"JAR export finished with warnings. See details for additional information.
myproject/src/META-INF/MANIFEST.MF was replaced by the generated MANIFEST.MF and is no longer in the JAR."
Anyone know how I can avoid this when I export my project in eclipse?
While exporting the jar, select the option to use existing manifest and browse to the manifest file of your project. The generated jar will have that manifest file now.
Using existing manifest http://img46.imageshack.us/img46/6752/export.png
Using Oxygen (Release 4.7.0), I was able to do this successfully. The confusing part is that on the JAR File Specification page of the JAR Export wizard, both the Next and Finish buttons are active. So if you don't notice that and just click Finish, you'll end up with a warning (and the generated manifest). To use your own, click Next instead (once for JAR Packaging Options, and again for JAR Manifest Specification).

how to exclude external jar while creating executable jar in eclipse or commandline?

I have written a program in Eclipse IDE which uses BouncyProvider class of BouncyCastle.jar. So to compile my class I added BouncyCastle.jar in my project classpath and it compiles perfectly.
Now I want to export my project as Runnable JAR so when I do that from Eclipse, it by default adds the classes of BouncyCastle.jar also in that runnable jar.
But I want to keep my application jar and BouncyCastle.jar different from each other.
How can I achieve this? Can anybody please help?
It sounds like you want to use the "Export JAR File" wizard instead of the "Export Runnable JAR File" wizard. When exporting a runnable jar file, Eclipse attempts to pack everything needed to run the application into a single archive. On the other hand, the "Export JAR File" wizard gives you more control over what is packaged in the archive. You can still create a runnable jar file, but you must make sure to include BouncyCastle.jar on the classpath when you execute the jar. Here are step-by-step instructions:
Click "File | Export". The Export
dialog pops up.
Expand the "Java" folder and select
"JAR file" (not "Runnable JAR
file"). Click Next. On the JAR file
specification page, choose the
classes you want included in the jar
file, and specify the name of the
JAR file to create. Click Next.
On the JAR Packaging Options page,
select options appropriate for you.
The defaults are probably fine.
Click Next.
On the JAR Manifest Specification,
make sure to select the "Main class" for your jar file. This is
the class that will be executed when
you execute the jar file. If you
leave this blank, the jar file will
not be runnable. Click Finish to
create the jar file.
You should be able to execute the jar file by executing "java -jar myjarfile.jar -classpath BouncyCastle.jar" from a command line.
Unfortunately, looks like you can't actually do that. A JAR can't use another JAR that's stored inside itself.
I'd say, unless you have a really strong reason why you can't unpack your BouncyCastle.jar
(like maybe licensing problems?)
just let it unpack (which you can do by adding BouncyCastle.jar as an external archive in Eclipse:)
Right-click on your project
Build Path...
Add External Archives...
Add your archive
Export as runnable JAR)
and watch your package names for conflicts.
Here's an open Java bug ID I found describing your situation
One-JAR may help - a open source solution to your situation
It looks like this has been added in Eclipse 3.5 Milestone 5. See the News for the latest build and bug 219530