How can I open and run .java files in eclipse? - java

I have to work with a bunch of small applets that were sent to me in a folder, all of them are .java files. In order to see which part of the code is responsible for a particular outcome I want to open it in eclipse and run it there too. How can I do this?
I have tried copying the code into a new eclipse window, but it could not run it.

.java files are pure text files, create java project in eclipse and copy the files there.

Related

Java Eclipse Export keeping folderstructure

I'm getting my java project to a finish and I'm about to export it to an easy useable program on the desktop.
In my program I'm using .txt files to keep all my data, so I've made a folder for my databases and my images.
The problem comes when I'm exporting the project to the desktop and it looks like everything mashes up and becomes one big pile of files instead of a folder structure I made it like in eclipse.
From eclipse
What is the right way to export the project, and how does I keep my filestructure?
Exporting to JAR file at the moment.
EDIT:
I'm also getting this error when I try to follow exampels from the internet.
'Utforsking/src/org/eclipse/wb/swing/FocusTraversalOnArray.java'
You can choose export->General->File System.
Then choose "Create directory structure for files" and that should work. I am using Luna.
If you hit problems, let me know.

Get back my java source code from .war file?

I recently lost my netbeans project folder of the project that I was working on at the time. However somewhere on a server here at the company that I work at, I deployed it. So that means that I (hopefully) can still get hold of the .war file.
Is it possible to then 'unpack' this .war and get my .java source files back that I was working on at the time?
Thanks in advance!
If the .java sources aren't in the WAR (and they should not be), you'll have to take the additional step of decompiling them using a tool like JAD.
This is a good time to set up a version control system, like Subversion or Git or Mercurial, so this never happens to you again. Get into the habit of using source code management, even if you're the sole developer working on the project.
Short answer: No.
Slightly longer answer: Look for Java decompilers, but they won't give you your Netbeans project folder.
You only get *.class files from your war (rename war to zip and use a decompression tool).
Then you could decompile them.
See this related question for some suggestions.
Suppose if you had exported the source files while creating the war, you can get it. Else, JAD is your only hope that too cannot fully rely on it.
It is possible to unzip the war file where you will get only class files and other property files. Then use Java decompiler to see source code and it works really well (not recommended).
Also you can change the property files without JD and all you need to do just change the property files and zip to war file again.It will work.
But I would recommend you to maintain source code in SVN or TFS or multiple copies with version numbers in local system at any point of time.
In Eclipse, you can Import your War, it will create a new Project and set the resources in the project structure. IF your war holds the source java files, the project will cointain your sources. IF not, the packages will be empty and you will have to manually decompile your classes from bytecode to java files, using jad or another decompiler.

Save files in .jar

I have a couple files I want to include in my .jar for a game server. The files, a SQLite database and an icon, work properly when and only when I put them in the Eclipse project folder and run it straight from Eclipse. As I want this to be distributable to end-users easily, how can I include these files and use them at runtime? Thanks in advance!
Accessing files from within a jar file can be tricky depending on the code that's using them. If the code is written to open a file from the file system, you have to extract it. If your Java code opens it with Class.getResourceAsStream(), it can be read from within the jar. You mentioned an icon and SQLite. I would guess you need to extract those files. I've done this with the maven-dependency-plugin and unpack when using maven. "jar xf foo.jar icon.gif" works too.

Taking an eclipse java project and packing it into a jar?

Right now i've written a simple SWT application using eclipse, and I want to pack it into an executable .jar file so I can give it out to friends and such. But I have the following problems:
-Right now i'm reading files by using their filename in the program, and putting them in the root folder of the eclipse project. That works fine for running in eclipse, but when I export to jar they're not in the jar. Is there a way to put them in the jar and access them in the code?
-I also need the SWT .jar dependencies or whatever its called(the files you need for SWT).
Does anyone know how to do this?
Take a look at ClassLoader.getResourceAsStream() API.
All you need to do is include these files in the with the source code of your project, then to have access to then have a look at this link

Getting started with Java using Eclipse

I just heard of library for reading/writing excel files without COM, so I figured I'd go check it out.
I downloaded jexcelapi_2_6_12.zip from this page http://sourceforge.net/projects/jexcelapi/files/ but I have no idea how to open it in Eclipse.
I know it's a silly question, but I'm sure it's not the first time someone's asked it, how do I open this in Eclipse in Windows, compile, run and debug it?
Primarily what you need from that zip is the jar which contains the library. You'll still need to actually write a Java app that uses it.
So what you need to do is:
Unzip the file you downloaded
create a new java project
add a lib directory to the project
copy jxl.jar from the zip into your projects lib directory
right click on the jar in eclipse and select "Build Path>Add to build path"
The classes in the library are now available to your project
Next create a new java file in your projects source folder and start coding.
Extract the zip file somewhere, put the jar file in your project's directory somewhere (e.g. under a lib directory) and then right-click on it and select "Add to build path" or something similar.
It's not runnable on its own though - you'll need to write some code in order to debug.
If you want to debug into the source code of the library itself, you'll need to tell Eclipse where the source is - but that's unlikely to be necessary.

Categories