Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want add a file into the jar package but this is a separate file from the java program, can I run it and if I can run it, how can I run it? Can you recomment anything?
Thanks.
Not possible; java doesn't run arbitrary executables; your OS does. Java ask your OS to run an executable, but OSes generally do not have the ability to run executables from within zip files. Let alone jmod files.
If your java application can read and process the data itself (example: Render a swing JLabel object with some PNG as its image), then you can to this:
YourClass.class.getResource("open_url.png")
Will get you an inputstream for the stated file, as long as that file is in the same place that YourClass.class is - even if it is in a jar file or jmod file.
However, if you have an .exe, you'd have to extract the executable, save it to a tmp dir, and then ask the OS to run that file. Saving executables to temp dirs is a little tricky (if it's a global temp dir, some other user could overwrite your executable in the middle, and thus run its code in your process, you see how that's security-wise quite a big issue). But, you can do it. Note that this makes your app not platform independent anymore, of course.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 months ago.
Improve this question
I have found a Java application repository on GitHub which provides the application in JAR format and in the native binary format for different operating systems such as MacOS, Windows, Linux.
I am able to execute the JAR file using the java -jar command but I would like to run the native binary file so users can execute it without installing the Java in their system.
Can someone please inform me how can I run the binary file on Macos? I tried to search and found the command chmod +x name-of-binary but this command does not do anything.
I am really new to this and do not have much idea about this so any suggestion would be really helpful.
The most simple way would be to either open a terminal and manually running the binary, like so:
./<name-of-file>
This would only work if you are running the file in a user who has execution privileges on that file. if you run into trouble with priviliges, that's where I would use chmod.
If you need any more specific help, I would recommend posting the link to that GitHub repo for us to look at, and telling us what is it that it should do.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have recently developed a school management system in java netbeans using derby(java built in database).Now i want to make a jar file and proivide it to my client .So can this jar run on client pc without netbeans or java installed? and what about database?
You can create a jar of your source code using netbeans using How to create a Jar file in Netbeans
You cannot package the derby or what ever database into a jar. Instead you can have script to start the db.
Java must be installed with at least the version of java you used. Embedded databases need no extra installation other than in your code.
Starting from a jar is a bit different than in the IDE from a class path. A jar contains only read-only resources, and the file names in the jar (zip archive) are case-sensitive.
It could be that the software first has to use a resource file as initial template to be copied to the file system. Like a prefilled database to be written to.
Java 9 can use jlink to create your own smaller JRE, java run time. (I do not think you are using java 9 though.)
Java 8 has a javapackager.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I wrote a Java program in Eclipse that uses Processing IDE libraries, and it works just fine. This program gets some data from a .csv file and assign those values to the variables inside the program.
I want to make this program run multiple times automatically and sequentially, and before each run I want to modify some of the data from the .csv file so that I can get different outputs at each time.
I've been thinking about this for a long time and couldn't come up with any answer myself. Any help will be appreciated.
Thanks,
Mert
One of the simplest way of I can think of is creating infinite for loop, but this is only on the assumption that your question is based on some sort of assignment,
for(;;){
// read the folder path
File folder = new File("your folder path");
if(folder.listFiles().length > 0){
//read files - your csv file
//process files - capture any values
//delete file - delete the file
}
}
Now you can change the csv file manually, put it in this folder, let the program read it and once it is deleted you will understand it is processed and you can add new file/s.
Also it is not clear that how long due to want the program to run, accordingly you have to take care releasing File resources in your program so they are available for garbage collection.
Hope this helps!!
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm creating a specialized IDE in Java and I need to store and use resources associated with the current project being worked on. Should I store my whole project as one file (an archive), or as a system of files? I would prefer to use an archive (duh, one file.), but I'm unfamiliar with the APIs, and I'm not sure how slow that might be. Would it be terribly slower to read images and various other resources from an archive rather that the raw file system?
For example:
User clicks on an image in a jtree
Image is loaded from the file system to an editor
vs
...
Image is loaded from a jar to an editor
If the user is likely to be saving their individual project files, then using a filesystem rather than an archive will be a lot faster since the whole archive doesn't need to be written, only the changed files.
If possible you should only read the files once at the time the project is loaded into the editor, and after that have it all in memory. This is a lot faster than reading from the filesystem all the time.
So in summary, it's not the reading but the writing that would be the bottleneck with an archive.
On the other hand it also depends on how much data we are talking about.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
is there a way to execute a cmd command like "move FolderA FolderB" without creating a .bat file and start it?
It would be nice if it would work without creating files on HDD.
Runtime.getRuntime().exec(new String[]{"cmd.exe","/c","move","dirA/a.txt","dirB"});
Process process = new ProcessBuilder("cmd.exe",
"/c","move","dirA/a.txt","dirB").start();
ProcessBuilder is preferred to Runtime.exec() since Java 1.5, according to JavaDoc.
Be sure to read the Process Javadoc to understand how to read from and write to processes.
Shelling out for commands like move is bad practice, because it's neither portable nor secure. Work with File classes instead. But sometimes you have to shell out to interact with more esoteric external programs.