NetBeans Cant find rt.jar when building - java

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.

Related

Running .jar File Java 8

I've run .jar files before, but I've encountered a "different" situation, and I'm not sure what to do. I'd appreciate if someone could help me out.
Previously, I programmed with Java 6 and Eclipse Juno exported all my programs to runnable jar files. I'd get a .jar file that I could run by just double clicking on it. The files always looked something like this (note the jar file icon):
Recently, I wrote a program in Java 8 with Eclipse Luna (Release 4.4.0) and exported it to a runnable jar file, and I got something different (note the different file icon):
It no longer runs when I double click it. Instead, my computer uncompresses the jar, as it would a zip file. I tried running it from terminal. I cd'd to the directory and typed
java -jar graph3D.jar
I got the following error message:
Error: Unable to access jarfile graph3D.jar
After uncompressing the jar file, I found a folder named META-INF with the manifest file, MANIFEST.MF in it. It was the only file that seemed to resemble an executable file. Do I have to do something with that?
Could someone explain how I can run the second jar file graph3D.jar? Is it something new with Java 8, or something different about Eclipse Luna, or something else?
(Both programs run fine in Eclipse, by the way)
Thanks for your time and help.
Edit:
Below was the dialog box Eclipse displayed if anyone is interested.
Selecting "Use .jar;.zip" makes the filename "graph3D.jar;.jar;*.zip" .
Selecting "Use .zip" makes the filename "graph3D.jar;*.zip"
Selecting "Cancel" doesn't let you go forward.
You'd have to manually delete the extra file extension.
Somehow when you exported the file, the filters for the file dialog box (*.jar;*.zip) got attached to the filename, which is graph3D.jar;*.jar;*.zip, not graph3D.jar. Java can't find it because it doesn't have the name you supplied. Rename the file and pay close attention next time you export; either you fat-fingered something, or you're triggering a significant bug that needs fixing.
I recommend that you will access the build folder after you've built your project on the IDE under your project folder (in your workspace) and copy both the libraries folder and the .jar and post them wherever you want the program to be "installed", you'll then have an executable jar that should run smoothly without problems, just as I said don't forget the lib folder.
I think there is nothing new in Java 8 related with the running jar, I guess you need to check the the Eclipse export issues, it seems your classes are missing from your second jar file.

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

How to run Java source file with multiple packages using Eclipse

I am a beginner of Java and Eclipse. Now I have a Java plugin and its source file. I want to debug the source file in Eclipse to see how each part of the code runs. I created a new project named first trial, and the structure is like this:
src\analyser: 1.java,2.java,3.java...
GUI: 1.java,2.java,3.java,4.java,5.java...
GUIPanelWindow: 1.java...
main:1.java...
segmentation: 1.java...
tracking: 1.java
There are more than 5 classes in each package. It's based on the third party-Fiji, so at the beginning of each class it shows the syntax like this "import ij.Prefs","import ij.plugin.PlugIn" and so on.I have also added external JAR files into the library, but it also shows the error "The import ij cannot be resolved ". Thus, the result of debug shows that
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at main.LineageTracker.main(LineageTracker.java:320)
I want to know if I can debug a Java source file like this or what other steps I should do? I will appreciate your help.
Following up on PM 77-1's comment, assuming ij is in one or more JAR files, here's how to add those JAR files to your Build Path (tested on Eclipse Kepler, the most recent version):
Right-click on your project (first trial) in the Package Explorer.
Select the Build Path submenu.
Choose Add External Archives.
In the resulting JAR selection dialog, choose the JAR files for ij. You can select more than one file.
Hit OK.
The JARs you selected will appear in the Package Explorer, below src, under Referenced Libraries.
Build and hopefully it will work!

Java application will run from CMD and Eclipse but not double click

I've done a search and I can see that a lot of people have had the same problem as me, but none of the solutions have worked for me.
Basically I have a Java Project in Eclipse that is from my old Windows Installation. I've cleaned and rebuilt it because at first it wouldn't compile, but now I have it exported as a Runnable Jar. However, the only way I can get the application to appear is to do java -jar foo.jar in command prompt, or run it in Eclipse. If I double click the JAR in Windows Explorer nothing happens even though I know that Java is associated correctly because other Runnable Jars work.
The project only has the x86 JRE listed in it's Build Path Libraries and all the files listed appear to exist. I'm running Windows 7 HP.
Update: I'm sorry, but I just discovered that no other Runnable Jars are working either. If they are wrapped with launch4j they work though...
Edit: The Runnable Jars that I export from Eclipse do work fine on other systems and load on double click
Some registry values or file associations are probably messed up. Wiping off all of your existing JRE's and JDK's and re-installing them should fix your issue.
Alternatively you may be able to fix it by manually editing the registry value here:
HKLM > SOFTWARE > Classes > jarfile > shell > open > command
My value is
Type: REG_SZ
Data: "C:\Program Files\Java\jre8\bin\javaw.exe" -jar "%1" %*
You'd of course want that path to point to your javaw.exe, and make sure you have the additional arguments.
I was also facing the same problem while i was working with Spring tool suite.
You may use the following steps:-
Right click on project -> export -> Runnable jar file -> (Here,In library handling,there are three options,you have to choose middle one i.e package required library into generated jar.It will package external dependency also).
-In my case, my runnable jar was only executing on my environment i.e on which i have created that JAR. Initially i have selected the first option to create JAR i.e extract required libraries into required JAR.but that was not proper.
It may help you.Let me correct if i am getting wrong.
Since you are able to run the JAR running the command line, I believe your issue is related to which version of Java is set to run the file when it is double-clicked.
To find out which version is successfully running the file from the command line and set it to open JAR files by default:
Open a new command prompt window.
Run echo %path%. Among the path values, you should be able to find one pointing to the bin folder of one of the installed versions of Java. Copy this path somewhere.
Navigate to the JAR file you would like to run. Right click the JAR -> Open with -> Choose default program... -> Browse...
Browse to the path you copied in step 2. (the easiest way is to paste it into the address bar)
Double click javaw.exe.
Click OK.
You should now be able to run the JAR file. Please let me know if your problem persists.
I have made a jar with and keep it on desktop.Then,I double clicked on the jar and it working fine for me.
How I and what I have monintored: In my main class, perform some operation and at the end I add on Thread.sleep(25000); to hold the program for few moments. After every double click on the exported jar I found one new javaw.exe process added in the system process tree. I have noticed it on Task manager. and after 25000ms respective javaw.exe process ended. As my application does not cointain any GUI that's why I have not seen any GUI changes for the respective process. I'm Confident that if my application have some GUI, I will surely get the respective GUI window on every run.
Common mistakes : when we export a project from Eclipse as Runnable JAR file, it is exported with selected Eclipse launch configuration and Eclipse specific launch wrappers. Now if the configuration does not match when you are trying to run it via double-click you will not be able to see the error, If you run it from CMD then surely you will get the error log.
To create standard executable JAR file : To create a standard executable JAR file, you can export as JAR file and specify the main class in last screen of the wizard.
That's working for me fine. I used the same jar from different system and keeping it different location.

Eclipse edit java files and run under original folder

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.

Categories