Skip to content

Instantly share code, notes, and snippets.

@kant2002
Forked from seclerp/Program.csrpoj
Created November 16, 2022 05:06
Show Gist options
  • Save kant2002/df0972d7fc83e29324513e71a36c919f to your computer and use it in GitHub Desktop.
Save kant2002/df0972d7fc83e29324513e71a36c919f to your computer and use it in GitHub Desktop.
Solution for the task "Run the Java Hello World example via both dotnet run and javac"
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.java" />
</ItemGroup>
<Target Name="GenerateCsharp" BeforeTargets="BeforeBuild" KeepDuplicateOutputs="true">
<WriteLinesToFile File="$(IntermediateOutputPath)augmentation.cs" Overwrite="true" Encoding="Unicode"
Lines="namespace System {
class err {
public static void println(string message) {
Console.WriteLine(message)%3B
}
}
}
" />
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)augmentation.cs" />
</ItemGroup>
</Target>
</Project>
class Program {
public static void main(String[] args) {
System.err.println("Hello, World!");
}
public static void Main(String[] args) {
main(args);
}
}
@kant2002
Copy link
Author

Other variant where we run java )

<Project>
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net6.0</TargetFramework>
        <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
        <RunCommand>java</RunCommand>
        <RunArguments>Program</RunArguments>
    </PropertyGroup>
    
    <Target Name="Build">
        <Exec Command="javac Program.java" />
    </Target>
</Project>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment