Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7944501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:34:14+00:00 2026-06-04T00:34:14+00:00

I am trying to generate java code using jcodemodel in my maven project. My

  • 0

I am trying to generate java code using jcodemodel in my maven project. My maven project has three modules. I have written a sample jcodemodel in one of my module for testing purpose.But when i execute it, throws me error in the line. But I created the directory and also checked. I checked this example in simple maven project it works. But when I give it inside maven module, it throws error. where does it check for the build file?

codeModel.build(new File("src/main/java/check"));

java.io.IOException: src\main\java\check: non-existent directory
at com.sun.codemodel.writer.FileCodeWriter.(FileCodeWriter.java:73)

public class Consumer {

    /**
     * @param args
     * @throws JClassAlreadyExistsException 
     * @throws IOException 
     * @throws JAXBException 
     */
    public static void main(String[] args) throws JClassAlreadyExistsException, IOException, JAXBException {
            writeCodeModel("com.cts");
    }

    public static JType getTypeDetailsForCodeModel(JCodeModel jCodeModel, String type) {
        if (type.equals("Unsigned32")) {
            return jCodeModel.LONG;
        } else if (type.equals("Unsigned64")) {
            return jCodeModel.LONG;
        } else if (type.equals("Integer32")) {
            return jCodeModel.INT;
        } else if (type.equals("Integer64")) {
            return jCodeModel.LONG;
        } else if (type.equals("Enumerated")) {
            return jCodeModel.INT;
        } else if (type.equals("Float32")) {
            return jCodeModel.FLOAT;
        } else if (type.equals("Float64")) {
            return jCodeModel.DOUBLE;
        } else {
            return null;
        }
    }

    // Function to generate CodeModel Class
    public static void writeCodeModel(String factroyPackage) throws JAXBException {
        try {

            JCodeModel codeModel = new JCodeModel();
            JDefinedClass foo = codeModel._class( "Foo" ); //Creates a new class

            JMethod method = foo.method( JMod.PUBLIC, Void.TYPE, "doFoo" ); //Adds a method to the class
            method.body()._return( JExpr.lit( 42 ) ); //the return statement

            codeModel.build(new File("src/main/java/check"));

        } catch (Exception ex) {

            ex.printStackTrace();
        }
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:34:16+00:00Added an answer on June 4, 2026 at 12:34 am

    The exception message seems pretty clear:

    java.io.IOException: src\main\java\check: non-existent directory at com.sun.codemodel.writer.FileCodeWriter.(FileCodeWriter.java:73)

    To create the target directory you can modify your code like this, the preferred folder for generated sources is at target/generated-sources/.

    File target = new File("target/generated-sources/java");
    if (!target.mkdirs()) {
        throw new IOException("could not create directory");
    }
    codeModel.build(target);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate java code from xsd using JAXB 2.1 XJC. I have
In trying to write more testable Java code, I have been using the Model-View-Presenter
Im trying to generate a color gradient using ColdFusion. My current code below works
I am trying to deterministically generate an RSA key pair using Java on Android.
I've started using Doxygen to document my team's project source code (we have C#,
I'm trying to generate a Java Client with the axis using wsdl2java (wrapped by
I'm trying to generate Java Web Start files using PHP. Right now I'm just
I'm trying to incorporate server-based code diff and highlighting in my GWT (Java) project.
I am trying to upload files using Java URL class and I have found
I'm trying to generate code coverage reports with EMMA using tests of which some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.