Opening a .jar in Ubuntu - java

While making a game, i moved from programming in windows to ubuntu for better usability. that aside, when in windows, using Desktop d = Desktop.getDesktop(); and using d.open(new File("file dir.jar"); and it worked in windows. but, when using ubuntu, it opens the jar in an archive manager. so my question is, how would i open the .jar to be executed? Any help would be great! thanks in advance!
Edit: it may be possible i installed java wrong... but i did it the way i found on google. if that is the case, any correction would be great :D

I see two ways:
1) add the jar you want to run to the program classpath and run it's main method.
2) using Runtime.exec() you can run anything you want, but you may lose platform independence

The archive manager is set as the default program to open .jar files. You will have to change it in Ubuntu's settings for default programs. You can right-click on the file you want to open and select to open it with your installed Java runtime environment, in the meantime.

Related

Navigating the file system with netbeans is VERY slow

Since a few days, navigating the file system with Netbeans is VERY slow (more than two minutes to access a file, and if you have to navigate a file system, it is true every time. I have exactly the same problem after clearing the cache, and with Netbeans 8.2 and Netbeans 12 (Netbeans 8 with Java 8, and Netbeans 12 with Java 17 in my tests).
Strangely I don't have the same problem with regular Java file choosers which I use in my projects. For example, if I click on "Open Project", the IDE is frozen for sometimes 2 or 3 minutes before I can see the file navigator.
When I am looking in the task manager while trying to open a project for example, it appear that Network usage is very low (1% to 0%), CPU also very low (less than 2%)
I am talking about Netbeans itself, for example if I want to open an existing project, or adding a jar file to the list of Jar libraries for an existing project
The standard Swing JFileChooser works correctly. With this example code the navigation is immediate (as expected):
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(JFileChooser.OPEN_DIALOG);
chooser.setDialogTitle("Test FileChooser");
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int ret = chooser.showOpenDialog(null);
if (ret == JFileChooser.APPROVE_OPTION{
System.out.println(chooser.getSelectedFile().getAbsolutePath());
}
I am on Windows, on my workplace network (I am working on local files on my PC, but there are two remote drives which are accessible on the network). I only have problems with Netbeans, other apps have no problem with the file system.
My problem is with Netbeans itself navigating the file system (for example opening an existing project, or adding a jar file as a library for a project)
This looks to behave exactly as this bug: https://bz.apache.org/netbeans/show_bug.cgi?id=42079, except that it does not happen with the Swing JFileChooser as shown above.
Is it a known problem, and if it is, is there a mean to fix it? I was thinking for example about a setting on the command line used to start Netbeans.
There is a bug in netbeans with links from the desktop, that behaves like you described. Try to remove all links from the desktop and default location for the open file dialog.
issues.apache.org/jira/browse/NETBEANS-1537
It was a BROKEN PATH in a link on the desktop in Windows 10, in my case.
NetBeans 12.5 -> Creating a new project dialog, than "Browse" to choose appropriate directory took a very long time. I tried to test links on my desktop. I found one old "broken link". Broken in terms - it pointed out to non existent path. I corrected this path in this link and... voilĂ , magically NetBeans is working correctly.
Ok -- this is crazy -- but after trying everything listed, here is what finally worked for me.
I created a Batch file on the desktop to point to the netbeans64.exe app. the secret for me was to NOT do a cd to the netbeans location.. but to call the app in using the full path. Here is what my batch file looks like
"C:\Program Files\NetBeans-15\netbeans\bin\netbeans64.exe"
I know it seems way too easy.. but it works for me. As Sam Snead said about the latest golf gear back in the 60's "I ain't no scientist. just a believer.." LOL!!!
I had the same problem. As they wrote here, it is necessary to check the links on the desktop. Removing bad links helped me.
I had the same issue on Windows, thanks to you guys I solved it by removing the symbolic links (shortcuts) from the desktop, but not from any desktop, I mean that this method didn't work for me when I removed them from the user desktop "C:\Users\user\Desktop", it only worked when I removed them from the public desktop, which is located at "C:\Users\Public\Desktop".
I hope this clarification helps and sorry I don't have enough reputation here on StackOverflow to comment, so I had to post this as an answer....
I find that this happens when I run Netbeans without administrator rights.
With admin rights it works fine.
Had this issue with Netbeans 15. Resolved it by removing a broken shortcut from my desktop.

Regarding executable jar file

I have developed an application and mostly it is a Swing based application. I have made the executable JAR of the whole project. Now when I click that JAR it gets executed and my project starts and the Swing window shows up as usual. But when I try to execute that same executable JAR on another system it doesn't get executed. Please advise how to solve this..!!
The reason that might be that the JRE may also not be installed on his system or the class path was not set..! Please advise how to execute the same JAR on his system too.
Are you working with eclipse? Maybe the other system doesn't have the JRE7. If this is the case, you have following possibilities:
Update the JRE on the other system
Create a new project in eclipse and select JavaSE-1.6 at "Use an execution environment JRE"
This compiles your project JRE6 compatible. However, you have to put more details to your question.
Have a look to:
http://launch4j.sourceforge.net
http://jsmooth.sourceforge.net
these wraps your jar into an executable,which makes easier to distribute your app,taking care of things as setting the classpath and installing the JVM if not present.
Your questions is missing some details.
Please, specify output that you get when running your application on your friend's machine.
Otherwise it is hard to advice something.
More details are also welcome: jdk/jre version, OS version, build scripts, etc.

Netbeans 7.2 won't open on OS X

I installed Netbeans on OSX Mountain Lion running JDK 7. Everything was working fine. Then my machine for no reason crashed. After this I could no longer open Netbeans anymore.
If I try to start Netbeans from the commandline:
/Applications/NetBeans/NetBeans 7.2.app/Contents/MacOS/netbeans
Then it works fine. From there I can select Netbeans > About and confirm that my userdir and cachedir is:
User directory: /Users/<user>/Library/Application Support/NetBeans/7.2
Cache directory: /Users/<user>/Library/Caches/NetBeans/7.2
So, I deleted these directories and tried again, but alas, I can only start netbeans via the commandline.
Ideas appreciated...
Sounds to me like this is not a NetBeans problem at all, rather a problem with the bundle, such that OS X is not launching the app as it should.
To verify, I'd try opening NetBeans through Finder from the command line:
open -a "NetBeans 7.2.app"
This command will ask the system launcher to open the application as if you had clicked on the icon. In your case, it probably won't open. If this is true, then you know it's not something in your terminal environment that's allowing NetBeans to launch.
The next step that I would take would be to look at the package contents: examine /Applications/NetBeans/NetBeans 7.2.app/Contents/Info.plist for anything that seems amiss - this file is the information store that OS X looks for to see how to launch the package, what its icon is, etc... - in particular, I think you should look at the CFBundleExecutable value to see what command is used to launch the app. If it's not netbeans, you've found a big hint on what might be amiss: bundles are set up so that launchers should run bundle_dir.app/Contents/{platform}/{CFBundleExecutable_value}. Looking at CFBundleExecutable should show you if there's some other script used to launch the app than just running netbeans.
From this point, you'll have to do more digging, but hopefully this is enough information for you to get started tracking down how apps are launched from the OS X launcher. For more info and a better reference, check out this link, which is Apple's documentation for keys in Info.plist.
Finally, you should note that the launch information for all apps are heavily cached; I've heard that if you make a change to Info.plist, you have to rename the app bundle and name it back to have the changes picked up by the launcher.
Good luck!
Here's an idea: use Eclipse >=)
..but seriously, something got corrupted in Netbeans' metadata/cache data files. You cleared a couple of them but there may be others elsewhere.
Try comparing the launch command in your shortcut to what you're typing in the console. Are they the same?
To find the root cause, I would check the NetBeans logs, as detailed here
/Users/yourname/Library/Application Support/NetBeans/7.2/var/log/messages.log
And if that doesn't help, I'd archive your project(s) and put a clean install of NetBeans on your machine, and then import the archived project(s) back into NetBeans.

Make an executeble JAR run in a console when double clicked

I'm in the process of porting simple console apps written in C++ to Java in order to show how similar the languages are, and how code can be ported. I've exported executable JARs for the programs using Eclipse. These JARs work fine when they are run using the java -jar command. However, they do not run properly when executed from windows explorer (double clicked). A console window simply opens and closes rapidly.
The only solution I have found thus far is to use a batch file. Is there any other option?
There are some options:
Sleep a bit when the program is done, so you can read the output.
Call System.in.read() (again at the end of the program), which will wait until you type a char and hits enter.
Create your own little swing terminal, which doesn't close when the application code is done.
This seems like the jre used from the command line and from the registry are not the same (this can occur when multiple JRE's are installed)
Have you checked in your windows registry what is the jre used to run the executable jars ?
You can find more on the registry settings on sun's site
Seems to me that your main class does not even gets executed.
This would explain the quick open/close of console window.
Or is it possible that another program than java has the "jar" file type?
Happened to me after installing a Nokia software.
Using a batch file seems to be my best option. I suppose that's why Eclipse has a launcher.
Change the open with program to
c:\Program files\java\jre7\bin\javaw.exe

JVM: could not open

Error - JVM - BlackBerry 9800
Simulator
--------------------------------------- JVM: could not open
C:\Users\Bayron.Tellez\Downloads\eclipse-java-helios-win32\eclipse\plugins\net.rim.ejde.componentpack6.0.0_6.0.0.29\components\simulator\Java\net_rim_bis_lib.cod
My friend installed Eclipse with the Blackberry simulator. I'm assuming it was a portable installation because at no point we were prompted to install.
Now, he zipped it up and copied it to my machine when running I receive that error above. Obviously it's because it's trying to look for something on my friends directory. How can I change it to my path?
My path is:
C:\Eclipse\eclipse\plugins\net.rim.ejde.componentpack6.0.0_6.0.0.29\components\simulator\Java\net_rim_bis_lib.cod
Where do I change this?
I would suggest not running eclipse from a copy of someone else's installation. This will probably contain lots of installation-specific files which are unlikely to match your machine.
Why not install it yourself, then install the Blackberry Java Developer plugin? It's available at http://na.blackberry.com/eng/developers/javaappdev/devtools.jsp
You can change the early installed paths of all .cod files from xml.manifest
[Eclipse Installed Path]\plugins\net.rim.ejde.componentpack7.1.0\components\simulator\[BlackBerry simulator version].xml.manifest
Eg:
C:\Program Files\Eclipse\plugins\net.rim.ejde.componentpack6.0.0_6.0.0.30\components\simulator\9800.xml.manifest
Then remove the [BlackBerry simulator version].xml.manifest.bin file.
Now it should be work.
You may also want to check file Settings.rc,
found in the folder
PATH\plugins\net.rim.ejde.componentpack4.6.1_4.6.1.49\components\bin
first you have a path to your eclipse installation, and then corresponding Simulator you are trying to run.
hope this helps,
Use notepad++ to replace all occurrances of old directory into new directory in the eclipse directory.
Start the eclipse, and click clean simulator button.
That should be all.
Though it is not advisable to run a copy of eclipse, there is a very simple way for one to solve such a problem: it is by running the clean.bat file that is in the simulator folder of the specific component pack version folder. The path to that file would look like this: PATH\plugins\net.rim.ejde.componentpack[BlackBerry version]\components\simulator\clean.bat
I think that would do.
Still, installing a new version is the best option.
It will be better you install it yourself frsh rather than copying it from friends machine.
But you can give it a try.
Goto your eclipse\plugins\net.rim.ejde.componentpack6.0.0_6.0.0.29 directory and check do on of these files contain this path:
plugin.properties
plugin.xml
META-INF/eclipse.inf
.options
Or else you could grep for problem path in your plugin directory and replace same with updated path.
This error occurse cause your simulator have previously loadded application. Removing them solve your problem.
How to remove installed Java programs on the simulator?
Quote from Reset and clean the blackberry simulator:
Are you sick of having a million icons on your BlackBerry simulator for every HelloWorld and demo project you have every tested? Try this to remove old programs from the simulator and start with a clean ribbon. From the command line browser to your rim jde directory, switch to the simulator sub directory and run clean.bat. This program takes longer than you would expect (about 30 seconds or so on my 3 ghz machine).
UPDATE
Also delete all [app name].cod|cso|debug|jar files from simulator folder Also make sure projects you don't want on simulator are not active and are not in build configuration.

Categories

Resources