I want to show configuration page if its run for the first time else its show other pages. How can I implement in my netbeans project?
There are several ways to do this, but this might be the easiest:
Save your configuration at the applications startup to a persistent storage. You could use a database (e.g. h2), a file (e.g. txt/ini/config, XML, YAML, ...) or even the users registry with the Java Persistence API.
After that, on every startup the application loads that configuration and displays the appropriate configuration menu when either all or some information cannot be found.
That way you can also ensure that there is always a valid configuration in case it gets lost for whatever reason.
Related
I have a problem ."This is just a configuration which I would like to manage during runtime. I don't want to redeploy whole app to update configuration".I am reading some values from the property files.How can i acheive this?
There are lots of possible solutions, depending on the exact need (and this like possibility to reload these properties on demand etc.).
The simplest one seems to be this one:
Create a bean that internally has a cache defined (like Guava Cache)
Set certain TTL for the cache contents (this will cause your properties to be reloaded every TTL seconds)
Provide a way to populate the cache
Optionally provide a way to force refresh of cache contents
As for the last point I cannot give you a way to do this because I know nothing of your project, but there are at least few good options here depending on the project you are working on.
Assuming your file is not part of deployable (WAR/EAR/JAR), you can watch for directory changes and identify whether your file has changed (refer Can I watch for single file change with WatchService (not the whole directory)?). Once you notice the file has changed, you can execute your logic.
Our application is deployed in websphere and uses lots of custom jvm properties.
Right now we are adding the properties one by one through admin console.
This is a pain during development phase.
Because every day after syncing their code, each and every developer needs to find out if a new property has been added/renamed and do those changes in their own console. Else the application wont start.
It also takes a lot of application setup time, while deploying to various testing environments.
Could you help me identify the place where websphere stores these custom properties? We are thinking of writing a code to update that file (?) directly instead of adding one by one through admin console.
Please help.
P.S:- We are not allowed to use jython in our local :(
In the server.xml configuration for that given server, located somewhere like
Dmgr/config/cells/cellName/nodes/nodeName/servers/server1/server.xml
You can inspect the <processDefinitions> element and add a "systemProperties" stanza like:
<systemProperties xmi:id="Property_1460665921900" name="someName" value="someValue" required="false"/>
DO THIS AT YOUR OWN RISK. The "Property_1112223334445" part is fragile, and you need to make sure it has a unique 13-digit number at the end.
Or, you can modify the "genericJvmArguments" tag in the same file, using a format more like -DsomeName=someValue
Finally, if you do have jacl scripting access, there is an article on updating using scripting here.
I am developing a web application to migrate images from CVS to Adobe CQ. There is a requirement to maintain versioning for the images in a database table. The flow is as follows:
Check Out files from CVS -- returns a list of all files checked out, but does not tell whether a file was updated or newly added to CVS! (Due to the files being binary file, it seems it is not able to detect updates and all files are treated as additions)
Check if this is application's first run, if yes, then treat all files as additions. If not, for every file, check database for presence of record corresponding to this file. If record present, treat as update, else insert
... Carry on with other operations
For every insert, add an entry in the database
I have to detect if the application is running for the first time, or has been run previously. This also needs to support future tasks such as resetting everything and starting the application from scratch.
What would be a good way to do this? The application is hosted in WebSphere in Linux. I have thought of two ways:
a. creating an entry in a file with a flag set to true, which I will have to reset to false after the first run - difficult for a user to reset later
b. creating a .firstrun or similar file in the app folder somewhere and check presence of this file to determine first run, easier to reset for any user
Which of this is a better way? Or is there any other way to do it better?
You mentioned database. Why not to store in db, in even more extended way: when what version, # of runs, etc.
I have a program that I want to distribute, without giving the source code or database used. It's an sqlite database, and doesn't need to be updated. I tried using eclipse fatjar and changing where to look for the jar, but when I run the program, it just creates a blank database file in the same directory as the jar. I just want one file that I can distribute.
From comments deemed relevant:
..include an XML after tested with a TXT file.
I would, but this database is 80,000 lines long, and has 4 columns. It's only going to get bigger too, with updates to the program, not during runtime.
Put it on a server and have a web interface.
I want to avoid using any internet connection really. If someone wants to decompile the jar, whatever I don't care. I just want it to work from double click, and no extra files laying around.
(deployment) ..usability and neatness is important for me
That makes me think that what is really needed for this is a cross-platform installer. The user gets one file and double clicks it, 'follows the prompts' (if any prompts are required) & it extracts the app. ready for use.
It might create multiple files, but this will be largely invisible to the end user. 'Out of site is out of mind'.
I want to avoid using any internet connection..
I recommend you rethink that. What size does the app. come to when Jar'd? A couple of megabytes? That is nothing in this day and age of internet traffic. That's a 2 minute YouTube.
The ratio of devices having internet connections to machines having (for example) CD/DVD drives to load software is also changing. It is coming to a time when more machines capable of running J2SE have internet connections than have drives. I have a desktop PC and a Netbook that can both run J2SE. Both have an internet connection, but only the desktop PC has CD/DVD drives.
If that is the case (getting to my point) look to Java Web Start to deploy the app. and DB. Very user friendly, with good desktop integration.
it's about 50mb, but the problem is not all end users will have access to internet at all times. Distributing the application can be done through the internet, but I don't want to rely on it for accessing the database or loading the application all together.
That is not necessary. JWS caches the application resources locally. It will check the server for updated Jars, but can be configured to allow launch from the cached copy even if there is no internet connection at that moment. The launch file element to configure that would look something like:
<update check="always" policy="prompt-run">
Don't know whether you can do this with a SQLite database, but Derby supports jar: paths: http://db.apache.org/derby/docs/dev/devguide/cdevdvlp17453.html
Alternatively, extract the database from the jar to the filesystem upon launch and point there.
I think you can do the following:
Package your database on the classpath.
When the app loads, copy the database to some temporary directory (like /tmp)
Instruct sqlite to read it from there (by setting the jdbc url)
Add a jvm hook to delete the file when the app gets closed.
That should work like a charm.
Hint:
Use getClass().getResourceAsStream(); to get the reference of the file on the classpath.
I have been using IntelliJ for a while now and I'm enjoying its suite of features but I'm having a hard time getting the run configurations to work for a java applet. I have a pre-existing Java tool that uses Swing and I'm using the JApplet class to load those GUI objects as an applet. The problem is I have a couple configuration files that I need loaded. I load these from the working directory and from my knowledge, this working directory would normally be the directory in which the applet resides. I think the major problem is IDEA sets the startup variable:
-Didea.launcher.bin.path=IDEA_BIN_DIR
I would like to be able to change this but I am seemingly unable to. I have tried overriding this flag by editing the applets run configuration VM parameters, but IDEA will continue putting the above one in even if I specify something different.
So in short, I'm having a hard time loading a local configuration file because I can't set the working directory for the run configuration in IDEA. Does anyone know how to get around this or know of a better way of running Java applets that use configuration files, in IDEA?
An applet normally runs in a sandbox in a browser, and such an applet can't access the local computer's file system, for security reasons.
Thus it is generally a bad idea to load configuration files from the file system, and "working directory" is not a useful term for an applet.
If these files change seldom (i.e. in principle only by the developer), you can put them to the applet's class files (i.e. in the jar file, or during development in the directory where the classes will be generated), and use class.getResource() or .getResourceAsStream() to load them.
If the configuration files should be definable by the webmaster, put them on the webserver - either at some fixed location relative to getCodeBase() or .getDocumentBase(), or specify them as parameters to your applet tag in the HTML tag.
If these are user specific configuration files (which the applet should be able to write), you either need to store them on the server and retrieve/store after a login (i.e. you need some logic at the server side), or you would store them at the client side.
The current way to do this would be using the JNLP API (in javax.jnlp.*) - there are some interfaces allowing Persistence, or loading/storing data (with the user having a FileChooser). Alternatively, you could sign your applet and request an AllPermission from the user - then you can access the file system.
Sorry, nothing of these answers your original question (I don't use IDEA), but maybe these help you to find another way.