Eclipse edit java files and run under original folder - java

Although this seems an easy thing I'm not able to find the answer for it.
What I'd like to achieve is simple. I have a folder with java source files and I want to edit them using eclipse within a new project. But at the time of running the application I don't want eclipse to use the workspace project folder as "root", instead it should use the folder with the java source files.
The effect should be like opening the source files with a text editor directly and changing them, but instead this should be done through an eclipse project but still use the original folder to run the application.
I just want to have all the advantages that come from editing source files within an eclipse project instead of using something like notepad++.
I tried linking the source files and changing the relative path to the source directory but it doesn't work. When running the application it needs xml files which exist in the directory but because it's running "from" the eclipse project folder it doesn't find them.

I'm not sure I really understand what you want to do, but sounds like you want to set the run configuration's working directory: Open 'Run Configurations', choose the class containing your main method (or create a new run configuration for that class first if it's not yet there), then specify the Working Directory on tab 'Arguments'.

I do same with all my projects. What you need to do is :
Create workspace directory on different location than your source code.
Import your source code in your workspace directory. Here don't copy source to your workspace
EDIT
In Eclipse
Go to File->Switch Workspace->Other-> Type "new directory workspace" path, click OK. Eclipse will restart.
Go to File->Import->General-> Existing Projects into Workspace-> Next-> Select Root directory
Eclipse will list your project, select it.
Start editing and saving files.

Thought this does not directly answer your question, as an alternative to using Eclipse IDE for Java files try using Padclipse which is a text editor based on Eclipse.
Padclipse is a light weight text editor based on Eclipse. The basic
product is composed of Eclipse RCP plus Text Editor, Compare and
Search facilities and their dependencies. A few additional third party
plug-ins are included as well.
Check it out here
Also, the default JDK on my system was a 64 bit because of which starting up padclipse failed. Create a padclipse.ini in the folder where you unzipped it in and put in the following contents :
-showsplash
-launcher
padclipse.exe
-name
Padclipse
--launcher.library
plugins\org.eclipse.equinox.launcher.win32.win32.x86_1.0.0.v20070523\eclipse_1017a.dll
-startup
plugins\org.eclipse.equinox.launcher_1.0.0.v20070606.jar
-vm
C:\dev\jdk\1.5\1.5.0_21\jre\bin\server\jvm.dll
Change -vm argument to point to the java.exe or jvm.dll of a 32 bit jdk.

Related

Exporting processing to a jar file

I've been working on a processing application using ControlP5 and Twitter4j. I want to have my project run from a single jar file from any operating system. Basically I want to package up my application. My application uses images. I've been browsing for more than an hour, but I cant find how to do this. Any suggestions?
using
processing 2
twitter4j3
Thanks in advance!
I dont know if you can directly do it from the Processing IDE however, if export your sketch to a Java applet then locate the .java the the sketch folder you can use this in conjunction with Eclipse to export to a jar file.
So, I know that this post is very old but if you are still looking for a solution, or to other people that see this thread, it's relatively simple.
Export the project
In the folder with the exported project (something like application.windows64), navigate to lib and find core.jar and project name.jar (you need to have file name extensions visible)
Rename the files to .zip files
Extract core.jar to whatever folder
Extract project name.jar into the same folder (make sure you don't do it into a subfolder)
Click yes if it asks if it wants you to replace a file (if it doesn't you extracted the files incorrectly)
Delete core.jar and project name.jar
If the project uses images, move them into the same folder as all the other files
Select all of the files in the folder, right click, hover over send to and select compressed (zipped) folder
Rename the .zip file to name of project.jar
This might be old, but i still find other posts about it on processing forums.
This is the best way to run processing project as a jar file.
When exporting application, you will always end up with a lib folder inside exported application(whether for Linux and Windows). For windows, open command prompt(or power shell), you can use right-click+shift and then click on open power shell here.
After that you can run the following command.
java -classpath lib\* DisplayDepthStream
Now DisplayDepthStream is the name of sketch file.
To explain the command, -classpath lib\* tells java to add everything under lib directory to the class path. And DisplayDepthStream is the name of my main class.
Hope this helps~!
Chears

BlueJ Importing custom class library

Ok the deal is, I've made a small class library (*.Jar file) to help make a more visually organized code and to help with some common tasks.
Before you tell me to go to: Tools > Preferences > Libraries.
I have done that, over and over and over again.. I also tried to manually add it to: C:\Program Files\BlueJ\lib\userlib\"jar file here"
And yes, i did restart BlueJ to load the newly added libraries.
No matter what i seem to try it won't let me import it to my project using the import command, but without it, it just won't compile.
I know i can just add the classes manually, but as the class library slowly grow, so does the effort of adding all the classes in that library.
In advance, thanks for your help and consideration.
If adding your jar file in the Preferences > Libraries tab doesn't work, you can try adding the jar to the "userlib" directory at <bluej-dir>/lib/userlib (where <bluej-dir> is the folder where BlueJ was installed).
A third option you can try is adding your jar file directly to a project by creating a +libs directory inside your project directory and copying the jar to that directory. This has the drawback that you have to manually copy the jar to each project +libs subfolder that needs your library. On the plus side, it allows you to distribute your project (library jars included) just by zipping up the root project directory.
On Windows I create directory named "+libs" on my blueJ project directory,
then add .jar to that directory, and restart blueJ ,
that´s help me, and import after that work fine
Despite the post's oldness for who stumble upon i can say with the newest version of BlueJ (actually 4.1.3) in an old Ubuntu distro(Lucid Lynx aka 10.04LTS) all work as intended per default without any hack

Managing Source and Class Files in Java

I'm relatively new to Java and programming in general, so my question may seem obvious, but I am trying to learn.
To make it short, there are .class files in my source folder.
I work in Eclipse and I'm not sure how they got there. I've always had the output directory in a bin folder rather than the src folder. Based on Windows, those .class files haven't been changed in over a month.
Would anyone suggest removing them to make the work space a little bit neater?
Thanks.
Yes, you can always remove the .class files - Eclipse will just remake them at the right time.
To change where they are stored, right-mouse on your project in the Package Explorer and select Build Path > Configure Build Path. Click on the "Source" tab. The output folder is listed at the bottom of the tab.

Eclipse error with archived java projects "editor does not contain main type" [duplicate]

This question already has answers here:
Error: Selection does not contain a main type
(24 answers)
Closed 8 years ago.
I am receiving the errors: Editor does not contain main type, or, Selection does not contain main type when I import an archived Java project into Eclipse and try to run it. I have gotten this error on several different operating systems.
Archive Protocol
Export project
General->Archive File
All are selected: project folder, .classpath and .project
[x] save in zip format
[x] create directory structure for files
[x] compress contents of file
A Work Around That May Explain It... but how?!
I notice that when I import an archived project into an existing project (a blank Java project), The folder hierarchy is something like:
Project
src
bin
imported_project
bin
src
actual_code.java
Now, when I try to run actual_code.java, I get the above error. I discovered the following work around: if I drag actual_code.java and drop it into Project->src and then run it, it works.
This is a nice work around. However, I would prefer to be able to run the imported project without moving things around. Any suggestions on how to do this? It seems like it should be a trivial fix--it simply seems like the project isn't importing to where it ought to.
And yes...
I have tried every method I have come across to remedy this. That includes quite a few from this site and others: syntax, libraries, source path, restart eclipse, rearchive, different operating systems, different machines... etc.
The .java files are in the src folder before I archive them, and my build path seems correct.
You could import the archive as a Project instead of as files into a newly created blank project. Use Import > Existing Projects into Workspace. Then, use Select archive file.
You might want to put the src folder of your imported_project in classpath.
Right click on your project -> Properties -> Java Build Path -> Source -> Add Folder
I also faced the same error ajnd after reading above article i just drag/drop my class-file to src and new class-file generated in src is working fine .
I had the same problem after I New/Java Project then pulling src, docs, lib, examples, ... folders. I could not import it as an Eclipse project since the code is not an Eclipse project. The main is right there in the example code, but the IDE would find it.
The solution for me is deleting the project from the IDE, then recreating it with the Eclipse IDE. When recreating, the IDE cached all the sub-folders for me. Also, make sure you add the code onto the Java Build Path as Source using the 'Configure Build Path...' of the project.
Restarting IDE, closing then reopening the file didn't help me.

NetBeans Cant find rt.jar when building

I have a simple Java project in NetBeans7.2, and when I try to Clean/Build it fails:
Building jar: D:\MEUS PROJETOS\_Workspace\JavaWorkspace\Mina\dist\Mina.jar
To run this application from the command line without Ant, try:
java -jar "D:\MEUS PROJETOS\_Workspace\JavaWorkspace\Mina\dist\Mina.jar"
Realizando o ofuscamento do código
Obfuscating dist/Mina.jar...
Created dir: D:\MEUS PROJETOS\_Workspace\JavaWorkspace\Mina\build\obfuscated
ProGuard, version 4.8
Reading program jar [D:\MEUS PROJETOS\_Workspace\JavaWorkspace\Mina\dist\Mina.jar]
Reading library jar [C:\Program Files\Java\jdk1.7.0\jre\lib\ext\jna.jar]
Reading library jar [C:\Program Files\Java\jdk1.7.0\jre\lib\ext\mysql-connector-java-5.1.21-bin.jar]
Reading library jar [C:\Program Files\Java\jre7\lib\rt.jar]
Reading library jar [C:\Library\Java\Home\lib\rt.jar]
D:\MEUS PROJETOS\_Workspace\JavaWorkspace\Mina\build.xml:28: Can't read [C:\Library\Java\Home\lib\rt.jar] (No such file or directory)
BUILD FAILED (total time: 5 seconds)
It's odd because I don't have that [C:\Library\Java\Home\lib\rt.jar] called in my project's library (there is no "C:\Library" in my computer at all)!
Also, why "rt.jar" is called again, if it's already called from "C:\Program Files\Java\jre7\lib\rt.jar"?
I have absolutely no idea where this came from, nor where I can change it (because it is not in my project's library list).
Thanks in advance! Forgive my bad english...
EDITED:
I just figured out that this issue doesn't happen when the application is compiled (build), but when NetBeans' ProGuard4.8 plugin try to Obfuscate!
I suppose that by "simple Java project" you mean the "Java application" project from "Java" category in NetBeans "New Project..." action from "File" menu.
Netbeans default build system is Ant. Ant is the program that compiles, packs and runs the source code from your project.
If you can't find the string "C:\Library\Java\Home\lib\rt.jar" anywhere in the project Properties window, the next place to look for are the properties files inside the nb-folder in project root (change from "Projects" to "Files" view) or the build{-impl}.xml files.
When you click on the "Clean and Build" action from the right click on the project icon in the "Projects" view ant reads the build.xml file (which imports the build-impl.xml file), finds the clean and jar targets, calculates all the dependent targets and properties needed to successfully run the aforementioned targets and finnally runs the calculated sequence of targets.
But, if it is a project made through the NetBeans "New project" action, the build.xml and nb-project are automatically generated, and changing the project properties from GUI effectivley changes the parts of build-impl.xml and some other files. In case you hadn't edited the automatically generated files, that is not the place to look for.
The next thing is to consider if it is Netbeans cache issue, see here for it's location, enter that directory and delete its contents (I can't guarantee it will help though).
Interesting thing is that rt.jar is usually in JRE_HOME/lib directory where JRE_HOME is full path to some JRE installation, so that might lead to conslusion that you have an JRE_HOME environment variable set to this (nonexistent) location.
It's all just guesses but something of this should help you. Please feedback.

Categories