Compile Java Source Files At Runtime In JRE
Feb 14, 2014
I am looking for a way to compile Java Source-Files at runtime and save them all in an executable jar; almost like an IDE would do. I know that there is the javax.tools package which provides a JavaCompiler interface and you can use ToolProvider.getSystemJavaCompiler() to get an instance of a compiler. However, this method has one important problem: it only works on machines that have the JDK installed. Not when only the JRE is installed.
I guess at this point that I need some kind of third party library that offers an implementation of a JavaCompiler. Unfortunately, this is really complicated to search for on the internet since all top listings when searching "compile java at runtime jre" do not really provide a solution to the problem.
I am writing a (somewhat) complex simulation software right now which is supposed to be used by people who have absolutely no knowledge of programming. At the same time, this software should provide the user with a certain amount of flexibility and control over the flow of the simulation.
My previous take on this problem was to build a complex system to interprete user settings from a GUI. I would basically read the GUI input, output it to some kind of own scripting syntax which I just quickly made up and have that interpreted at runtime. Then I realized, that is a silly concept and I threw it out before I got far into the developement.
The much better solution I came up with is taking the input from the GUI, create java source code from it and compile it at run-time. Seems much cleaner and nicer to me; will also probably have a better performance, but thats not really an issue anyways.
View Replies
ADVERTISEMENT
Apr 10, 2014
my course material is due for term 1 of my cert 4 programming course, but My lecture will not pass my java projects because there is no source files generated for them in the net beans project structure, tried building, cleaning and building, all i can think of?, tried IDE's 7.4 and 8.0 .
View Replies
View Related
Oct 10, 2014
I'v tried everything, i'v tried to create new path in enviornment variables i tried adding this path -->(C:Program FilesJavajdk1.8.0_20bin) to the end of the default path doesnt work i uninstalled and reinstalled and did the same thing over and it didnt work am i editing the files wrong ? what i do is write the hello world program in eclipse to make sure there arent any errors then copy and paste in note pad++ save it as a .java file and it doesnt work i tried save it in regular notepad as .java laso and it doesnt work iv done every thing i could possibly find on youtube is this stuff outdated ? is there a new way? this one one of the errors ill get
C:javat>javac helloworld.java
helloworld.java:1: error: '{' exp
public class helloworld.java {
^
And this is the code for that file im trying to compile
public class helloworld.java {
public static void main (String args[]){
System.out.println("hello world");
}
}
View Replies
View Related
May 17, 2014
I am trying to compile multiple jar files into one jar file from inside a java program. I know how to do this with shell scripts but I would rather have a universal application than one that will only run on Mac, Windows, or Linux. This is my current compiler code:
if(System.getProperty() == "Mac OS X"){
Runtime.getRuntime().exec("javac -classpath jar1.jar; jar2.jar");
}
I would then continue this on for Linux and Windows, but this limits my application.
View Replies
View Related
Apr 4, 2014
The first 4 class below are the main classes while the last class is the testing class. I got it all to compile but for whatever reason there are several runtime errors. I have spent hours trying to figure out what they are, but I was only able to eliminate a few.
import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Set;
import java.lang.*;
public class PhoneNetwork {
[Code] .....
View Replies
View Related
Jan 23, 2015
During runtime, I need to load the JAR files and relevant config files( .cfg files and .properties file) into CLASSPATH and run a specific java program from one of the JAR which is available in CLASSPATH.
Any relevant Java API details or a sample java program to implement the above use case.
View Replies
View Related
Apr 3, 2015
In using javac, I have installed the JDK, set the PATH and JAVA_HOME. When I run this:
"C:Program FilesJavajdk1.8.0_40injavac" -cp C:Gj_javacHTMLCarbonResults.java
I get: javac: no source files
Since I placed the source file path in the command line, I don't understand why it can't find the one .java file.
View Replies
View Related
Apr 3, 2014
The problem is what to do when the source file for a class gets too big ( a judgment call for sure). Is it possible for one class to be defined in multiple files and if so how do you do it, and is it good practice?
I do see ways to refactor into a base class or move code into a helper class but sometimes the abstraction is cleaner as a single class that does a lot of stuff. My problem is how to organize a BIG class?
View Replies
View Related
Jan 9, 2014
I compiled a program with a JAR in the classpath. Also ran it with the JAR passed with classpath. For instance I used MySQL .jar.
So I feel it was required in both classpath. I have heard the Servlet API jar is also an example of what is needed at compile time.
View Replies
View Related
Apr 23, 2015
I'm having another issue. I have 2 java source files(see below). They are place in the same directory. How do I compile them using classpath?
I have already tried 1st attempt :
javac -cp com.companyname.interview.DuplicateReplace.java DuplicateReplaceTest.java [did not work!]
2nd attempt: javac -cp DuplicateReplace.java DuplicateReplaceTest.java [again, did not work!]
package com.companyname.interview;
public class DuplicateReplace { /* code */}
[Code] ....
View Replies
View Related
Apr 24, 2015
I'm trying to compile one of my Selenium WebDriver .java files to run from the command line. Since it's just one file, I only need to compile the file into a .class file to run it from the cmd line. I don't need to make a .jar file.
The .java file runs fine inside Eclipse, so now I need to make it run from the windows command line.
I tried compiling it using
javac -classpath C:WDJarFilesselenium-server-standalone-2.42.2.jar TasksCreateAssignments.java
but got this error
TasksCreateAssignments.java:23: error: package org.apache.poi.hssf.usermodel does not exist
how can I can fix that?
View Replies
View Related
Oct 26, 2014
What step to know to develop software..
View Replies
View Related
Jun 17, 2014
I have to build a server application. My issue is that it can never shutdown/restart. But I still need to update it.After some research I learned about OSGI where I can add/remove a bundle of code while the application is running. (update to a new version)Can I use JavaWS to update my OSGI application without having to close and restart it? I'm new to OSGI/JavaWS.
View Replies
View Related
Jul 8, 2014
While executing my application i came across with this unexpected error which i don't know why?
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000007fdcacd79a9, pid=4980, tid=7724
#
# JRE version: Java(TM) SE Runtime Environment (7.0_45-b18) (build 1.7.0_45-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [ntdll.dll+0x79a9]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit: [URL} .....
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
View Replies
View Related
Mar 31, 2015
We are shipping in our company the JRE bundled with the client application in order to ensure the compatibility. But when upgrading from jre6 to jre8 the size increased by 50 MB!
Is there a reliable and secure way to reduce the footprint of the JRE? Are there "light distributions" or a list of libs/files that can be safely removed?
View Replies
View Related
Sep 9, 2014
I want to trace how many wifi signals are available near some source within some distance in JAVA. How do I do that?
View Replies
View Related
Oct 30, 2014
I will detailedly explain my requirement below,. I am going to automate a manual process. I will be reading multiple CSV files from a remote location using java.There are five formats of input files are expected, each differs in their header structure. For example, Type 1 - Number, ID, Name, Phone, Address...Type 2 - Number, GID, Employee Name, Address1, Address2, Phone number and so the other three types are also differs.
The precondition is not all the files are expected for a particular run. I need to read these files one by one, validate it, log the validation error and i have to consolidate all the correct data from all the files together in a standard output format, in a single file The standard output format will be like,Number, Name, ID, Address
I need to have the above data alone in the output file and rest of the data can be ignored.What i have tried is as follows, I have created 5 bean classes representing each type's header. I just read an input, identify its type and parsed it. I parsed line by line.
public String[] parseCSV(String inputLine){
try {
String[] fields;
Pattern p =
Pattern.compile(",(?=([^"]*"[^"]*")*(?![^"]*"))");
fields = p.split(inputLine);
/*for ( int i = 0; i < fields.length; i++ ) {
System.out.println(fields[i]);
}*/
[code]...
I have validated as per the validation rules and i appended each line elements into an object. I have added all the objects in to a MAP collection. Likewise, i have created 5 beans and did the same.But, what is the change needed now is,. All the headers in all the five types of rosters are configurable items. hence, i have to change my bean classes everytime when the header structures are changed.
We have to create one single utility, which is configurable for all the five types of input files. To be very clear, if type 1 input comes with 8 columns and type 3 comes with 12 columns, the utility is able to parse it.
We are going to have a table which has the data regarding the header structure of all the five types of inputs alone. Once i read a file and identify its type, i will hit the database and read the header structure of that particular type and its column count. I will match the column count with the input file's header count and i will have to proceed creating a bean class on runtime depending upon the header structure read now. I will validate and consolidate as i did above. The requirement is, Runtime configuration of bean class, depending upon the type of input.
View Replies
View Related
Aug 2, 2014
i have a run time error that could not find or load the main file java .
View Replies
View Related
Mar 13, 2015
I was having trouble running some Java programs (not my own) in Windows XP, and in the process I uninstalled and installed JRE versions 6, 7, and 8, one at a time, probably in the order 7, 8, 7, 6, 7. The program that had the original problem only worked in V6, but some other programs stopped working. I went back to V7, and those other programs still didn't work. The message was "the registry refers to a nonexistent java runtime environment installation". The only advice I could find with Web searches was to reinstall the JRE. Needless to say, that didn't work.
So I looked at the registry, and I found that there were still references to V8, which had been uninstalled. The first was
HKEY_CLASSES_ROOTjarfileshellopencommand - (Default) = "C:Program FilesJavajre1.8.0_31binjavaw.exe" -jar "%1" %*
The folder re1.8.0_31 doesn't exist, so I changed it to jre7. That didn't work.
Then I found
HKEY_LOCAL_MACHINESOFTWAREJavaSoftJava Runtime Environment - CurrentVersion = 1.8
I changed this to 1.7, and deleted some following entries such as
HKEY_LOCAL_MACHINESOFTWAREJavaSoftJava Runtime Environment1.8 - JavaHome = C:Program FilesJavajre1.8.0_31
retaining entries such as
HKEY_LOCAL_MACHINESOFTWAREJavaSoftJava Runtime Environment1.7 - JavaHome = C:Program FilesJavajre7
That worked!
So, there is a bug in the installer(s): if you uninstall V8 and install V7, the 'CurrentVersion' isn't set correctly, with the result that the registry points to a non-existent folder. The V8 uninstallation should delete these entries, or the V7 installation should change them.
View Replies
View Related
Oct 7, 2014
Lately I've been working with JDBC and writing queries in some Java programs. I've noticed that I keep experimenting with where I place my blocks of querying code. I've tried creating a private method in the class where the query is used, I've created utility classes where I can call the query when needed, and sometimes I've just put it in a localized block of code where I need to. Also, most often these queries are one-shot queries where I need to pull the data to populate a JTable.
In short, this has made me realize that I don't have a solid practice for organizing my queries in Java. So my question is "Is there a practice for organizing query code?".
View Replies
View Related
Jun 30, 2014
I have installed and tested j2se jdk8 u5 on my Windows 7 64 bit laptop and successfully tested in Eclipse with a quick Hello World.
JAVA_HOME = C:Program FilesJavajdk1.6.0_25
When I try to install j2ee jdk7 sdk7 I get
Error: Could not find the required version of the Java(TM) 2 Runtime Environment in '(null)'
View Replies
View Related
Feb 10, 2015
how java imports libraries from a jar file inside a source. Let's say I have the following code on Something.java file,
import com.mycomanyA.*;
import com.mycomanyB.*;
public class Something{
public static void main(String ... args){
// code goes here...
}
}
And the Something.java is inside the following structure...
A.jar
com/
mycompanyA/
A.class
Another.class
B.jar
com/
mycompanyB/
B.class
neededImage.gif
bin-folder/
org/
apache/
Something.java
To compile this code(Something.java) from command line I want to use the following command,
javac org/apache/Something.class
And for the compilation to be successful, I'll have to be just above bin-folder because...
- > Only then my default class path will be (.) and java would automatically include A.jar and B.jar(the other way is to add the jar files using -cp argument, which I want to avoid in this scenario)
- > And for the import org.mycompanyX to work I'll have to be in the (.) directory.
Are my assumptions correct about how java find jar contents imported in a source file?
View Replies
View Related
May 28, 2014
I am looking for pure java API to be able to create/read outlook tasks.
Any open source API's available for the same.
View Replies
View Related
Aug 13, 2014
I am using java process to start a system command in windows
Runtime r = Runtime.getRuntime();
Process pr = r.exec(cmdString);
I want to get the prompt out put from cmdString = "cmd /c type fileSmallSize"->>>> It is ok the have the content of the file when file is small.
However, for a large file java process will hang and no Exception occurred, what is the problem?
The easiest testing you can try on the logging.properties file in java.
public static String executeCmdAndReturnPromptResult(String cmdString)
throws Exception {
LOGGER.entering(CLASSNAME,
"Entering executeCmdAndReturnPromptResult()", cmdString);
String cmd = cmdString;
[Code] ....
It seemed to me that the bufferSize is limited so that I can only have it less than a default one, how to increase it?
My question now is how to increase the size of buffer in order to read a larger InputStream ?
BufferedInputStream() default size is
private static int defaultCharBufferSize = 8192;
private static int defaultExpectedLineLength = 80;
How to make it larger and working? I tried to increase the defaultCharBufferSize to 500000000 but it did not work!
View Replies
View Related
Feb 19, 2014
I have been given a task to scan the contents of a websites source code, and use delimiters to extract all hyperlinks from the site and display them. We havent been told anything about how to do this so after some looking around online this is what I have so far:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
[Code] ....
So my program can extract each line from the source code of a website and display it, but realistically I want it to extract each WORD as such from the source code rather than every line. I've looked around online but I don't really know how it's done because I keep getting errors when I use input.read();
How to make it extract each word from the source code?
View Replies
View Related
Feb 3, 2014
Why is this not valid in java:
Both uses public with the same class/interface name.
Test.java:
public class Test implements Test{
/// Some codes
}
public interface Test {
///Some methods
}
View Replies
View Related