How do I clear a specific file in the Java cache? - java

I would like to remove a specific cached jar file from a Java program. Java cache behaves weirdly sometimes, and keeps loading an old jar even if a new one should be used.
The "Java Control Panel" has a "Java Cache Viewer" feature that allows us to see cached jar files.
I was wondering if there was a way to detect a cached jar file but directly from a java program, and then remove that file. Is there an API allowing that?

Yes! I've just found a solution to this problem. There's a command line statement "javaws" that let's you handle specific java-related actions. You can type javaws into your console/terminal and it'll give you options but to remove a specific application, you could add this to your code:
Runtime.getRuntime().exec("javaws -uninstall <jnlp file>");
where can be the file or a url.
Hope this helps!

See http://download.oracle.com/javase/1.5.0/docs/guide/plugin/developer_guide/applet_caching.html for ways to control the cache.

Related

How to set a classpath automatically during the installation of an excutable java application?

I am writing down an example of what I was trying to do.
But this is just one example, I am sure there would be many. So I want a generalised answer for this.
I was trying to make a java desktop application which reads the word documents. I realized I need some Apache libraries/APIs that would help me do it.
So I downloaded the library.
But now I need to set the classpath of the files from the library.
I am a developer and I can do it, but imagine giving such instructions of setting a classpath to a complete non-developer user.
I was wondering if when I am over with the making of this java application, I would make it executable (exe) application and when someone installs it, the classpaths are set automatically during the installation and the apache library files are automatically extracted.
How can I do it? Can someone explain me in detail - step-by-step?
Please consider using some development IDE, like (free) eclipse for instance.
Then crate new folder (clled lib for example) in your project, copy the library into it,
then click on your library by the right button and select "add to build path"
As already mentioned - best way to do it is to use Manifest file in your jar. Official documentation: https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

java.lang.NoSuchMethodError in Genexus

I am using GeneXus Evolution 2 for my project. While I was developing, I got the following error:
HTTPステータス 500 -java.lang.NoSuchMethodError:com.genexus.ModelContext.server2webcli(Ljava/util/Date;)Ljava/util/Date;
I don't know what it is and how to solve this. Any ideas?
A NoSuchMethodError usually indicates that a method (declaration) was there when you compiled the code, but the implementation is missing when you're running it. In most cases, the reason for this is that you had one version of the respective library's JAR file on your class path when compiling, and another, incompatible one when running.
A more detailed answer would require a more detailed question...;-)
Supposing you're using Tomcat as servlet container, look at {Tomcat_Home}/webapps/MyApp/WEB-INF/lib, where MyApp is your app name. There will be a gxclassR.jar file that should match with the version of your Genexus installation. To test if you have the right one:
Assure that there is not other similar lib, like gxclassD.jar, in the same folder. If there is, delete it.
Go to the environment target folder where you're working (from the Genexus DE Menu "Tools -> Explore Target Environment Directory") and look for the gxclassR.zip file. Copy to the WEB-INF/lib folder, rename it to gxclassR.jar replacing actual gxclassR.zip file.
Restart tomcat application to assure that the new gxclassR.jar is being used.
If your object keep failing, then the problem may be the .class associated to your genexus object. Maybe isn't correctly generated/compiled. So, to fix this:
Force the building of the genexus object. For this, try the Build with this only option associated to the object. Activate the Force option for this action, accessing to "Tools -> Options -> Build -> Build with this Only"
Once forced the build, go once again to the environment target folder and look for the .class file/s associated to the object. Usually the name of the file/s matches the name of the object. Look the modification date and confirm that is recently.
Copy this .class files to WEB-INF\classes folder inside your webapp folder.
I think this is good enough info to fix your problem. If not, detail your error a little bit more.
It may also be that the method you are calling does not exist, or exists with different parameters, either by quantity or by type.
Check the date and size of the file gxclassR.zip that is on your web folder inside your KB (Tools -> Explore Target Environment Directory), and compare it with the one used by your web application (folder WEB-INF/lib). If they don't match, replace the one in your web application with the one in your KB.
If you are unsure about it, and would rather GX handle it, delete all the .ver files in your web folder and force a build. That should synchronize all the files to the proper version.

Can't update java.security file - want to add bouncy castle provider

I am trying to use 'Bouncy castle' library in JAVA and want to add that jar file(bouncy castle's) to the providers list in the 'java.security file', I'm using windows7 and I have changed the permissions too for the files and folders but yet I'm getting an error "Access to 'complete-path' was denied". Kindly help me in how to deal with this error.
You can only save edits made to a java.security file if the editor you are using is running as an administrator.
Notepad is sadly not good enough for this job, as Notepad only supports files with CR+LF line-endings and java.security uses LF line endings. I normally use Notepad++ for this task, although Notepad2 and various other programmer's editors can be used instead if that's your preference.
Note that you must quit Notepad++ if it is currently running. If Notepad++ is running and you attempt to start another copy of it (as administrator or otherwise), Notepad++ will figure out that it is already running and instead give focus to the already-running copy of Notepad++.
The solution for me was to copy the file somewhere else, update it and paste it back in. There is a security warning that I had to say 'continue' to.

Dependency issues in deploying using Java Webstart

I am working on a project in Java which has a directory structure something like this:
MainFolder
/ | \
Folder1 Folder2 Folder3...
|
Program.jar|Run.sh
In Folder1 I have main jar file along with the shell script to run the program.
In Folder2 I'm having configuration files in xml which may later be modified by the program
and In Folder3 I'm having jar files that the main program depends on.
Now I want to deploy this program using Java web-start.My current understanding is that web start allows us to deploy programs using 1 or more jar files.My problem is that I need the directory structure also.Can anyone suggest a solution for this.
As mentioned by others, the shell script raises problems. What does it do specifically to 'run the program'?
For the configuration files - 'Folder 2', webstart provides the PersistenceService. I have a small demo. (1)
As far as the Jars in 'Folder 3' go. Move them, as well as the Jar's in folders 2 & 1 to a single directory named 'lib'. The main Jar and the configuration files will be required eagerly, which is the default for JWS. If any of the other Jars (ex. '3') might not be needed immediately or at all, they should be deployed as download='lazy'.
To access the local file system - for reading input supplied by the user or writing a new file they created - a JWS app. normally needs to be digitally signed and trusted. But JWS also provides the much more limited form of access through the FileContents object. For more details, see the demo. of the File Service in the page linked below. (1)
1) Demos of the JNLP API, including the PersistenceService & FileContents object.
I think you will have to make some changes to the structure for webstart deployment (possibly package it as a jar or set of jars), also the launching will be done via JNLP, by webstart and not Run.sh.
Additionally you will have to sign your deployment if you need permissions to write to the disk.
See the FAQ for webstart here
Also check out the developer guide on how to deploy using webstart
Java WebStart does not provide any help in making the filsystem as you need it - it only provides the program components for memory.
If you need this structure, you will need to maintain it yourself (and then, where?)
If the only thing you need is a shell script to run, you can keep the contents of that file as a resource inside your jar, create a temporary file at each run, put the desired contents inside, and execute it, and then delete the temporary file when you are done. Note that this brings you into the wonderful world of code signing which is rather tedious.

Hiding specific files in TextMate

I do a lot of JRuby on Rails apps, and we have a fair amount of Java .jar dependencies. These become quite annoying in textmate as it really muddies up my lib directory, and I never (obviously) need to actually open these files.
Can someone tell me how I might hide .jar files from my file listing in Textmate??
You need to modify File Pattern regex in :
TextMate-->Preferences-->Advanced-->FolderReferences
You just have to add |\.(jar) to your regex:
!(/\.(?!htaccess)[^/]*|\.(tmproj|o|pyc)|\.(jar)|/Icon\r|/svn-commit(\.[2-9])?\.tmp)$
Have a look at this.
You can do this for a specific Textmate project too:
Save the project somewhere, for example in myproject.tmproj.
Make sure the project isn't open in Textmate (otherwise Textmate will overwrite your changes when you close the project)
Open up the myproject.tmproj file with a different text editor
Add a pattern for the files you want to ignore to the <string> value on the line immediately following the regexFolderFilter line. In this case you would add |\.jar just before the )$</string>.
Save the file.
Re-open the project in Textmate.
You can also open the .tmproj file in step 3 with Textmate if you use the command line command mate, too.

Categories

Resources