So I've been pigeon-holed into writing some Jython code. I've been using the latest version of Eclipse IDE with the PyDev plugin for development. Up until now, things have been moderately tolerable. I've gotten all my Python scripts working and I'm successfully including a couple of JAR files and the class directory of another Java project as external dependencies. Everything seems to run fine through the Eclipse IDE.
Now I need to package everything up and deploy it. From what I can gather, the best way to do this would be to package everything up in a JAR file. The Jython documentation suggests starting out with the jython.jar file and adding to it. OK. So I modify my main python module and start adding all my python source to the JAR.
It executes but of course can't find all the external dependencies.
How is one supposed to add the external JAR files so that they are correctly seen by the Jython interpreter? How is one supposed to manage more complex dependencies in a setup like this?
Is there a plugin for Eclipse or maybe something like Ant or Maven that can handle all of these steps for me with the push of a button?
I can't be the first person that has needed to deploy Jython code with complex dependencies can I?
I've made some headway on getting this all working so I thought I would put some notes here in case they help anyone else out. I'd still like to hear from others on their experiences trying to put together something like this.
It turns out that Eclipse as of 3.5 has a project export option for Java -> Runnable JAR File. If you use this option, you can point to a Java main class in the export wizard. You also have the option to have it repackage all the JARs that you are dependent on in your new JAR file. Make sure to check the box to save the export as an ANT build so that you can repeat the process quickly. NOTE that the first time you do this through the interface, it may fail, but it will still have created a JAR file.
Now here's where it gets strange. To track all the dependencies, I am still using a mostly incomplete Maven build in my project. I create the Maven .POM file. And I told Maven what my external JAR dependency was. I then told Maven to do a dependency update for me. It pulled everything into my Maven repository as expected.
Now when I do my ANT build, it appears that it is getting its list of JARs to include in the final build from Maven. I'm not really sure if it is supposed to work that way. I'm also not 100% sure that it is working. I guess I'll find out when I have to add another external JAR to the project.
Anyways, if you follow this question you'll see that you can take the latest builds of Jython and pull the org.python.util.JarRunner.java file out and use it in your own project. This is you Java.main class that you will need to point your ANT build at. From there, convert your main Python/Jython script to be the run script that was talked about in that question.
Next, build up another copy of the Jython JAR file in your Jython directory. This one should have the /Lib directory pulled into the JAR. Save that off and then point your Eclipse IDE Jave Build option for your PyDev project at that JAR as an external dependency. Your JarRunner will now work and execute the run.py file under Jython.
If all that works, you should then be able to rerun the ANT exported build from earlier and you will end up with a single JAR file that you can execute on the command line as:
java -jar {yourjar} args
And distribute to your customers without any additional dependencies.
If that all seems a little bit convoluted, it is. If anyone has a better way of setting this all up using Eclipse, please let me know.
Make your life easier and just use Maven and the mavenjython compile plugin.
See my answer of this question: Using Jython with Maven
You get full automation of the build and deploy process, and the result is a jar that includes jython and all other dependencies.
Related
I've recently come with the need to create for a Java project a build.xml file in which is meant to be run using the terminal.
The issue is that until now we've used Eclipse as the utility to run the build.xml while depending on Eclipse UI to let the Ant package manager to create our jars, but not putting the external jars in each jar we create.
That way, the memory in which the jar libraries take(~40MB) isn't replicated to each Jar we make.
I'm pretty a beginner in Ant so what I'm trying to do is create a build.xml in which take a folder of Jar libraries, and for the project which is a Jar library itself, create the Jar while knowing the libraries but not include them in the end Jar.
I alternatively tried understanding how eclipse teels the build.xml for ant but the classpath of the project, how to access the jars and other configurations, so if there's a possibility for that then it will be much better.
If possible, it would be great to help with that.
I've tried of course seeing other questions on Stackoverflow but didn't saw something similar to this.
If there's one of course I'll be happy to see it :)
Thanks heads up! :)
I am trying to use a number of external libraries in a Java project. The project runs fine from Intelij but I want to package it in a jar, (or something else) so I can distribute it to others. When I package it in a jar it works if I just do hello world, but as soon as I start using my libraries I get the error bellow. I have also tried packaging it as an application but when I run the batch file it just opens and then immediatly closes a command window. I read all the other posts and nothing is fixing my problem. Please help
My error
My build.gradle
The problem is most likely that your classpath does not point to the correct relative location of your 3rd party libraries. You can check the manifest file to verify if the paths are correct.
However, if it is a runnable jar file with a main method (which it looks like it is), you should use the Application plugin and package it with the Distribution plugin. Right now you are using the Java Library Distribution plugin, which is for libraries. If you do this, you can remove most of the stuff under your jar task.
When testing it locally, run gradle run and when ready, use gradle distZip to create a zip of it all. It will create a script used to start the application with the correct classpath.
Alternatively, you could also package it in a fat jar using the Shadow plugin or similar.
For a project I completed a game in Java on Eclipse using LibGDX. I now need to turn in the source code to my professor. When I export the project and try opening it on a new computer, about a dozen libraries are missing.
I would like to export my entire project so that when the project is opened in eclipse, it will still compile. Is there any way to do this? I know that runnable jars come with the .jar files of the dependencies and no source code, but I need both.
Thanks in advance
Libgdx required number of dependent jars so it's hard to manually add all jars into project.
Make your project gradle based so that When you import your project through gradle into another System then gradle do most of your task* for you.
*gradle try to find dependent jars in file system if already exist then link with your project if not then it download from given repository and link them in your project. Make sure your system is connected with internet when you build your project.
I highly encourage to use Android Studio or IntelliJIDEA.
On window, by default all jars are stored inside
C:\Users\User_name\.gradle\caches\modules-2\files-2.1
In Mac OSX
/Users/User_name/.gradle/caches/modules-2/files-2.1
When you want to deploy or packaging for the desktop run this command on your IDE terminal.
gradlew desktop:dist
You can use maven or gradle to build your project, take a look of one of the tool and it's won't take you too much time. these tool could help you define your own way for build
A much easier way you could use "fat jar". this is an old tool for build a jar with all lib you need and could be run in any place.
I'm coding a project that uses JRuby and I want to be able to do three things in one command, right off the bat after cloning the repository.
Install rubygem dependencies.
Install maven dependencies.
Package everything into a standalone jar, including JRuby.
What is the simplest and most straightforward way to achieve this? I could probably hack around with custom build commands in my pom.xml, but it seems like other people must have wanted to do this before. I don't want to mess around with a shell script that downloads stuff through maven and then shoves my ruby code into ruby-complete.jar, after "java -jar ruby-complete.jar -S gem install"ing my gems. I want a simple, declarative file that says: "these are the dependencies, now parse me and figure out how to get what cheshircat wants."
Is there a way to do this with maven? I've tried jbundler, but it keeps giving me errors, and I've tried it on multiple platforms.
I would look at the torquebox jruby-maven-plugins. I use them for my work to do two of the three requirements you list:
'Install rubygem dependencies' using the gem-maven-plugin
'Install maven plugins' like any other plugin because it's maven and maven is driving the build and packaging.
The gems get installed to your project's ./target/rubygems directory.
I am sure you can jar up whatever you want with the maven-jar-plugin.
I wrote up a more detailed explanation:
http://thechurchofautomation.com/java-ruby-interoperability-torquebox-maven-plugins/
Not sure about the maven dependencies, but in general warbler is the tool you want for packaging up everything, including jruby and gem dependencies, into a standalone jar.
https://github.com/jruby/warbler
It will do .war as well as .jar. If your thing doesn't look like a webapp (doesn't have a rack.up file), it'll do a jar though, just what you want.
It doesn't need any extra declarative config, it just uses what you've already got, like your Gemfile.
You may have to do maven as an extra step, but you could try asking the warbler folks for advice.
I have been making something in eclipse until just recently I had some technical issues causing my hard drive to be completely destroyed and I lost everything except a jar file.
I wish to start working on it again but am not sure what to do since I have no source file just the jar. I tried decompiling and importing except it made a mess of my code and will take forever to clean it up. Hopefully I did something wrong and there is a much easier way to do this.
If you don't need the sources of the JAR you can make a dependency to it within eclipse (right click on project -> Build Path -> Dependencies).
Or if you use a build tool (maven, gradle, etc.) put the jar to your local/remote repository and put it as dependency to your build file.
Otherwise decompile the JAR for e.g. with Java Decompiler and put the java files to your eclipse project.