I am currently developing a minecraft plugin that depends on other plugins to function. Shading the other plugins into my own plugin isn't an option since it is impossible to load three different plugins from within the same jar. That's why I need to do it like this. (Another option would be to just use some kind of maven API to download my library on runtime but I have no idea how to google for that)
There is a jar file in the resources of my plugin and I copy it to the outside using Files.copy(this.class.getResourceAsStream("myjar.jar"), new File("myjar.jar").toPath()) but when I try to load it, there's an exception thrown: java.util.zip.ZipException: zip END header not found. The jar in my resources directory is fine. I'm able to unzip it. When I try to unzip the file created by my program my ark (Linux zip viewer) complains about the zip file being broken. How can I copy the file without the file breaking?
If you have any idea how I can shade a maven wrapper or something in my jar to download the other plugin from a maven repository that would be nice too. I also somewhat tried to look up how maven repositories are built to kind of reverse engineer the maven dependency function but I gave up because I don't want to write my own sucky version of maven.
Thank you for reading my question.
Related
I want to download the .jar file of a java framework.
That .jar should of course contain all the .class files that I need for my project.
I tried downloading from here:
https://mvnrepository.com/artifact/org.apache.camel/camel-core/3.18.2
But the .jar file is only 4KB big and contains only meta information, but no java classes.
I found jar files with java classes in them in older versions, but in newer versions they seem to upload only meta information.
So I don't know how to get to the .jar file with all .class files inside.
I don't want to work with maven or gradle for now.
And you can't just download jars with maven or gradle you have to build your entire project with it.
I also searched the github (https://github.com/apache/camel) and source code of the "Apache Camel" project and did not encounter jar files.
Is there any other popular place where open source java frameworks/libraries with jar files can be found?
The apache camel module doesn't contain any code. It just declares a list of dependencies, in the /META-INF/maven/org.apache.camel/camel-core/pom.xml file:
camel-core-engine
camel-core-languages
camel-bean
camel-browse
camel-cluster
camel-controlbus
camel-dataformat
camel-dataset
camel-direct
camel-directvm
camel-file
camel-health
camel-language
camel-log
camel-mock
camel-ref
camel-rest
camel-saga
camel-scheduler
camel-seda
camel-stub
camel-timer
camel-validator
camel-vm
camel-xpath
camel-xslt
camel-xml-jaxb
camel-xml-jaxp
slf4j-api
You have to download the jars that you need in this list of dependencies. All jars can be found on https://mvnrepository.com/.
This is why everyone will recommend you to use maven or gradle, as those tools will manage the dependencies for you.
I have a project where I want to add an external JAR file. The desired external JAR file has a nifty Github page with source, but no pre-compiled JAR file.
These are the steps I've completed so far:
1. I have downloaded the source in a zip. (its Twinkle from SwingFx.ch in case you're interested)
2. I have extracted the zip file to my workspace.
3. I have created a new project with the same name as the extracted folder from the zip file. (project loads the source successfully)
4. I select the export option from the File menu and selected the 'JAR file' option and clicked next.
Note: I had to add an external library to the above Twinkle project for it to build successfully (in case that makes a difference to the settings).
On the JAR File Specification page there are multiple check-box options available(see below):
Export generated class file and resources
Export all output folder for checked projects
Export Java source files and resources
Export refactorings for checked projects
Compress the contents of the JAR file
Add directory entries
I am not sure which are supposed to be selected and if it makes a difference in the behaviour of the project I will add the (soon-to-be) exported JAR file to. I tested it by exporting with the default settings. This worked ok.. However, I now do not know if I should have chosen different settings in case of any reasons I am not aware of. I am not sure if there are specific settings I should choose when I intend for the JAR file to, specifically, be added as an external JAR file to another project.
Please enlighten me!
This is a traditional Java library that uses Maven. It should be fairly easy to build using Maven, which should be better and quicker to build this, if you already have Maven and git installed.
Let's consider that you did not download the source file as a zip, but take the github approach, where you'd use git to download the source code.
If you don't have git, download its latest version and install it.
If you don't have Maven, download its latest version and install it.
Once Maven and git are installed, make sure the Maven and git binaries are configured in your environment PATH variable. If not set, you would, on the Windows platform and for Maven binaries, set it this way (using the default installation path):
set PATH=%PATH%;C:\Program Files (x86)\Apache\maven-3.1.1\bin
Create and change directory in a work directory of your choice, that we'll refer to %work_directory% from now on.
Run the following:
cd %work_directory%
git clone https://github.com/spreiter301/Core.git
git clone https://github.com/spreiter301/Twinkle.git
cd Core
mvn clean install
cd ../Twinkle
mvn package
6. Retrieve the twinkle-1.0.0.jar file in the newly created '%work_directory%/Twinkle/target' folder.
In this case, it was necessary to retrieve the Core library because it is a dependency of the Twinkle project. Normally, this is not necessary because dependencies are automatically retrieved from a maven repository. But in that case, that dependency is not available on any Maven repository. Hence we manually retrieved the dependency from github, compiled it and installed it in your local cached repository. Then we could package the Twinkle project into the JAR file.
This should do it. If you want a 5 minutes tutorial on Maven, there is a tutorial for this here. I highly recommend it, you will encounter this often in the Java world. Maven is the standard build tool for Java, just like 'make' is for C, 'rake' for Ruby, 'sbt' for Scala, etc..! Good luck with the rest.
I'm trying to learn about debuggers in eclipse, and in this article:
http://www.eclipse.org/articles/Article-Debugger/how-to.html
They give a few sample plugins at the bottom that one can install and try out (the zip file on the bottom).
I'm not so familiar with eclipse plugins, and I am unsure as to how to install/view the source code of these jar files in eclipse. I have tried importing them into PDE and that has not worked.
Thanks for any help.
Unpack the ZIP file.
Unpack each JAR file into it's own directory with:
jar xf org.eclipse...jar
One of the unpacked files will be coresrc.zip, which contains the source for the core plugin, and one file will be uisrc.zip, which contains the source for the UI plugin.
Unpack those ZIP files somewhere
Import the directories created from the ZIP files as plugin projects.
This is not elegant, but will get the source into Eclipse.
It is quite possible that you will not be able to run the plugins, as they've been developed for Eclipse 3.0, which is about 100 years old and pretty much all interfaces have changed since then.
What are the best practices (and enabling tools) to deploy Java standalone applications along with any required jar dependencies, config files, and launch scripts?
Are there any Maven plugins that easies publishing binary releases, so that users don't need to use maven for example?
Are there any Maven plugins that easies publishing binary releases, so that users don't need to use maven for example?
Use the Maven Assembly Plugin to create a binary distribution as zip/tar.gz/tar.bz2 of your project. This plugin is extremely flexible - at the price of some complexity - and you can do almost anything you want. Then deploy (in the maven sense) the produced artifact, upload it somewhere, etc.
As for dependency, I just use maven dependency copy plugin and copy all dependencies into a ./lib folder, and supply a launch script that uses the class path wildcard (that way you can change your dependencies as much as you want and don't have to change the launch script). As for configuration files, I put it in a ./config folder and again include it in my app's classpath in the launch script (The former admittedly only works for > java 1.6).
So in the end almost all my app has the following structure:
mystuff.jar launch.sh
./lib
./config
Then I'll just zip up the whole thing and give it to my users. The whole process is probably easy to automate using maven, but I confess that I do it by hand :p
If you prefer and the licenses permit, you could also just bundle all dependencies into a single jar (with expanded dependencies inside) using the assembly plugin. This tends to make the jar bulky and giving the users an updated app. more difficult. Also I had issues with it several time because of class files getting overwritten or something so I personally stick to the ./lib folder.
There's launch4j, which, if you can get it to work, will bundle up a Java app into an executable for your platform.
If your deployment target supports RPM files, I strongly suggest you investigate the rpm-maven-plugin. It allows you to easily map your project artifacts , including dependencies, to a RPM package.
I've been using it with great success to medium-scale application deployment.
You can use Oracle's ant or maven scripts:
http://docs.oracle.com/javafx/2/deployment/jfxpub-deployment.htm
The above will not only compile your code and create jar files, but it will also create binary executable (windows exe file or Mac app file). It can also create native installers. In addition it lets you include JVM with your distribution so the end use doesn't need to install Java.
Take a look at the Appassembler Maven Plugin. You may also want to combine it with the Assembly Maven Plugin.
Use the appassembler plugin to generate a set of "programs" by specifying executable names and main classes. You can also have it prepend and create an etc directory in which you can add configuration files.
If generating the directory with the start-up scripts and directory of binary files isn't enough, you can use the assembly plugin to copy over additional files (say your configuration files) into the appropriate directory and/or package your application into an archive.
I have installed Red5 server successfully and also am able to run the demos fine. Now, I want to create a sample red5 server application. I created a sample project according to the specific directory structure that Red5 requires. But, now when I try to open this project in Netbeans 6.8, I am unable to because both have a different directory structure. So, Netbeans doesn't consider it as a project. I actually want to convert this project to a war file, so I can deploy it to red5/webapps directory and then red5 deployer service can make project out it automatically. How do I convert this project to a war file? because in Netbeans I am unable to open it. Please help.
I don't know if this will fully answer your questions but this is my configuration.
In the main red5 directory there is a file called project.zip, you can open it to get basic configuration files, directories structure and build files for ant (Pure Java build tool).
Using netbeans, you create a new free-form project and point it to the directory of your project. because of the ant build files the project will be recognized.
Netbeans provides it's own ant version but i prefer to install and use ant from command line.
when you'll run ant in the project directory it will try to find dependencies and probably at first will complain that it cannot find ivy.
Ivy is a dependency manager that red5 project uses that can be found in the following URL: http://ant.apache.org/ivy/download.html
please notice that ant will tell you exactly where it searches for the required jar file, just download the ivy zip, unzip it, and place the jar inside it in the requested directory.
once ant will compile the project properly (just by running the commant ant), it will also create a war file under dist directory.
don't forget to add to your red5 netbeans project the relevant red5 jars in order for the project to compile properly.
I am also prefer use ant from command line. I have two directory structures. One for source files and another for deployment.
This example helped me to start.