c# - How to execute a .Jar file with Arguments.Length > 8191 - java

I should starting a .jar several times like this
string JavaDir = #"C:\Program Files\Java\jdk1.8.0_161\bin\javaw.exe";
string MinecraftVersion = #"1.12.2";
string ForgeVersion = #"14.23.2.2611";
string Version = MinecraftVersion + #"-forge-" + ForgeVersion;
string ClientDir = #CurrentDirectory + #"\Client";
string Assets = ClientDir + #"\assets";
string Libraries = ClientDir + #"\libraries";
string Jar = ClientDir + #"\versions\" + MinecraftVersion + #"\" + MinecraftVersion + #".jar";
string Natives = ClientDir + #"\versions\" + MinecraftVersion + #"\" + MinecraftVersion + "-natives";
string Arguments = #"-XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx1G -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode -XX:-UseAdaptiveSizePolicy -Xmn128M -Djava.library.path=""" + Natives + #""" -cp """ + Libraries + #"\net\minecraftforge\forge\" + MinecraftVersion + #"-" + ForgeVersion + #"\" + Version + #".jar"";""" + Libraries + #"\net\minecraft\launchwrapper\1.12\launchwrapper-1.12.jar"";""" + Libraries + #"\org\ow2\asm\asm-all\5.2\asm-all-5.2.jar"";""" + Libraries + #"\jline\jline\2.13\jline-2.13.jar"";""" + Libraries + #"\com\typesafe\akka\akka-actor_2.11\2.3.3\akka-actor_2.11-2.3.3.jar"";""" + Libraries + #"\com\typesafe\config\1.2.1\config-1.2.1.jar"";""" + Libraries + #"\org\scala-lang\scala-actors-migration_2.11\1.1.0\scala-actors-migration_2.11-1.1.0.jar"";""" + Libraries + #"\org\scala-lang\scala-compiler\2.11.1\scala-compiler-2.11.1.jar"";""" + Libraries + #"\org\scala-lang\plugins\scala-continuations-library_2.11\1.0.2\scala-continuations-library_2.11-1.0.2.jar"";""" + Libraries + #"\org\scala-lang\plugins\scala-continuations-plugin_2.11.1\1.0.2\scala-continuations-plugin_2.11.1-1.0.2.jar"";""" + Libraries + #"\org\scala-lang\scala-library\2.11.1\scala-library-2.11.1.jar"";""" + Libraries + #"\org\scala-lang\scala-parser-combinators_2.11\1.0.1\scala-parser-combinators_2.11-1.0.1.jar"";""" + Libraries + #"\org\scala-lang\scala-reflect\2.11.1\scala-reflect-2.11.1.jar"";""" + Libraries + #"\org\scala-lang\scala-swing_2.11\1.0.1\scala-swing_2.11-1.0.1.jar"";""" + Libraries + #"\org\scala-lang\scala-xml_2.11\1.0.2\scala-xml_2.11-1.0.2.jar"";""" + Libraries + #"\lzma\lzma\0.0.1\lzma-0.0.1.jar"";""" + Libraries + #"\net\sf\jopt-simple\jopt-simple\5.0.3\jopt-simple-5.0.3.jar"";""" + Libraries + #"\java3d\vecmath\1.5.2\vecmath-1.5.2.jar"";""" + Libraries + #"\net\sf\trove4j\trove4j\3.0.3\trove4j-3.0.3.jar"";""" + Libraries + #"\net\minecraftforge\MercuriusUpdater\1.12.2\MercuriusUpdater-1.12.2.jar"";""" + Libraries + #"\oshi-project\oshi-core\1.1\oshi-core-1.1.jar"";""" + Libraries + #"\net\java\dev\jna\jna\4.4.0\jna-4.4.0.jar"";""" + Libraries + #"\net\java\dev\jna\platform\3.4.0\platform-3.4.0.jar"";""" + Libraries + #"\com\ibm\icu\icu4j-core-mojang\51.2\icu4j-core-mojang-51.2.jar"";""" + Libraries + #"\net\sf\jopt-simple\jopt-simple\5.0.3\jopt-simple-5.0.3.jar"";""" + Libraries + #"\com\paulscode\codecjorbis\20101023\codecjorbis-20101023.jar"";""" + Libraries + #"\com\paulscode\codecwav\20101023\codecwav-20101023.jar"";""" + Libraries + #"\com\paulscode\libraryjavasound\20101123\libraryjavasound-20101123.jar"";""" + Libraries + #"\com\paulscode\librarylwjglopenal\20100824\librarylwjglopenal-20100824.jar"";""" + Libraries + #"\com\paulscode\soundsystem\20120107\soundsystem-20120107.jar"";""" + Libraries + #"\io\netty\netty-all\4.1.9.Final\netty-all-4.1.9.Final.jar"";""" + Libraries + #"\com\google\guava\guava\21.0\guava-21.0.jar"";""" + Libraries + #"\org\apache\commons\commons-lang3\3.5\commons-lang3-3.5.jar"";""" + Libraries + #"\commons-io\commons-io\2.5\commons-io-2.5.jar"";""" + Libraries + #"\commons-codec\commons-codec\1.10\commons-codec-1.10.jar"";""" + Libraries + #"\net\java\jinput\jinput\2.0.5\jinput-2.0.5.jar"";""" + Libraries + #"\net\java\jutils\jutils\1.0.0\jutils-1.0.0.jar"";""" + Libraries + #"\com\google\code\gson\gson\2.8.0\gson-2.8.0.jar"";""" + Libraries + #"\com\mojang\authlib\1.5.25\authlib-1.5.25.jar"";""" + Libraries + #"\com\mojang\realms\1.10.19\realms-1.10.19.jar"";""" + Libraries + #"\org\apache\commons\commons-compress\1.8.1\commons-compress-1.8.1.jar"";""" + Libraries + #"\org\apache\httpcomponents\httpclient\4.3.3\httpclient-4.3.3.jar"";""" + Libraries + #"\commons-logging\commons-logging\1.1.3\commons-logging-1.1.3.jar"";""" + Libraries + #"\org\apache\httpcomponents\httpcore\4.3.2\httpcore-4.3.2.jar"";""" + Libraries + #"\it\unimi\dsi\fastutil\7.1.0\fastutil-7.1.0.jar"";""" + Libraries + #"\org\apache\logging\log4j\log4j-api\2.8.1\log4j-api-2.8.1.jar"";""" + Libraries + #"\org\apache\logging\log4j\log4j-core\2.8.1\log4j-core-2.8.1.jar"";""" + Libraries + #"\org\lwjgl\lwjgl\lwjgl\2.9.4-nightly-20150209\lwjgl-2.9.4-nightly-20150209.jar"";""" + Libraries + #"\org\lwjgl\lwjgl\lwjgl_util\2.9.4-nightly-20150209\lwjgl_util-2.9.4-nightly-20150209.jar"";""" + Libraries + #"\com\mojang\text2speech\1.10.3\text2speech-1.10.3.jar"";""" + Jar + #" net.minecraft.launchwrapper.Launch --username " + Username + #" --version " + Version + #" --gameDir """ + ClientDir + #""" --assetsDir """ + Assets + #""" --assetIndex 1.12 --uuid " + UUID + #" --accessToken " + AccessToken + #" --userType legacy --tweakClass net.minecraftforge.fml.common.launcher.FMLTweaker --versionType Forge";
Client.StartInfo.FileName = #"""" + JavaDir + #"""";
Client.StartInfo.Arguments = Arguments;
Client.Start();
but the argument's limit is 8191 char and my argument is greater than the limit.
How I can run it?
EDIT: https://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html

You could make your program receive a file as an argument and read it.
The file would have one or more lines depending the number of arguments you'd like to pass to the program.
Your program would need to receive the file and parse it line by line.

Related

how to simulate Excel control codes in String

One web project I'm involved in requires generating a CSV to the user.
One field is notes and there can be multiple notes in the field, separated by a return (alt-enter in Excel), appearing as
A USER entered on 02/17/2023: Test note
A USER entered on 02/17/2023: This is another note
Is it possible to insert control codes into a Java string that Excel will pick up and format the cell properly?
For what it's worth, this was my attempt:
}else if (formType.equalsIgnoreCase("downloadCSV")) {
Date d = new Date();
String filename = "C:/temp/rtTmp" + d.getTime() + ".csv";
File f = new File(filename);
List<Contact> contactList = RetentionTrackDatabaseUtil.getContacts();
BufferedWriter bw = new BufferedWriter(new FileWriter(f));
bw.write("name,"
+ "gender,"
+ "age,"
+ "DOB,"
+ "DOH,"
+ "DOR,"
+ "DOS,"
+ "dateContact,"
+ "reason,"
+ "status,"
+ "empNum,"
+ "shift,"
+ "phone,note(s)\n");
for (Contact c : contactList) {
System.out.println(c.getAge());
bw.append("\"" + c.getName() + "\"" + ","
+ c.getGender() + ","
+ Integer.toString(c.getAge()) + ","
+ (c.getDOB()!=null?RetentionTrackUtil.sdf.format(c.getDOB()):"") + ","
+ (c.getDOH()!=null?RetentionTrackUtil.sdf.format(c.getDOH()):"") + ","
+ (c.getDOR()!=null?RetentionTrackUtil.sdf.format(c.getDOR()):"") + ","
+ (c.getDOS()!=null?RetentionTrackUtil.sdf.format(c.getDOS()):"") + ","
+ (c.getDateContact()!=null?RetentionTrackUtil.sdf.format(c.getDateContact()):"") + ","
+ c.getReason() + ","
+ c.getStatus() + ","
+ c.getEmpNum() + ","
+ c.getShift() + ","
+ c.getPhone() + ",");
for(Note n: c.getNoteList()){
bw.append("(" + n.getEnteredBy() + " on " + RetentionTrackUtil.sdf.format(n.getNoteDate()) + ")" + n.getNote() + "\\n");
}
bw.append("\n");
}
bw.close();
sendFile(response, filename);
}

Resolve Uncaught exception spotted in thread main: java.lang.AbstractMethodError

I am trying to call a java service from python. I am appending current timestamp to the file name to create a dynamic file name and passing it as a parameter in the java command. When I don't append the timestamp and pass the parameter as is, the code works but when I append the timestamp, I get Uncaught exception spotted in thread main: java.lang.AbstractMethodError error.
The code that doesn't works:
import subprocess
import time
Class DH:
#staticmethod
def restart_server(CLASSPATH, CLIENT_JVM_OPTIONS, SERVER_JVM_OPTIONS, SERVER_CONNECTION, DB_CONFIG, USER, SERVER_LOG, VERBOSE_OPTION):
subprocess.call("java -cp " + CLASSPATH + " " + CLIENT_JVM_OPTIONS + " -Djava.security.policy=..\\conf\\rmi.policy lib/main/Run -s " + SERVER_CONNECTION + " -user " + USER + " " + VERBOSE_OPTION + " shutdown SERVER")
timestr = time.strftime("%Y%m%d - %H%M%S")
log_file_name = "..\logs\DHLogFile" + timestr + ".log"
print(log_file_name)
subprocess.call("java -cp " + CLASSPATH + " " + SERVER_JVM_OPTIONS + " -Djava.security.policy=..\conf\\rmi.policy lib/main/Server -export " + SERVER_CONNECTION + " -db " + DB_CONFIG + " -log " + log_file_name + " -loglevel EFWIT " + VERBOSE_OPTION)
The code that works,
import subprocess
import time
Class DH:
#staticmethod
def restart_server(CLASSPATH, CLIENT_JVM_OPTIONS, SERVER_JVM_OPTIONS, SERVER_CONNECTION, DB_CONFIG, USER, SERVER_LOG, VERBOSE_OPTION):
subprocess.call("java -cp " + CLASSPATH + " " + CLIENT_JVM_OPTIONS + " -Djava.security.policy=..\\conf\\rmi.policy lib/main/Run -s " + SERVER_CONNECTION + " -user " + USER + " " + VERBOSE_OPTION + " shutdown SERVER")
log_file_name = "..\logs\DHLogFile.log"
subprocess.call("java -cp " + CLASSPATH + " " + SERVER_JVM_OPTIONS + " -Djava.security.policy=..\conf\\rmi.policy lib/main/Server -export " + SERVER_CONNECTION + " -db " + DB_CONFIG + " -log " + log_file_name + " -loglevel EFWIT " + VERBOSE_OPTION)
The full error is:
E 28/12/17-11:37:36.358 [-5] Uncaught exception spotted in thread main: java.lang.AbstractMethodError
E 28/12/17-11:37:36.358 [-5] java.lang.AbstractMethodError :
lib.main.a$a.a([Ljava/lang/String;I)I
java.lang.AbstractMethodError: lib.main.a$a.a([Ljava/lang/String;I)I
at lib.main.a.processArgs(SourceFile:646)
at lib.main.a.setupEnv(SourceFile:1078)
at lib.main.Server.main(SourceFile:157)
Could you please help me understand what is giving me AbstractMethodError Exception as I really want to have timestamp in the filename.

sending Meeting request outlook in java , and linebreaks in "DESCRIPTION:" are takenout

String textEmail= "Hi, \n this is an automatic message \n from sender.
StringBuffer buffer = sb.append("BEGIN:VCALENDAR\n" +
"PRODID:-//Microsoft Corporation//Outlook 9.0 MIMEDIR//EN\n" +
"VERSION:2.0\n" +
"METHOD:REQUEST\n" +
"BEGIN:VEVENT\n" +
"ATTENDEE;ROLE=REQ-PARTICIPANT;RSVP=TRUE:MAILTO:" +emailAdressTo+"\n" +
"ORGANIZER:MAILTO:XX#gmail.com\n" +
"DTSTART:" + meetingStartTime + "\n"+
"DTEND:" + meetingEndTime + "\n"+
"LOCATION: Room FR PAR-New York\n" +
"TRANSP:OPAQUE\n" +
"SEQUENCE:0\n" +
"UID:"+ uniqueId +"\n" +
"DTSTAMP:"+ meetingEndTime + "\n" +
"CATEGORIES:Meeting\n" +
"DESCRIPTION:"+textEmail +"\n" +
"SUMMARY:"+subjectEmail+"\n" +
"PRIORITY:5\n" +
"CLASS:PUBLIC\n" +
"BEGIN:VALARM\n" +
"TRIGGER:PT1440M\n" +
"ACTION:DISPLAY\n" +
"DESCRIPTION:Reminder\n" +
"END:VALARM\n" +
"END:VEVENT\n" +
"END:VCALENDAR");
email.setContent(buffer.toString(),"text/calendar");
email.setCharset("UTF-8");
the linebreaks breaks are not taken in consideration and my output is just:
"Hi,this is an automatic message from sender"
I have tried every think in this post:
[1]How do I format a String in an email so Outlook will print the line breaks? but still same result Any help would be apreciated, thks
List item

can't restore from .sql dump file in mysql

I used mysqldump command to export/dump .sql file with rows like:
String cmd1 = mysqldump + " -h" + host + " -u" + username + " -p" + password + " " + "--compact --no-create-info " + "--where=ID=" + "'5b4ed36d-6152-4bfd-ad06-666f781e8bdc'" + " " + database + " " + "EMPLOYEE" + " " + "--result-file=" + "C:\\employee.sql";
This is the result of above command in a employee.sql file:
INSERT INTO `employee` VALUES ('Anette','Busch','2014-08-12','admin',' ','FALSE');
Now, I want to import the values from empolyee.sql file using command:
String cmd = mysql + " --user=" + username + " --password=" + password + " -e" + " source " + restoreFile;
The problem is I can't execute import command. I'm using the same import command for whole database, that works fine, but not in this case.
Thanks a lot for your guidance.

Java built-in data structure for mapping adjacent rooms

I'm looking for a Java built-in data structure that would be the best at handling adjacent rooms.
I have a grid/floor divided into randomly generated rooms like so:
+ + + + + + + + + + + + + + + + + + + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + +
and i'm looking for a data structure in which it would be fastest/easiest to store this grid and map out what rooms neighbour what rooms.
Does anyone have a suggestion?
thanks
You just need to store:
the opposite corners of each room
the adjacency graph/matrix of the graph formed by rooms as nodes and adjacency as the edge.
You can use a graph to represent rooms as nodes and neighboring relationship as edges.
You can represent graphs in many different ways. In this case, since the relationship is sparse, it's better to use adjacency list instead of adjacency matrix.
In Java, the graph can be represented with Map<Room,List<Room>>. Basically, it is what it says: it's a map from a Room to a list of its neighboring Rooms.
Alternatively, if you prefer to work with basic integers and arrays, you can use an adjacency matrix representation boolean[][] adj, where adj[i][j] == true if and only if room i and room j are neighbors.

Categories

Resources