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.
Related
What is the equivalent project file for a Java project? For example, a C# project file is denoted by the delimiter of .csproj. So what would it be for a Java project? Is it dependent on what IDE I am using for Java?
I did some search online about this and it seems to me that the answer to this question is dependent on the IDE. From memory, it seems to me, that all I have to do is drop the Java files into an IDE and then, somehow, a project file is automatically generated. I do not want to be steered in the wrong direction on this and so I want to first ask around for guidance.
You're probably looking for the build file, not the IDE project definition.
Is it dependent on what IDE I am using for Java?
Yes. IntelliJ has .iml files, and Eclipse has .project (that's not a file ending - that's the file), as well as .classpath, .factorypath, and more. But, many of these are effectively generated or just refer to the build file. In C that tends to be called Makefile, in the Java ecosystem, Gradle and Maven are the 2 most popular build tools; they have build.gradle and pom.xml respectively. These would be more useful as basis for knowing how a project is 'put together', so to speak.
From memory, it seems to me, that all I have to do is drop the Java files into an IDE and then, somehow, a project file is automatically generated.
That's very basic and should rarely work except for the simplest projects. For example, most Java projects have source files, test files (also source files but they are not part of the distribution), and resource files (non-Java files that are also needed for the app; think about the images for the icon on a button), as well as a ton of dependencies (third party libraries used by the Java app).
Given that folks like many IDEs, the IDE 'config file' is not what you are looking for, and many projects don't even check these into source control (and probably shouldn't). Together with the source, you have a build file. This build file knows how to download dependencies, compile every artifact (there doesn't have to be one; maybe there's the test code to the built, the main app, a plugin for some other tool, and an installer. Build tools can handle all that), run the tests and report on them, possibly even tell you about code coverage, and they usually can run the app, but more generally, you just want to tell the build tool to build a distributable for each relevant artifact.
Those build files are what you're looking for. With those you can build your project, or point an IDE at them and then you can edit the project with all the dependencies and classpath linkages all worked out for you.
I have tried various things starting with Java Maven project to get a jar which when imported looks exactly like the original but I have found that I can't for example get the src/main/resources folder to appear in the imported project. The goal is simple: so that on the new machine for example that the project can be run and worked on just like the original. Not sure what I am missing. I have tried importing existing project from archive which seems like it should work. On the original machine I select all files and folders but this still leaves out some things. I have tried to create an empty folder in Eclipse but this can't be done and various permutations.
A jar file usually contains compiled code and whatever else you drop in there which in turn enables you to run the code.
An eclipse, maven, intellij, ... project structure may be completely different. In the end a transformation will happen from that project structure to the jar content structure. In the case of Maven this will not be the same as the project structure.
The intent of a jar is running the compiled code, an intent of a project structure is to edit the source code.
If you want to copy an eclipse workspace to work on then do so. Copy the workspace folder.
user392486 basically showed what to do. The key is to export the file not as a jar but as a zip and the import it as an existing project which has an archive option. that works just as one would want, an identical project. how i could not already know this is beyond me...
I am writing a Bukkit plugin in Eclipse in which I separate different functions into different packages and export each package as its own jar file.
However, I would still like to keep these packages in the same project, rather than separating them into different Eclipse projects. These plugins each have files which must be in the root of the jar file, such as plugin.yml. I have moved each jar's files into their respective packages, but these files are put into plugin.jar\com\Preston159\plugin rather than in the root of the jar file (plugin.jar\), causing the plugin not to work.
Does Eclipse have any function to make these files automatically compress into the root of the jar file even though they are contained within the package in the source, or, is this something that I could solve by using Maven? My current solution to this problem is to move the files manually after exporting the jar, but this is becoming increasingly annoying.
EDIT:
The project builder XML I ended up using to complete this task can be found here
You would need to use a Build Tool. There are several supported by Eclipse. Ant and Maven are now built-in, but there are several build tools that run directly within Eclipse, but Eclipse can also be configured to run an external build tool as well.
Do a quick search on build.xml for examples of ANT build jobs.
Unless you're specifically required to use MAVEN for continuous integration, etc. then what you want to accomplish would be easily done with ANT.
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.
I've created a simple plugin project in eclipse 3.5 that just stores third-party libraries for the use by other bundles in an eclipse RCP application. Worked as expected: I edited the manifest, exported the required packages and added the libraries to the build path (project build path as well as manifest build path).
Some days later I added another jar to that project, did the same steps (exporting a package, adding the library to the build path(s)) but this time I can't import classes from that exported package in other bundles. The package was clearly selectable on the manifest editor but import statements in classes just taunt me with curly red lines. Importing classes from other packages exported by the bundles still works, only classes from the newly added lib remain invisible.
Has anyone has an idea what I might have missed? I'm pretty stuck and have no idea how to convince google to show me the solution to that ugly issue...
Check the following:
Make sure they are in the Build
Configuration -> Order and Export
area, and they are check for export.
Make sure you have the packages
exported in the manifest (PDE Tools
-> Open Manifest -> Runtime tab)
In the same place as above, make
sure the JAR files are in the
manifest classpath.
(as Al says
below), make sure the build
properties has your jars marked for
exclusion (though this is not likely
your issue as you are getting errors
compiling).
If all of this is done (and it's still not working), do a clean build an restart eclipse. Sometimes the Eclipse gets a little confused about this and a restart helps.
Check the build.properties to see if the bin.includes includes your newly added Jar. Without it, it won't be exported by the build process, and thus won't be able to use it in dependent bundles.